@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/cookie'); |
@@ -30,21 +30,21 @@ discard block |
||
| 30 | 30 | * @return void |
| 31 | 31 | */ |
| 32 | 32 | function action_converser_dist() { |
| 33 | - $update_session = false; |
|
| 34 | - if (_request('arg') and spip_connect()) { |
|
| 35 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | - $securiser_action(); |
|
| 37 | - $update_session = true; |
|
| 38 | - } |
|
| 33 | + $update_session = false; |
|
| 34 | + if (_request('arg') and spip_connect()) { |
|
| 35 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | + $securiser_action(); |
|
| 37 | + $update_session = true; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $lang = action_converser_changer_langue($update_session); |
|
| 41 | - $redirect = rawurldecode(_request('redirect')); |
|
| 40 | + $lang = action_converser_changer_langue($update_session); |
|
| 41 | + $redirect = rawurldecode(_request('redirect')); |
|
| 42 | 42 | |
| 43 | - if (!$redirect) { |
|
| 44 | - $redirect = _DIR_RESTREINT_ABS; |
|
| 45 | - } |
|
| 46 | - $redirect = parametre_url($redirect, 'lang', $lang, '&'); |
|
| 47 | - redirige_par_entete($redirect, true); |
|
| 43 | + if (!$redirect) { |
|
| 44 | + $redirect = _DIR_RESTREINT_ABS; |
|
| 45 | + } |
|
| 46 | + $redirect = parametre_url($redirect, 'lang', $lang, '&'); |
|
| 47 | + redirige_par_entete($redirect, true); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -56,23 +56,23 @@ discard block |
||
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | 58 | function action_converser_changer_langue($update_session) { |
| 59 | - if ($lang = _request('var_lang')) { |
|
| 60 | - action_converser_post($lang); |
|
| 61 | - } elseif ($lang = _request('var_lang_ecrire')) { |
|
| 62 | - if ($update_session) { |
|
| 63 | - sql_updateq('spip_auteurs', ['lang' => $lang], 'id_auteur = ' . $GLOBALS['visiteur_session']['id_auteur']); |
|
| 64 | - $GLOBALS['visiteur_session']['lang'] = $lang; |
|
| 65 | - $session = charger_fonction('session', 'inc'); |
|
| 66 | - if ($spip_session = $session($GLOBALS['visiteur_session'])) { |
|
| 67 | - spip_setcookie('spip_session', $spip_session, [ |
|
| 68 | - 'expires' => time() + 3600 * 24 * 14 |
|
| 69 | - ]); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - action_converser_post($lang, true); |
|
| 73 | - } |
|
| 59 | + if ($lang = _request('var_lang')) { |
|
| 60 | + action_converser_post($lang); |
|
| 61 | + } elseif ($lang = _request('var_lang_ecrire')) { |
|
| 62 | + if ($update_session) { |
|
| 63 | + sql_updateq('spip_auteurs', ['lang' => $lang], 'id_auteur = ' . $GLOBALS['visiteur_session']['id_auteur']); |
|
| 64 | + $GLOBALS['visiteur_session']['lang'] = $lang; |
|
| 65 | + $session = charger_fonction('session', 'inc'); |
|
| 66 | + if ($spip_session = $session($GLOBALS['visiteur_session'])) { |
|
| 67 | + spip_setcookie('spip_session', $spip_session, [ |
|
| 68 | + 'expires' => time() + 3600 * 24 * 14 |
|
| 69 | + ]); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + action_converser_post($lang, true); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return $lang; |
|
| 75 | + return $lang; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | * @return void |
| 84 | 84 | */ |
| 85 | 85 | function action_converser_post($lang, $ecrire = false) { |
| 86 | - if ($lang) { |
|
| 87 | - include_spip('inc/lang'); |
|
| 88 | - if (changer_langue($lang)) { |
|
| 89 | - spip_setcookie('spip_lang', $_COOKIE['spip_lang'] = $lang, [ |
|
| 90 | - 'expires' => time() + 365 * 24 * 3600 |
|
| 91 | - ]); |
|
| 92 | - if ($ecrire) { |
|
| 93 | - spip_setcookie('spip_lang_ecrire', $_COOKIE['spip_lang_ecrire'] = $lang, [ |
|
| 94 | - 'expires' => time() + 365 * 24 * 3600 |
|
| 95 | - ]); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 86 | + if ($lang) { |
|
| 87 | + include_spip('inc/lang'); |
|
| 88 | + if (changer_langue($lang)) { |
|
| 89 | + spip_setcookie('spip_lang', $_COOKIE['spip_lang'] = $lang, [ |
|
| 90 | + 'expires' => time() + 365 * 24 * 3600 |
|
| 91 | + ]); |
|
| 92 | + if ($ecrire) { |
|
| 93 | + spip_setcookie('spip_lang_ecrire', $_COOKIE['spip_lang_ecrire'] = $lang, [ |
|
| 94 | + 'expires' => time() + 365 * 24 * 3600 |
|
| 95 | + ]); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/cookie'); |
@@ -34,73 +34,73 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | */ |
| 36 | 36 | function action_logout_dist() { |
| 37 | - $logout = _request('logout'); |
|
| 38 | - $url = securiser_redirect_action(_request('url')); |
|
| 39 | - // cas particulier, logout dans l'espace public |
|
| 40 | - if ($logout == 'public' and !$url) { |
|
| 41 | - $url = url_de_base(); |
|
| 42 | - } |
|
| 37 | + $logout = _request('logout'); |
|
| 38 | + $url = securiser_redirect_action(_request('url')); |
|
| 39 | + // cas particulier, logout dans l'espace public |
|
| 40 | + if ($logout == 'public' and !$url) { |
|
| 41 | + $url = url_de_base(); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // seul le loge peut se deloger (mais id_auteur peut valoir 0 apres une restauration avortee) |
|
| 45 | - if ( |
|
| 46 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 47 | - and is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 48 | - // des sessions anonymes avec id_auteur=0 existent, mais elle n'ont pas de statut : double check |
|
| 49 | - and isset($GLOBALS['visiteur_session']['statut']) |
|
| 50 | - ) { |
|
| 51 | - // il faut un jeton pour fermer la session (eviter les CSRF) |
|
| 52 | - if ( |
|
| 53 | - !$jeton = _request('jeton') |
|
| 54 | - or !verifier_jeton_logout($jeton, $GLOBALS['visiteur_session']) |
|
| 55 | - ) { |
|
| 56 | - $jeton = generer_jeton_logout($GLOBALS['visiteur_session']); |
|
| 57 | - $action = generer_url_action('logout', "jeton=$jeton"); |
|
| 58 | - $action = parametre_url($action, 'logout', _request('logout')); |
|
| 59 | - $action = parametre_url($action, 'url', _request('url')); |
|
| 60 | - include_spip('inc/minipres'); |
|
| 61 | - include_spip('inc/filtres'); |
|
| 62 | - $texte = bouton_action(_T('spip:icone_deconnecter'), $action); |
|
| 63 | - $texte = "<div class='boutons'>$texte</div>"; |
|
| 64 | - $texte .= '<script type="text/javascript">document.write("<style>body{visibility:hidden;}</style>");window.document.forms[0].submit();</script>'; |
|
| 65 | - $res = minipres(_T('spip:icone_deconnecter'), $texte, ['all_inline' => true]); |
|
| 66 | - echo $res; |
|
| 44 | + // seul le loge peut se deloger (mais id_auteur peut valoir 0 apres une restauration avortee) |
|
| 45 | + if ( |
|
| 46 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 47 | + and is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 48 | + // des sessions anonymes avec id_auteur=0 existent, mais elle n'ont pas de statut : double check |
|
| 49 | + and isset($GLOBALS['visiteur_session']['statut']) |
|
| 50 | + ) { |
|
| 51 | + // il faut un jeton pour fermer la session (eviter les CSRF) |
|
| 52 | + if ( |
|
| 53 | + !$jeton = _request('jeton') |
|
| 54 | + or !verifier_jeton_logout($jeton, $GLOBALS['visiteur_session']) |
|
| 55 | + ) { |
|
| 56 | + $jeton = generer_jeton_logout($GLOBALS['visiteur_session']); |
|
| 57 | + $action = generer_url_action('logout', "jeton=$jeton"); |
|
| 58 | + $action = parametre_url($action, 'logout', _request('logout')); |
|
| 59 | + $action = parametre_url($action, 'url', _request('url')); |
|
| 60 | + include_spip('inc/minipres'); |
|
| 61 | + include_spip('inc/filtres'); |
|
| 62 | + $texte = bouton_action(_T('spip:icone_deconnecter'), $action); |
|
| 63 | + $texte = "<div class='boutons'>$texte</div>"; |
|
| 64 | + $texte .= '<script type="text/javascript">document.write("<style>body{visibility:hidden;}</style>");window.document.forms[0].submit();</script>'; |
|
| 65 | + $res = minipres(_T('spip:icone_deconnecter'), $texte, ['all_inline' => true]); |
|
| 66 | + echo $res; |
|
| 67 | 67 | |
| 68 | - return; |
|
| 69 | - } |
|
| 68 | + return; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - include_spip('inc/auth'); |
|
| 72 | - auth_trace($GLOBALS['visiteur_session'], '0000-00-00 00:00:00'); |
|
| 73 | - // le logout explicite vaut destruction de toutes les sessions |
|
| 74 | - if (isset($_COOKIE['spip_session'])) { |
|
| 75 | - $session = charger_fonction('session', 'inc'); |
|
| 76 | - $session($GLOBALS['visiteur_session']['id_auteur']); |
|
| 77 | - spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 78 | - 'expires' => time() - 3600 |
|
| 79 | - ]); |
|
| 80 | - } |
|
| 81 | - // si authentification http, et que la personne est loge, |
|
| 82 | - // pour se deconnecter, il faut proposer un nouveau formulaire de connexion http |
|
| 83 | - if ( |
|
| 84 | - isset($_SERVER['PHP_AUTH_USER']) |
|
| 85 | - and !$GLOBALS['ignore_auth_http'] |
|
| 86 | - and $GLOBALS['auth_can_disconnect'] |
|
| 87 | - ) { |
|
| 88 | - ask_php_auth( |
|
| 89 | - _T('login_deconnexion_ok'), |
|
| 90 | - _T('login_verifiez_navigateur'), |
|
| 91 | - _T('login_retour_public'), |
|
| 92 | - 'redirect=' . _DIR_RESTREINT_ABS, |
|
| 93 | - _T('login_test_navigateur'), |
|
| 94 | - true |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - } |
|
| 71 | + include_spip('inc/auth'); |
|
| 72 | + auth_trace($GLOBALS['visiteur_session'], '0000-00-00 00:00:00'); |
|
| 73 | + // le logout explicite vaut destruction de toutes les sessions |
|
| 74 | + if (isset($_COOKIE['spip_session'])) { |
|
| 75 | + $session = charger_fonction('session', 'inc'); |
|
| 76 | + $session($GLOBALS['visiteur_session']['id_auteur']); |
|
| 77 | + spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 78 | + 'expires' => time() - 3600 |
|
| 79 | + ]); |
|
| 80 | + } |
|
| 81 | + // si authentification http, et que la personne est loge, |
|
| 82 | + // pour se deconnecter, il faut proposer un nouveau formulaire de connexion http |
|
| 83 | + if ( |
|
| 84 | + isset($_SERVER['PHP_AUTH_USER']) |
|
| 85 | + and !$GLOBALS['ignore_auth_http'] |
|
| 86 | + and $GLOBALS['auth_can_disconnect'] |
|
| 87 | + ) { |
|
| 88 | + ask_php_auth( |
|
| 89 | + _T('login_deconnexion_ok'), |
|
| 90 | + _T('login_verifiez_navigateur'), |
|
| 91 | + _T('login_retour_public'), |
|
| 92 | + 'redirect=' . _DIR_RESTREINT_ABS, |
|
| 93 | + _T('login_test_navigateur'), |
|
| 94 | + true |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - // Rediriger en contrant le cache navigateur (Safari3) |
|
| 100 | - include_spip('inc/headers'); |
|
| 101 | - redirige_par_entete($url |
|
| 102 | - ? parametre_url($url, 'var_hasard', uniqid(random_int(0, mt_getrandmax())), '&') |
|
| 103 | - : generer_url_public('login')); |
|
| 99 | + // Rediriger en contrant le cache navigateur (Safari3) |
|
| 100 | + include_spip('inc/headers'); |
|
| 101 | + redirige_par_entete($url |
|
| 102 | + ? parametre_url($url, 'var_hasard', uniqid(random_int(0, mt_getrandmax())), '&') |
|
| 103 | + : generer_url_public('login')); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -111,17 +111,17 @@ discard block |
||
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | 113 | function generer_jeton_logout($session, $alea = null) { |
| 114 | - if (is_null($alea)) { |
|
| 115 | - include_spip('inc/acces'); |
|
| 116 | - $alea = charger_aleas(); |
|
| 117 | - } |
|
| 114 | + if (is_null($alea)) { |
|
| 115 | + include_spip('inc/acces'); |
|
| 116 | + $alea = charger_aleas(); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - $jeton = md5($session['date_session'] |
|
| 120 | - . $session['id_auteur'] |
|
| 121 | - . $session['statut'] |
|
| 122 | - . $alea); |
|
| 119 | + $jeton = md5($session['date_session'] |
|
| 120 | + . $session['id_auteur'] |
|
| 121 | + . $session['statut'] |
|
| 122 | + . $alea); |
|
| 123 | 123 | |
| 124 | - return $jeton; |
|
| 124 | + return $jeton; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | * @return bool |
| 136 | 136 | */ |
| 137 | 137 | function verifier_jeton_logout($jeton, $session) { |
| 138 | - if (generer_jeton_logout($session) === $jeton) { |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 138 | + if (generer_jeton_logout($session) === $jeton) { |
|
| 139 | + return true; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - if (generer_jeton_logout($session, $GLOBALS['meta']['alea_ephemere_ancien']) === $jeton) { |
|
| 143 | - return true; |
|
| 144 | - } |
|
| 142 | + if (generer_jeton_logout($session, $GLOBALS['meta']['alea_ephemere_ancien']) === $jeton) { |
|
| 143 | + return true; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - return false; |
|
| 146 | + return false; |
|
| 147 | 147 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,43 +31,43 @@ discard block |
||
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | 33 | function action_instituer_langue_objet_dist($objet, $id, $id_rubrique, $changer_lang, $serveur = '') { |
| 34 | - if ($changer_lang) { |
|
| 35 | - $table_objet_sql = table_objet_sql($objet); |
|
| 36 | - $id_table_objet = id_table_objet($objet); |
|
| 37 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 38 | - $desc = $trouver_table($table_objet_sql, $serveur); |
|
| 34 | + if ($changer_lang) { |
|
| 35 | + $table_objet_sql = table_objet_sql($objet); |
|
| 36 | + $id_table_objet = id_table_objet($objet); |
|
| 37 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 38 | + $desc = $trouver_table($table_objet_sql, $serveur); |
|
| 39 | 39 | |
| 40 | - $set = []; |
|
| 41 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 42 | - $set['langue_choisie'] = 'oui'; |
|
| 43 | - } |
|
| 40 | + $set = []; |
|
| 41 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 42 | + $set['langue_choisie'] = 'oui'; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - if ($changer_lang != 'herit') { |
|
| 46 | - $set['lang'] = $changer_lang; |
|
| 47 | - sql_updateq($table_objet_sql, $set, "$id_table_objet=" . intval($id), [], $serveur); |
|
| 48 | - include_spip('inc/rubriques'); // pour calculer_langues_rubriques et calculer_langues_utilisees |
|
| 49 | - if ($table_objet_sql == 'spip_rubriques') { |
|
| 50 | - calculer_langues_rubriques(); |
|
| 51 | - } |
|
| 52 | - $langues = calculer_langues_utilisees($serveur); |
|
| 53 | - ecrire_meta('langues_utilisees', $langues); |
|
| 54 | - } else { |
|
| 55 | - $langue_parent = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 56 | - if (!$langue_parent) { |
|
| 57 | - $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 58 | - } |
|
| 59 | - $changer_lang = $langue_parent; |
|
| 60 | - $set['lang'] = $changer_lang; |
|
| 61 | - if (isset($set['langue_choisie'])) { |
|
| 62 | - $set['langue_choisie'] = 'non'; |
|
| 63 | - } |
|
| 64 | - sql_updateq($table_objet_sql, $set, "$id_table_objet=" . intval($id), [], $serveur); |
|
| 65 | - if ($table_objet_sql == 'spip_rubriques') { |
|
| 66 | - include_spip('inc/rubriques'); |
|
| 67 | - calculer_langues_rubriques(); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 45 | + if ($changer_lang != 'herit') { |
|
| 46 | + $set['lang'] = $changer_lang; |
|
| 47 | + sql_updateq($table_objet_sql, $set, "$id_table_objet=" . intval($id), [], $serveur); |
|
| 48 | + include_spip('inc/rubriques'); // pour calculer_langues_rubriques et calculer_langues_utilisees |
|
| 49 | + if ($table_objet_sql == 'spip_rubriques') { |
|
| 50 | + calculer_langues_rubriques(); |
|
| 51 | + } |
|
| 52 | + $langues = calculer_langues_utilisees($serveur); |
|
| 53 | + ecrire_meta('langues_utilisees', $langues); |
|
| 54 | + } else { |
|
| 55 | + $langue_parent = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 56 | + if (!$langue_parent) { |
|
| 57 | + $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 58 | + } |
|
| 59 | + $changer_lang = $langue_parent; |
|
| 60 | + $set['lang'] = $changer_lang; |
|
| 61 | + if (isset($set['langue_choisie'])) { |
|
| 62 | + $set['langue_choisie'] = 'non'; |
|
| 63 | + } |
|
| 64 | + sql_updateq($table_objet_sql, $set, "$id_table_objet=" . intval($id), [], $serveur); |
|
| 65 | + if ($table_objet_sql == 'spip_rubriques') { |
|
| 66 | + include_spip('inc/rubriques'); |
|
| 67 | + calculer_langues_rubriques(); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $changer_lang; |
|
| 72 | + return $changer_lang; |
|
| 73 | 73 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 28 | - return; |
|
| 28 | + return; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** Version de l'API SQL */ |
@@ -45,39 +45,39 @@ discard block |
||
| 45 | 45 | * contexte de l'erreur |
| 46 | 46 | **/ |
| 47 | 47 | function sql_error_backtrace($compil_info = false) { |
| 48 | - $trace = debug_backtrace(); |
|
| 49 | - $caller = array_shift($trace); |
|
| 50 | - while (count($trace) and (empty($trace[0]['file']) or $trace[0]['file'] === $caller['file'] or $trace[0]['file'] === __FILE__)) { |
|
| 51 | - array_shift($trace); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($compil_info) { |
|
| 55 | - $contexte_compil = [ |
|
| 56 | - $trace[0]['file'],// sourcefile |
|
| 57 | - '', //nom |
|
| 58 | - (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 59 | - . $trace[0]['function'] . '();' |
|
| 60 | - . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 61 | - $trace[0]['line'], // ligne |
|
| 62 | - $GLOBALS['spip_lang'], // lang |
|
| 63 | - ]; |
|
| 64 | - |
|
| 65 | - return $contexte_compil; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 69 | - $f = []; |
|
| 70 | - while (count($trace) and $t = array_shift($trace)) { |
|
| 71 | - if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 72 | - break; |
|
| 73 | - } |
|
| 74 | - $f[] = $t['function']; |
|
| 75 | - } |
|
| 76 | - if (count($f)) { |
|
| 77 | - $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $message; |
|
| 48 | + $trace = debug_backtrace(); |
|
| 49 | + $caller = array_shift($trace); |
|
| 50 | + while (count($trace) and (empty($trace[0]['file']) or $trace[0]['file'] === $caller['file'] or $trace[0]['file'] === __FILE__)) { |
|
| 51 | + array_shift($trace); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($compil_info) { |
|
| 55 | + $contexte_compil = [ |
|
| 56 | + $trace[0]['file'],// sourcefile |
|
| 57 | + '', //nom |
|
| 58 | + (isset($trace[1]) ? $trace[1]['function'] . "(){\n" : '') |
|
| 59 | + . $trace[0]['function'] . '();' |
|
| 60 | + . (isset($trace[1]) ? "\n}" : ''), //id_boucle |
|
| 61 | + $trace[0]['line'], // ligne |
|
| 62 | + $GLOBALS['spip_lang'], // lang |
|
| 63 | + ]; |
|
| 64 | + |
|
| 65 | + return $contexte_compil; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $message = count($trace) ? $trace[0]['file'] . ' L' . $trace[0]['line'] : ''; |
|
| 69 | + $f = []; |
|
| 70 | + while (count($trace) and $t = array_shift($trace)) { |
|
| 71 | + if (in_array($t['function'], ['include_once', 'include_spip', 'find_in_path'])) { |
|
| 72 | + break; |
|
| 73 | + } |
|
| 74 | + $f[] = $t['function']; |
|
| 75 | + } |
|
| 76 | + if (count($f)) { |
|
| 77 | + $message .= ' [' . implode('(),', $f) . '()]'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $message; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | **/ |
| 104 | 104 | function sql_serveur($ins_sql = '', $serveur = '', $continue = false) { |
| 105 | - static $sql_serveur = []; |
|
| 106 | - if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 107 | - $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 108 | - if (!is_string($f) or !$f) { |
|
| 109 | - return $f; |
|
| 110 | - } |
|
| 111 | - $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $sql_serveur[$serveur][$ins_sql]; |
|
| 105 | + static $sql_serveur = []; |
|
| 106 | + if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 107 | + $f = spip_connect_sql(\SQL_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 108 | + if (!is_string($f) or !$f) { |
|
| 109 | + return $f; |
|
| 110 | + } |
|
| 111 | + $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $sql_serveur[$serveur][$ins_sql]; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -133,23 +133,23 @@ discard block |
||
| 133 | 133 | * Retourne le nom du charset si effectivement trouvé, sinon false. |
| 134 | 134 | **/ |
| 135 | 135 | function sql_get_charset($charset, $serveur = '', $option = true) { |
| 136 | - // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 137 | - $desc = sql_serveur('', $serveur, true); |
|
| 138 | - $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 139 | - $c = $desc['charsets'][$charset]; |
|
| 140 | - if ($c) { |
|
| 141 | - if (function_exists($f = @$desc['get_charset'])) { |
|
| 142 | - if ($f($c, $serveur, $option !== false)) { |
|
| 143 | - return $c; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - spip_log( |
|
| 148 | - "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 149 | - _LOG_AVERTISSEMENT |
|
| 150 | - ); |
|
| 151 | - |
|
| 152 | - return false; |
|
| 136 | + // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 137 | + $desc = sql_serveur('', $serveur, true); |
|
| 138 | + $desc = $desc[\SQL_ABSTRACT_VERSION]; |
|
| 139 | + $c = $desc['charsets'][$charset]; |
|
| 140 | + if ($c) { |
|
| 141 | + if (function_exists($f = @$desc['get_charset'])) { |
|
| 142 | + if ($f($c, $serveur, $option !== false)) { |
|
| 143 | + return $c; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + spip_log( |
|
| 148 | + "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", |
|
| 149 | + _LOG_AVERTISSEMENT |
|
| 150 | + ); |
|
| 151 | + |
|
| 152 | + return false; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | * Retourne true si elle reussie. |
| 176 | 176 | **/ |
| 177 | 177 | function sql_set_charset($charset, $serveur = '', $option = true) { |
| 178 | - $f = sql_serveur('set_charset', $serveur, $option === 'continue' or $option === false); |
|
| 179 | - if (!is_string($f) or !$f) { |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 178 | + $f = sql_serveur('set_charset', $serveur, $option === 'continue' or $option === false); |
|
| 179 | + if (!is_string($f) or !$f) { |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $f($charset, $serveur, $option !== false); |
|
| 183 | + return $f($charset, $serveur, $option !== false); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
@@ -231,59 +231,59 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | **/ |
| 233 | 233 | function sql_select( |
| 234 | - $select = [], |
|
| 235 | - $from = [], |
|
| 236 | - $where = [], |
|
| 237 | - $groupby = [], |
|
| 238 | - $orderby = [], |
|
| 239 | - $limit = '', |
|
| 240 | - $having = [], |
|
| 241 | - $serveur = '', |
|
| 242 | - $option = true |
|
| 234 | + $select = [], |
|
| 235 | + $from = [], |
|
| 236 | + $where = [], |
|
| 237 | + $groupby = [], |
|
| 238 | + $orderby = [], |
|
| 239 | + $limit = '', |
|
| 240 | + $having = [], |
|
| 241 | + $serveur = '', |
|
| 242 | + $option = true |
|
| 243 | 243 | ) { |
| 244 | - $f = sql_serveur('select', $serveur, $option === 'continue' or $option === false); |
|
| 245 | - if (!is_string($f) or !$f) { |
|
| 246 | - return false; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $debug = (defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 250 | - if (($option !== false) and !$debug) { |
|
| 251 | - $res = $f( |
|
| 252 | - $select, |
|
| 253 | - $from, |
|
| 254 | - $where, |
|
| 255 | - $groupby, |
|
| 256 | - $orderby, |
|
| 257 | - $limit, |
|
| 258 | - $having, |
|
| 259 | - $serveur, |
|
| 260 | - is_array($option) ? true : $option |
|
| 261 | - ); |
|
| 262 | - } else { |
|
| 263 | - $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 264 | - if (!$option) { |
|
| 265 | - return $query; |
|
| 266 | - } |
|
| 267 | - // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 268 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 269 | - [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 270 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 271 | - $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 272 | - } |
|
| 273 | - $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // en cas d'erreur |
|
| 277 | - if (!is_string($res)) { |
|
| 278 | - return $res; |
|
| 279 | - } |
|
| 280 | - // denoncer l'erreur SQL dans sa version brute |
|
| 281 | - spip_sql_erreur($serveur); |
|
| 282 | - // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 283 | - $contexte_compil = sql_error_backtrace(true); |
|
| 284 | - erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 285 | - |
|
| 286 | - return false; |
|
| 244 | + $f = sql_serveur('select', $serveur, $option === 'continue' or $option === false); |
|
| 245 | + if (!is_string($f) or !$f) { |
|
| 246 | + return false; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $debug = (defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 250 | + if (($option !== false) and !$debug) { |
|
| 251 | + $res = $f( |
|
| 252 | + $select, |
|
| 253 | + $from, |
|
| 254 | + $where, |
|
| 255 | + $groupby, |
|
| 256 | + $orderby, |
|
| 257 | + $limit, |
|
| 258 | + $having, |
|
| 259 | + $serveur, |
|
| 260 | + is_array($option) ? true : $option |
|
| 261 | + ); |
|
| 262 | + } else { |
|
| 263 | + $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 264 | + if (!$option) { |
|
| 265 | + return $query; |
|
| 266 | + } |
|
| 267 | + // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 268 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 269 | + [$table, $id, ] = $GLOBALS['debug']['aucasou']; |
|
| 270 | + $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 271 | + $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 272 | + } |
|
| 273 | + $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // en cas d'erreur |
|
| 277 | + if (!is_string($res)) { |
|
| 278 | + return $res; |
|
| 279 | + } |
|
| 280 | + // denoncer l'erreur SQL dans sa version brute |
|
| 281 | + spip_sql_erreur($serveur); |
|
| 282 | + // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 283 | + $contexte_compil = sql_error_backtrace(true); |
|
| 284 | + erreur_squelette([sql_errno($serveur), sql_error($serveur), $res], $contexte_compil); |
|
| 285 | + |
|
| 286 | + return false; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
@@ -320,16 +320,16 @@ discard block |
||
| 320 | 320 | * |
| 321 | 321 | **/ |
| 322 | 322 | function sql_get_select( |
| 323 | - $select = [], |
|
| 324 | - $from = [], |
|
| 325 | - $where = [], |
|
| 326 | - $groupby = [], |
|
| 327 | - $orderby = [], |
|
| 328 | - $limit = '', |
|
| 329 | - $having = [], |
|
| 330 | - $serveur = '' |
|
| 323 | + $select = [], |
|
| 324 | + $from = [], |
|
| 325 | + $where = [], |
|
| 326 | + $groupby = [], |
|
| 327 | + $orderby = [], |
|
| 328 | + $limit = '', |
|
| 329 | + $having = [], |
|
| 330 | + $serveur = '' |
|
| 331 | 331 | ) { |
| 332 | - return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 332 | + return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -373,23 +373,23 @@ discard block |
||
| 373 | 373 | * |
| 374 | 374 | **/ |
| 375 | 375 | function sql_countsel( |
| 376 | - $from = [], |
|
| 377 | - $where = [], |
|
| 378 | - $groupby = [], |
|
| 379 | - $having = [], |
|
| 380 | - $serveur = '', |
|
| 381 | - $option = true |
|
| 376 | + $from = [], |
|
| 377 | + $where = [], |
|
| 378 | + $groupby = [], |
|
| 379 | + $having = [], |
|
| 380 | + $serveur = '', |
|
| 381 | + $option = true |
|
| 382 | 382 | ) { |
| 383 | - $f = sql_serveur('countsel', $serveur, $option === 'continue' or $option === false); |
|
| 384 | - if (!is_string($f) or !$f) { |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 387 | - $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 388 | - if ($r === false) { |
|
| 389 | - spip_sql_erreur($serveur); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $r; |
|
| 383 | + $f = sql_serveur('countsel', $serveur, $option === 'continue' or $option === false); |
|
| 384 | + if (!is_string($f) or !$f) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | + $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 388 | + if ($r === false) { |
|
| 389 | + spip_sql_erreur($serveur); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $r; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -421,16 +421,16 @@ discard block |
||
| 421 | 421 | * Ce retour n'est pas pertinent pour savoir si l'opération est correctement réalisée. |
| 422 | 422 | **/ |
| 423 | 423 | function sql_alter($q, $serveur = '', $option = true) { |
| 424 | - $f = sql_serveur('alter', $serveur, $option === 'continue' or $option === false); |
|
| 425 | - if (!is_string($f) or !$f) { |
|
| 426 | - return false; |
|
| 427 | - } |
|
| 428 | - $r = $f($q, $serveur, $option !== false); |
|
| 429 | - if ($r === false) { |
|
| 430 | - spip_sql_erreur($serveur); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return $r; |
|
| 424 | + $f = sql_serveur('alter', $serveur, $option === 'continue' or $option === false); |
|
| 425 | + if (!is_string($f) or !$f) { |
|
| 426 | + return false; |
|
| 427 | + } |
|
| 428 | + $r = $f($q, $serveur, $option !== false); |
|
| 429 | + if ($r === false) { |
|
| 430 | + spip_sql_erreur($serveur); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return $r; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -453,12 +453,12 @@ discard block |
||
| 453 | 453 | * presentant une ligne de resultat d'une selection |
| 454 | 454 | */ |
| 455 | 455 | function sql_fetch($res, $serveur = '', $option = true) { |
| 456 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 457 | - if (!is_string($f) or !$f) { |
|
| 458 | - return false; |
|
| 459 | - } |
|
| 456 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 457 | + if (!is_string($f) or !$f) { |
|
| 458 | + return false; |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | - return $f($res, null, $serveur, $option !== false); |
|
| 461 | + return $f($res, null, $serveur, $option !== false); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
@@ -485,20 +485,20 @@ discard block |
||
| 485 | 485 | * presentant une ligne de resultat d'une selection |
| 486 | 486 | */ |
| 487 | 487 | function sql_fetch_all($res, $serveur = '', $option = true) { |
| 488 | - $rows = []; |
|
| 489 | - if (!$res) { |
|
| 490 | - return $rows; |
|
| 491 | - } |
|
| 492 | - $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 493 | - if (!is_string($f) or !$f) { |
|
| 494 | - return []; |
|
| 495 | - } |
|
| 496 | - while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 497 | - $rows[] = $r; |
|
| 498 | - } |
|
| 499 | - sql_free($res, $serveur); |
|
| 500 | - |
|
| 501 | - return $rows; |
|
| 488 | + $rows = []; |
|
| 489 | + if (!$res) { |
|
| 490 | + return $rows; |
|
| 491 | + } |
|
| 492 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' or $option === false); |
|
| 493 | + if (!is_string($f) or !$f) { |
|
| 494 | + return []; |
|
| 495 | + } |
|
| 496 | + while ($r = $f($res, null, $serveur, $option !== false)) { |
|
| 497 | + $rows[] = $r; |
|
| 498 | + } |
|
| 499 | + sql_free($res, $serveur); |
|
| 500 | + |
|
| 501 | + return $rows; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -526,16 +526,16 @@ discard block |
||
| 526 | 526 | * Operation effectuée (true), sinon false. |
| 527 | 527 | **/ |
| 528 | 528 | function sql_seek($res, $row_number, $serveur = '', $option = true) { |
| 529 | - $f = sql_serveur('seek', $serveur, $option === 'continue' or $option === false); |
|
| 530 | - if (!is_string($f) or !$f) { |
|
| 531 | - return false; |
|
| 532 | - } |
|
| 533 | - $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 534 | - if ($r === false) { |
|
| 535 | - spip_sql_erreur($serveur); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - return $r; |
|
| 529 | + $f = sql_serveur('seek', $serveur, $option === 'continue' or $option === false); |
|
| 530 | + if (!is_string($f) or !$f) { |
|
| 531 | + return false; |
|
| 532 | + } |
|
| 533 | + $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 534 | + if ($r === false) { |
|
| 535 | + spip_sql_erreur($serveur); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + return $r; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | |
@@ -560,16 +560,16 @@ discard block |
||
| 560 | 560 | * False en cas d'erreur. |
| 561 | 561 | **/ |
| 562 | 562 | function sql_listdbs($serveur = '', $option = true) { |
| 563 | - $f = sql_serveur('listdbs', $serveur, $option === 'continue' or $option === false); |
|
| 564 | - if (!is_string($f) or !$f) { |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - $r = $f($serveur); |
|
| 568 | - if ($r === false) { |
|
| 569 | - spip_sql_erreur($serveur); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return $r; |
|
| 563 | + $f = sql_serveur('listdbs', $serveur, $option === 'continue' or $option === false); |
|
| 564 | + if (!is_string($f) or !$f) { |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + $r = $f($serveur); |
|
| 568 | + if ($r === false) { |
|
| 569 | + spip_sql_erreur($serveur); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return $r; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
@@ -592,16 +592,16 @@ discard block |
||
| 592 | 592 | * - False en cas d'erreur. |
| 593 | 593 | **/ |
| 594 | 594 | function sql_selectdb($nom, $serveur = '', $option = true) { |
| 595 | - $f = sql_serveur('selectdb', $serveur, $option === 'continue' or $option === false); |
|
| 596 | - if (!is_string($f) or !$f) { |
|
| 597 | - return false; |
|
| 598 | - } |
|
| 599 | - $r = $f($nom, $serveur, $option !== false); |
|
| 600 | - if ($r === false) { |
|
| 601 | - spip_sql_erreur($serveur); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - return $r; |
|
| 595 | + $f = sql_serveur('selectdb', $serveur, $option === 'continue' or $option === false); |
|
| 596 | + if (!is_string($f) or !$f) { |
|
| 597 | + return false; |
|
| 598 | + } |
|
| 599 | + $r = $f($nom, $serveur, $option !== false); |
|
| 600 | + if ($r === false) { |
|
| 601 | + spip_sql_erreur($serveur); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + return $r; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -626,16 +626,16 @@ discard block |
||
| 626 | 626 | * - false en cas d'erreur. |
| 627 | 627 | **/ |
| 628 | 628 | function sql_count($res, $serveur = '', $option = true) { |
| 629 | - $f = sql_serveur('count', $serveur, $option === 'continue' or $option === false); |
|
| 630 | - if (!is_string($f) or !$f) { |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - $r = $f($res, $serveur, $option !== false); |
|
| 634 | - if ($r === false) { |
|
| 635 | - spip_sql_erreur($serveur); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - return $r; |
|
| 629 | + $f = sql_serveur('count', $serveur, $option === 'continue' or $option === false); |
|
| 630 | + if (!is_string($f) or !$f) { |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + $r = $f($res, $serveur, $option !== false); |
|
| 634 | + if ($r === false) { |
|
| 635 | + spip_sql_erreur($serveur); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + return $r; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -657,12 +657,12 @@ discard block |
||
| 657 | 657 | * True si réussi |
| 658 | 658 | */ |
| 659 | 659 | function sql_free($res, $serveur = '', $option = true) { |
| 660 | - $f = sql_serveur('free', $serveur, $option === 'continue' or $option === false); |
|
| 661 | - if (!is_string($f) or !$f) { |
|
| 662 | - return false; |
|
| 663 | - } |
|
| 660 | + $f = sql_serveur('free', $serveur, $option === 'continue' or $option === false); |
|
| 661 | + if (!is_string($f) or !$f) { |
|
| 662 | + return false; |
|
| 663 | + } |
|
| 664 | 664 | |
| 665 | - return $f($res); |
|
| 665 | + return $f($res); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
@@ -700,17 +700,17 @@ discard block |
||
| 700 | 700 | * - False en cas d'erreur. |
| 701 | 701 | **/ |
| 702 | 702 | function sql_insert($table, $noms, $valeurs, $desc = [], $serveur = '', $option = true) { |
| 703 | - $f = sql_serveur('insert', $serveur, $option === 'continue' or $option === false); |
|
| 704 | - if (!is_string($f) or !$f) { |
|
| 705 | - return false; |
|
| 706 | - } |
|
| 707 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 708 | - if ($r === false or $r === null) { |
|
| 709 | - spip_sql_erreur($serveur); |
|
| 710 | - $r = false; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - return $r; |
|
| 703 | + $f = sql_serveur('insert', $serveur, $option === 'continue' or $option === false); |
|
| 704 | + if (!is_string($f) or !$f) { |
|
| 705 | + return false; |
|
| 706 | + } |
|
| 707 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 708 | + if ($r === false or $r === null) { |
|
| 709 | + spip_sql_erreur($serveur); |
|
| 710 | + $r = false; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + return $r; |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -751,17 +751,17 @@ discard block |
||
| 751 | 751 | * - False en cas d'erreur. |
| 752 | 752 | **/ |
| 753 | 753 | function sql_insertq($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 754 | - $f = sql_serveur('insertq', $serveur, $option === 'continue' or $option === false); |
|
| 755 | - if (!is_string($f) or !$f) { |
|
| 756 | - return false; |
|
| 757 | - } |
|
| 758 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 759 | - if ($r === false or $r === null) { |
|
| 760 | - spip_sql_erreur($serveur); |
|
| 761 | - $r = false; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - return $r; |
|
| 754 | + $f = sql_serveur('insertq', $serveur, $option === 'continue' or $option === false); |
|
| 755 | + if (!is_string($f) or !$f) { |
|
| 756 | + return false; |
|
| 757 | + } |
|
| 758 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 759 | + if ($r === false or $r === null) { |
|
| 760 | + spip_sql_erreur($serveur); |
|
| 761 | + $r = false; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + return $r; |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -796,17 +796,17 @@ discard block |
||
| 796 | 796 | * - False en cas d'erreur. |
| 797 | 797 | **/ |
| 798 | 798 | function sql_insertq_multi($table, $couples = [], $desc = [], $serveur = '', $option = true) { |
| 799 | - $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' or $option === false); |
|
| 800 | - if (!is_string($f) or !$f) { |
|
| 801 | - return false; |
|
| 802 | - } |
|
| 803 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 804 | - if ($r === false or $r === null) { |
|
| 805 | - spip_sql_erreur($serveur); |
|
| 806 | - $r = false; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - return $r; |
|
| 799 | + $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' or $option === false); |
|
| 800 | + if (!is_string($f) or !$f) { |
|
| 801 | + return false; |
|
| 802 | + } |
|
| 803 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 804 | + if ($r === false or $r === null) { |
|
| 805 | + spip_sql_erreur($serveur); |
|
| 806 | + $r = false; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + return $r; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -846,16 +846,16 @@ discard block |
||
| 846 | 846 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 847 | 847 | */ |
| 848 | 848 | function sql_update($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 849 | - $f = sql_serveur('update', $serveur, $option === 'continue' or $option === false); |
|
| 850 | - if (!is_string($f) or !$f) { |
|
| 851 | - return false; |
|
| 852 | - } |
|
| 853 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 854 | - if ($r === false) { |
|
| 855 | - spip_sql_erreur($serveur); |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - return $r; |
|
| 849 | + $f = sql_serveur('update', $serveur, $option === 'continue' or $option === false); |
|
| 850 | + if (!is_string($f) or !$f) { |
|
| 851 | + return false; |
|
| 852 | + } |
|
| 853 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 854 | + if ($r === false) { |
|
| 855 | + spip_sql_erreur($serveur); |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + return $r; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | |
@@ -901,16 +901,16 @@ discard block |
||
| 901 | 901 | * - False en cas d'erreur. |
| 902 | 902 | **/ |
| 903 | 903 | function sql_updateq($table, $exp, $where = '', $desc = [], $serveur = '', $option = true) { |
| 904 | - $f = sql_serveur('updateq', $serveur, $option === 'continue' or $option === false); |
|
| 905 | - if (!is_string($f) or !$f) { |
|
| 906 | - return false; |
|
| 907 | - } |
|
| 908 | - $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 909 | - if ($r === false) { |
|
| 910 | - spip_sql_erreur($serveur); |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - return $r; |
|
| 904 | + $f = sql_serveur('updateq', $serveur, $option === 'continue' or $option === false); |
|
| 905 | + if (!is_string($f) or !$f) { |
|
| 906 | + return false; |
|
| 907 | + } |
|
| 908 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 909 | + if ($r === false) { |
|
| 910 | + spip_sql_erreur($serveur); |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + return $r; |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | /** |
@@ -941,16 +941,16 @@ discard block |
||
| 941 | 941 | * - False en cas d'erreur. |
| 942 | 942 | **/ |
| 943 | 943 | function sql_delete($table, $where = '', $serveur = '', $option = true) { |
| 944 | - $f = sql_serveur('delete', $serveur, $option === 'continue' or $option === false); |
|
| 945 | - if (!is_string($f) or !$f) { |
|
| 946 | - return false; |
|
| 947 | - } |
|
| 948 | - $r = $f($table, $where, $serveur, $option !== false); |
|
| 949 | - if ($r === false) { |
|
| 950 | - spip_sql_erreur($serveur); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - return $r; |
|
| 944 | + $f = sql_serveur('delete', $serveur, $option === 'continue' or $option === false); |
|
| 945 | + if (!is_string($f) or !$f) { |
|
| 946 | + return false; |
|
| 947 | + } |
|
| 948 | + $r = $f($table, $where, $serveur, $option !== false); |
|
| 949 | + if ($r === false) { |
|
| 950 | + spip_sql_erreur($serveur); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + return $r; |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | /** |
@@ -986,16 +986,16 @@ discard block |
||
| 986 | 986 | * - False en cas d'erreur. |
| 987 | 987 | **/ |
| 988 | 988 | function sql_replace($table, $couples, $desc = [], $serveur = '', $option = true) { |
| 989 | - $f = sql_serveur('replace', $serveur, $option === 'continue' or $option === false); |
|
| 990 | - if (!is_string($f) or !$f) { |
|
| 991 | - return false; |
|
| 992 | - } |
|
| 993 | - $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 994 | - if ($r === false) { |
|
| 995 | - spip_sql_erreur($serveur); |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - return $r; |
|
| 989 | + $f = sql_serveur('replace', $serveur, $option === 'continue' or $option === false); |
|
| 990 | + if (!is_string($f) or !$f) { |
|
| 991 | + return false; |
|
| 992 | + } |
|
| 993 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 994 | + if ($r === false) { |
|
| 995 | + spip_sql_erreur($serveur); |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + return $r; |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | |
@@ -1033,16 +1033,16 @@ discard block |
||
| 1033 | 1033 | * - False en cas d'erreur. |
| 1034 | 1034 | **/ |
| 1035 | 1035 | function sql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $option = true) { |
| 1036 | - $f = sql_serveur('replace_multi', $serveur, $option === 'continue' or $option === false); |
|
| 1037 | - if (!is_string($f) or !$f) { |
|
| 1038 | - return false; |
|
| 1039 | - } |
|
| 1040 | - $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1041 | - if ($r === false) { |
|
| 1042 | - spip_sql_erreur($serveur); |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - return $r; |
|
| 1036 | + $f = sql_serveur('replace_multi', $serveur, $option === 'continue' or $option === false); |
|
| 1037 | + if (!is_string($f) or !$f) { |
|
| 1038 | + return false; |
|
| 1039 | + } |
|
| 1040 | + $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 1041 | + if ($r === false) { |
|
| 1042 | + spip_sql_erreur($serveur); |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + return $r; |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | /** |
@@ -1070,16 +1070,16 @@ discard block |
||
| 1070 | 1070 | * - False en cas d'erreur. |
| 1071 | 1071 | **/ |
| 1072 | 1072 | function sql_drop_table($table, $exist = '', $serveur = '', $option = true) { |
| 1073 | - $f = sql_serveur('drop_table', $serveur, $option === 'continue' or $option === false); |
|
| 1074 | - if (!is_string($f) or !$f) { |
|
| 1075 | - return false; |
|
| 1076 | - } |
|
| 1077 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1078 | - if ($r === false) { |
|
| 1079 | - spip_sql_erreur($serveur); |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - return $r; |
|
| 1073 | + $f = sql_serveur('drop_table', $serveur, $option === 'continue' or $option === false); |
|
| 1074 | + if (!is_string($f) or !$f) { |
|
| 1075 | + return false; |
|
| 1076 | + } |
|
| 1077 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1078 | + if ($r === false) { |
|
| 1079 | + spip_sql_erreur($serveur); |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + return $r; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | /** |
@@ -1103,16 +1103,16 @@ discard block |
||
| 1103 | 1103 | * - true si la requête a réussie, false sinon |
| 1104 | 1104 | */ |
| 1105 | 1105 | function sql_drop_view($table, $exist = '', $serveur = '', $option = true) { |
| 1106 | - $f = sql_serveur('drop_view', $serveur, $option === 'continue' or $option === false); |
|
| 1107 | - if (!is_string($f) or !$f) { |
|
| 1108 | - return false; |
|
| 1109 | - } |
|
| 1110 | - $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1111 | - if ($r === false) { |
|
| 1112 | - spip_sql_erreur($serveur); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - return $r; |
|
| 1106 | + $f = sql_serveur('drop_view', $serveur, $option === 'continue' or $option === false); |
|
| 1107 | + if (!is_string($f) or !$f) { |
|
| 1108 | + return false; |
|
| 1109 | + } |
|
| 1110 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 1111 | + if ($r === false) { |
|
| 1112 | + spip_sql_erreur($serveur); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + return $r; |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | /** |
@@ -1136,18 +1136,18 @@ discard block |
||
| 1136 | 1136 | * Ressource à utiliser avec sql_fetch() |
| 1137 | 1137 | **/ |
| 1138 | 1138 | function sql_showbase($spip = null, $serveur = '', $option = true) { |
| 1139 | - $f = sql_serveur('showbase', $serveur, $option === 'continue' or $option === false); |
|
| 1140 | - if (!is_string($f) or !$f) { |
|
| 1141 | - return false; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1145 | - if ($spip == null) { |
|
| 1146 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1147 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - return $f($spip, $serveur, $option !== false); |
|
| 1139 | + $f = sql_serveur('showbase', $serveur, $option === 'continue' or $option === false); |
|
| 1140 | + if (!is_string($f) or !$f) { |
|
| 1141 | + return false; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1145 | + if ($spip == null) { |
|
| 1146 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1147 | + $spip = $connexion['prefixe'] . '\_%'; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + return $f($spip, $serveur, $option !== false); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
@@ -1170,15 +1170,15 @@ discard block |
||
| 1170 | 1170 | * Liste des tables SQL |
| 1171 | 1171 | **/ |
| 1172 | 1172 | function sql_alltable($spip = null, $serveur = '', $option = true) { |
| 1173 | - $q = sql_showbase($spip, $serveur, $option); |
|
| 1174 | - $r = []; |
|
| 1175 | - if ($q) { |
|
| 1176 | - while ($t = sql_fetch($q, $serveur)) { |
|
| 1177 | - $r[] = array_shift($t); |
|
| 1178 | - } |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - return $r; |
|
| 1173 | + $q = sql_showbase($spip, $serveur, $option); |
|
| 1174 | + $r = []; |
|
| 1175 | + if ($q) { |
|
| 1176 | + while ($t = sql_fetch($q, $serveur)) { |
|
| 1177 | + $r[] = array_shift($t); |
|
| 1178 | + } |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + return $r; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1211,31 +1211,31 @@ discard block |
||
| 1211 | 1211 | * - 'join' => array() // jointures, si déclarées. |
| 1212 | 1212 | **/ |
| 1213 | 1213 | function sql_showtable($table, $table_spip = false, $serveur = '', $option = true) { |
| 1214 | - $f = sql_serveur('showtable', $serveur, $option === 'continue' or $option === false); |
|
| 1215 | - if (!is_string($f) or !$f) { |
|
| 1216 | - return false; |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1220 | - if ($table_spip) { |
|
| 1221 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1222 | - $prefixe = $connexion['prefixe']; |
|
| 1223 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1224 | - } else { |
|
| 1225 | - $vraie_table = $table; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1229 | - if (!$f) { |
|
| 1230 | - return []; |
|
| 1231 | - } |
|
| 1232 | - if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1233 | - $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1234 | - } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1235 | - $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - return $f; |
|
| 1214 | + $f = sql_serveur('showtable', $serveur, $option === 'continue' or $option === false); |
|
| 1215 | + if (!is_string($f) or !$f) { |
|
| 1216 | + return false; |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1220 | + if ($table_spip) { |
|
| 1221 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1222 | + $prefixe = $connexion['prefixe']; |
|
| 1223 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1224 | + } else { |
|
| 1225 | + $vraie_table = $table; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + $f = $f($vraie_table, $serveur, $option !== false); |
|
| 1229 | + if (!$f) { |
|
| 1230 | + return []; |
|
| 1231 | + } |
|
| 1232 | + if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 1233 | + $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 1234 | + } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 1235 | + $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + return $f; |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | |
@@ -1263,21 +1263,21 @@ discard block |
||
| 1263 | 1263 | * - False en cas d'erreur. |
| 1264 | 1264 | **/ |
| 1265 | 1265 | function sql_table_exists(string $table, bool $table_spip = true, $serveur = '', $option = true) { |
| 1266 | - $f = sql_serveur('table_exists', $serveur, $option === 'continue' or $option === false); |
|
| 1267 | - if (!is_string($f) or !$f) { |
|
| 1268 | - return false; |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1272 | - if ($table_spip) { |
|
| 1273 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1274 | - $prefixe = $connexion['prefixe']; |
|
| 1275 | - $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1276 | - } else { |
|
| 1277 | - $vraie_table = $table; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - return $f($vraie_table, $serveur, $option !== false); |
|
| 1266 | + $f = sql_serveur('table_exists', $serveur, $option === 'continue' or $option === false); |
|
| 1267 | + if (!is_string($f) or !$f) { |
|
| 1268 | + return false; |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 1272 | + if ($table_spip) { |
|
| 1273 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1274 | + $prefixe = $connexion['prefixe']; |
|
| 1275 | + $vraie_table = prefixer_table_spip($table, $prefixe); |
|
| 1276 | + } else { |
|
| 1277 | + $vraie_table = $table; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + return $f($vraie_table, $serveur, $option !== false); |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | |
@@ -1323,24 +1323,24 @@ discard block |
||
| 1323 | 1323 | * true si succès, false en cas d'echec |
| 1324 | 1324 | **/ |
| 1325 | 1325 | function sql_create( |
| 1326 | - $nom, |
|
| 1327 | - $champs, |
|
| 1328 | - $cles = [], |
|
| 1329 | - $autoinc = false, |
|
| 1330 | - $temporary = false, |
|
| 1331 | - $serveur = '', |
|
| 1332 | - $option = true |
|
| 1326 | + $nom, |
|
| 1327 | + $champs, |
|
| 1328 | + $cles = [], |
|
| 1329 | + $autoinc = false, |
|
| 1330 | + $temporary = false, |
|
| 1331 | + $serveur = '', |
|
| 1332 | + $option = true |
|
| 1333 | 1333 | ) { |
| 1334 | - $f = sql_serveur('create', $serveur, $option === 'continue' or $option === false); |
|
| 1335 | - if (!is_string($f) or !$f) { |
|
| 1336 | - return false; |
|
| 1337 | - } |
|
| 1338 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1339 | - if ($r === false) { |
|
| 1340 | - spip_sql_erreur($serveur); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - return $r; |
|
| 1334 | + $f = sql_serveur('create', $serveur, $option === 'continue' or $option === false); |
|
| 1335 | + if (!is_string($f) or !$f) { |
|
| 1336 | + return false; |
|
| 1337 | + } |
|
| 1338 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 1339 | + if ($r === false) { |
|
| 1340 | + spip_sql_erreur($serveur); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + return $r; |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | /** |
@@ -1358,16 +1358,16 @@ discard block |
||
| 1358 | 1358 | * @return bool true si la base est créee. |
| 1359 | 1359 | **/ |
| 1360 | 1360 | function sql_create_base($nom, $serveur = '', $option = true) { |
| 1361 | - $f = sql_serveur('create_base', $serveur, $option === 'continue' or $option === false); |
|
| 1362 | - if (!is_string($f) or !$f) { |
|
| 1363 | - return false; |
|
| 1364 | - } |
|
| 1365 | - $r = $f($nom, $serveur, $option !== false); |
|
| 1366 | - if ($r === false) { |
|
| 1367 | - spip_sql_erreur($serveur); |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - return $r; |
|
| 1361 | + $f = sql_serveur('create_base', $serveur, $option === 'continue' or $option === false); |
|
| 1362 | + if (!is_string($f) or !$f) { |
|
| 1363 | + return false; |
|
| 1364 | + } |
|
| 1365 | + $r = $f($nom, $serveur, $option !== false); |
|
| 1366 | + if ($r === false) { |
|
| 1367 | + spip_sql_erreur($serveur); |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + return $r; |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | 1373 | |
@@ -1397,16 +1397,16 @@ discard block |
||
| 1397 | 1397 | * - false en cas d'échec. |
| 1398 | 1398 | **/ |
| 1399 | 1399 | function sql_create_view($nom, $select_query, $serveur = '', $option = true) { |
| 1400 | - $f = sql_serveur('create_view', $serveur, $option === 'continue' or $option === false); |
|
| 1401 | - if (!is_string($f) or !$f) { |
|
| 1402 | - return false; |
|
| 1403 | - } |
|
| 1404 | - $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1405 | - if ($r === false) { |
|
| 1406 | - spip_sql_erreur($serveur); |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - return $r; |
|
| 1400 | + $f = sql_serveur('create_view', $serveur, $option === 'continue' or $option === false); |
|
| 1401 | + if (!is_string($f) or !$f) { |
|
| 1402 | + return false; |
|
| 1403 | + } |
|
| 1404 | + $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 1405 | + if ($r === false) { |
|
| 1406 | + spip_sql_erreur($serveur); |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + return $r; |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | /** |
@@ -1435,12 +1435,12 @@ discard block |
||
| 1435 | 1435 | * Texte de sélection pour la requête |
| 1436 | 1436 | */ |
| 1437 | 1437 | function sql_multi($sel, $lang, $serveur = '', $option = true) { |
| 1438 | - $f = sql_serveur('multi', $serveur, $option === 'continue' or $option === false); |
|
| 1439 | - if (!is_string($f) or !$f) { |
|
| 1440 | - return false; |
|
| 1441 | - } |
|
| 1438 | + $f = sql_serveur('multi', $serveur, $option === 'continue' or $option === false); |
|
| 1439 | + if (!is_string($f) or !$f) { |
|
| 1440 | + return false; |
|
| 1441 | + } |
|
| 1442 | 1442 | |
| 1443 | - return $f($sel, $lang); |
|
| 1443 | + return $f($sel, $lang); |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | |
@@ -1455,12 +1455,12 @@ discard block |
||
| 1455 | 1455 | * False si le serveur est indisponible |
| 1456 | 1456 | */ |
| 1457 | 1457 | function sql_error($serveur = '') { |
| 1458 | - $f = sql_serveur('error', $serveur, true); |
|
| 1459 | - if (!is_string($f) or !$f) { |
|
| 1460 | - return false; |
|
| 1461 | - } |
|
| 1458 | + $f = sql_serveur('error', $serveur, true); |
|
| 1459 | + if (!is_string($f) or !$f) { |
|
| 1460 | + return false; |
|
| 1461 | + } |
|
| 1462 | 1462 | |
| 1463 | - return $f('query inconnue', $serveur); |
|
| 1463 | + return $f('query inconnue', $serveur); |
|
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | /** |
@@ -1474,12 +1474,12 @@ discard block |
||
| 1474 | 1474 | * False si le serveur est indisponible |
| 1475 | 1475 | */ |
| 1476 | 1476 | function sql_errno($serveur = '') { |
| 1477 | - $f = sql_serveur('errno', $serveur, true); |
|
| 1478 | - if (!is_string($f) or !$f) { |
|
| 1479 | - return false; |
|
| 1480 | - } |
|
| 1477 | + $f = sql_serveur('errno', $serveur, true); |
|
| 1478 | + if (!is_string($f) or !$f) { |
|
| 1479 | + return false; |
|
| 1480 | + } |
|
| 1481 | 1481 | |
| 1482 | - return $f($serveur); |
|
| 1482 | + return $f($serveur); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | /** |
@@ -1497,16 +1497,16 @@ discard block |
||
| 1497 | 1497 | * @return array|false Tableau de l'explication |
| 1498 | 1498 | */ |
| 1499 | 1499 | function sql_explain($q, $serveur = '', $option = true) { |
| 1500 | - $f = sql_serveur('explain', $serveur, true); |
|
| 1501 | - if (!is_string($f) or !$f) { |
|
| 1502 | - return false; |
|
| 1503 | - } |
|
| 1504 | - $r = $f($q, $serveur, $option !== false); |
|
| 1505 | - if ($r === false) { |
|
| 1506 | - spip_sql_erreur($serveur); |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - return $r; |
|
| 1500 | + $f = sql_serveur('explain', $serveur, true); |
|
| 1501 | + if (!is_string($f) or !$f) { |
|
| 1502 | + return false; |
|
| 1503 | + } |
|
| 1504 | + $r = $f($q, $serveur, $option !== false); |
|
| 1505 | + if ($r === false) { |
|
| 1506 | + spip_sql_erreur($serveur); |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + return $r; |
|
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | /** |
@@ -1524,16 +1524,16 @@ discard block |
||
| 1524 | 1524 | * @return bool Toujours true |
| 1525 | 1525 | */ |
| 1526 | 1526 | function sql_optimize($table, $serveur = '', $option = true) { |
| 1527 | - $f = sql_serveur('optimize', $serveur, $option === 'continue' or $option === false); |
|
| 1528 | - if (!is_string($f) or !$f) { |
|
| 1529 | - return false; |
|
| 1530 | - } |
|
| 1531 | - $r = $f($table, $serveur, $option !== false); |
|
| 1532 | - if ($r === false) { |
|
| 1533 | - spip_sql_erreur($serveur); |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - return $r; |
|
| 1527 | + $f = sql_serveur('optimize', $serveur, $option === 'continue' or $option === false); |
|
| 1528 | + if (!is_string($f) or !$f) { |
|
| 1529 | + return false; |
|
| 1530 | + } |
|
| 1531 | + $r = $f($table, $serveur, $option !== false); |
|
| 1532 | + if ($r === false) { |
|
| 1533 | + spip_sql_erreur($serveur); |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + return $r; |
|
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | /** |
@@ -1553,16 +1553,16 @@ discard block |
||
| 1553 | 1553 | * - true si la requête a réussie, false sinon |
| 1554 | 1554 | */ |
| 1555 | 1555 | function sql_repair($table, $serveur = '', $option = true) { |
| 1556 | - $f = sql_serveur('repair', $serveur, $option === 'continue' or $option === false); |
|
| 1557 | - if (!is_string($f) or !$f) { |
|
| 1558 | - return false; |
|
| 1559 | - } |
|
| 1560 | - $r = $f($table, $serveur, $option !== false); |
|
| 1561 | - if ($r === false) { |
|
| 1562 | - spip_sql_erreur($serveur); |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - return $r; |
|
| 1556 | + $f = sql_serveur('repair', $serveur, $option === 'continue' or $option === false); |
|
| 1557 | + if (!is_string($f) or !$f) { |
|
| 1558 | + return false; |
|
| 1559 | + } |
|
| 1560 | + $r = $f($table, $serveur, $option !== false); |
|
| 1561 | + if ($r === false) { |
|
| 1562 | + spip_sql_erreur($serveur); |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + return $r; |
|
| 1566 | 1566 | } |
| 1567 | 1567 | |
| 1568 | 1568 | |
@@ -1587,16 +1587,16 @@ discard block |
||
| 1587 | 1587 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 1588 | 1588 | */ |
| 1589 | 1589 | function sql_query($ins, $serveur = '', $option = true) { |
| 1590 | - $f = sql_serveur('query', $serveur, $option === 'continue' or $option === false); |
|
| 1591 | - if (!is_string($f) or !$f) { |
|
| 1592 | - return false; |
|
| 1593 | - } |
|
| 1594 | - $r = $f($ins, $serveur, $option !== false); |
|
| 1595 | - if ($r === false) { |
|
| 1596 | - spip_sql_erreur($serveur); |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - return $r; |
|
| 1590 | + $f = sql_serveur('query', $serveur, $option === 'continue' or $option === false); |
|
| 1591 | + if (!is_string($f) or !$f) { |
|
| 1592 | + return false; |
|
| 1593 | + } |
|
| 1594 | + $r = $f($ins, $serveur, $option !== false); |
|
| 1595 | + if ($r === false) { |
|
| 1596 | + spip_sql_erreur($serveur); |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + return $r; |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | 1602 | /** |
@@ -1644,27 +1644,27 @@ discard block |
||
| 1644 | 1644 | * |
| 1645 | 1645 | **/ |
| 1646 | 1646 | function sql_fetsel( |
| 1647 | - $select = [], |
|
| 1648 | - $from = [], |
|
| 1649 | - $where = [], |
|
| 1650 | - $groupby = [], |
|
| 1651 | - $orderby = [], |
|
| 1652 | - $limit = '', |
|
| 1653 | - $having = [], |
|
| 1654 | - $serveur = '', |
|
| 1655 | - $option = true |
|
| 1647 | + $select = [], |
|
| 1648 | + $from = [], |
|
| 1649 | + $where = [], |
|
| 1650 | + $groupby = [], |
|
| 1651 | + $orderby = [], |
|
| 1652 | + $limit = '', |
|
| 1653 | + $having = [], |
|
| 1654 | + $serveur = '', |
|
| 1655 | + $option = true |
|
| 1656 | 1656 | ) { |
| 1657 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1658 | - if ($option === false) { |
|
| 1659 | - return $q; |
|
| 1660 | - } |
|
| 1661 | - if (!$q) { |
|
| 1662 | - return []; |
|
| 1663 | - } |
|
| 1664 | - $r = sql_fetch($q, $serveur, $option); |
|
| 1665 | - sql_free($q, $serveur, $option); |
|
| 1666 | - |
|
| 1667 | - return $r; |
|
| 1657 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1658 | + if ($option === false) { |
|
| 1659 | + return $q; |
|
| 1660 | + } |
|
| 1661 | + if (!$q) { |
|
| 1662 | + return []; |
|
| 1663 | + } |
|
| 1664 | + $r = sql_fetch($q, $serveur, $option); |
|
| 1665 | + sql_free($q, $serveur, $option); |
|
| 1666 | + |
|
| 1667 | + return $r; |
|
| 1668 | 1668 | } |
| 1669 | 1669 | |
| 1670 | 1670 | |
@@ -1721,22 +1721,22 @@ discard block |
||
| 1721 | 1721 | * |
| 1722 | 1722 | **/ |
| 1723 | 1723 | function sql_allfetsel( |
| 1724 | - $select = [], |
|
| 1725 | - $from = [], |
|
| 1726 | - $where = [], |
|
| 1727 | - $groupby = [], |
|
| 1728 | - $orderby = [], |
|
| 1729 | - $limit = '', |
|
| 1730 | - $having = [], |
|
| 1731 | - $serveur = '', |
|
| 1732 | - $option = true |
|
| 1724 | + $select = [], |
|
| 1725 | + $from = [], |
|
| 1726 | + $where = [], |
|
| 1727 | + $groupby = [], |
|
| 1728 | + $orderby = [], |
|
| 1729 | + $limit = '', |
|
| 1730 | + $having = [], |
|
| 1731 | + $serveur = '', |
|
| 1732 | + $option = true |
|
| 1733 | 1733 | ) { |
| 1734 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1735 | - if ($option === false) { |
|
| 1736 | - return $q; |
|
| 1737 | - } |
|
| 1734 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1735 | + if ($option === false) { |
|
| 1736 | + return $q; |
|
| 1737 | + } |
|
| 1738 | 1738 | |
| 1739 | - return sql_fetch_all($q, $serveur, $option); |
|
| 1739 | + return sql_fetch_all($q, $serveur, $option); |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | |
@@ -1783,33 +1783,33 @@ discard block |
||
| 1783 | 1783 | * |
| 1784 | 1784 | **/ |
| 1785 | 1785 | function sql_getfetsel( |
| 1786 | - $select, |
|
| 1787 | - $from = [], |
|
| 1788 | - $where = [], |
|
| 1789 | - $groupby = [], |
|
| 1790 | - $orderby = [], |
|
| 1791 | - $limit = '', |
|
| 1792 | - $having = [], |
|
| 1793 | - $serveur = '', |
|
| 1794 | - $option = true |
|
| 1786 | + $select, |
|
| 1787 | + $from = [], |
|
| 1788 | + $where = [], |
|
| 1789 | + $groupby = [], |
|
| 1790 | + $orderby = [], |
|
| 1791 | + $limit = '', |
|
| 1792 | + $having = [], |
|
| 1793 | + $serveur = '', |
|
| 1794 | + $option = true |
|
| 1795 | 1795 | ) { |
| 1796 | - if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1797 | - $id = $c[1]; |
|
| 1798 | - } elseif (!preg_match('/\W/', $select)) { |
|
| 1799 | - $id = $select; |
|
| 1800 | - } else { |
|
| 1801 | - $id = 'n'; |
|
| 1802 | - $select .= ' AS n'; |
|
| 1803 | - } |
|
| 1804 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1805 | - if ($option === false) { |
|
| 1806 | - return $r; |
|
| 1807 | - } |
|
| 1808 | - if (!$r) { |
|
| 1809 | - return null; |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - return $r[$id]; |
|
| 1796 | + if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1797 | + $id = $c[1]; |
|
| 1798 | + } elseif (!preg_match('/\W/', $select)) { |
|
| 1799 | + $id = $select; |
|
| 1800 | + } else { |
|
| 1801 | + $id = 'n'; |
|
| 1802 | + $select .= ' AS n'; |
|
| 1803 | + } |
|
| 1804 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 1805 | + if ($option === false) { |
|
| 1806 | + return $r; |
|
| 1807 | + } |
|
| 1808 | + if (!$r) { |
|
| 1809 | + return null; |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + return $r[$id]; |
|
| 1813 | 1813 | } |
| 1814 | 1814 | |
| 1815 | 1815 | /** |
@@ -1827,9 +1827,9 @@ discard block |
||
| 1827 | 1827 | * Numero de version du serveur SQL |
| 1828 | 1828 | **/ |
| 1829 | 1829 | function sql_version($serveur = '', $option = true) { |
| 1830 | - $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1830 | + $row = sql_fetsel('version() AS n', '', '', '', '', '', '', $serveur); |
|
| 1831 | 1831 | |
| 1832 | - return ($row['n']); |
|
| 1832 | + return ($row['n']); |
|
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | /** |
@@ -1865,16 +1865,16 @@ discard block |
||
| 1865 | 1865 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function sql_preferer_transaction($serveur = '', $option = true) { |
| 1868 | - $f = sql_serveur('preferer_transaction', $serveur, true); |
|
| 1869 | - if (!is_string($f) or !$f) { |
|
| 1870 | - return false; |
|
| 1871 | - } |
|
| 1872 | - $r = $f($serveur, $option !== false); |
|
| 1873 | - if ($r === false) { |
|
| 1874 | - spip_sql_erreur($serveur); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - return $r; |
|
| 1868 | + $f = sql_serveur('preferer_transaction', $serveur, true); |
|
| 1869 | + if (!is_string($f) or !$f) { |
|
| 1870 | + return false; |
|
| 1871 | + } |
|
| 1872 | + $r = $f($serveur, $option !== false); |
|
| 1873 | + if ($r === false) { |
|
| 1874 | + spip_sql_erreur($serveur); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + return $r; |
|
| 1878 | 1878 | } |
| 1879 | 1879 | |
| 1880 | 1880 | ; |
@@ -1899,16 +1899,16 @@ discard block |
||
| 1899 | 1899 | * false en cas d'erreur |
| 1900 | 1900 | **/ |
| 1901 | 1901 | function sql_demarrer_transaction($serveur = '', $option = true) { |
| 1902 | - $f = sql_serveur('demarrer_transaction', $serveur, true); |
|
| 1903 | - if (!is_string($f) or !$f) { |
|
| 1904 | - return false; |
|
| 1905 | - } |
|
| 1906 | - $r = $f($serveur, $option !== false); |
|
| 1907 | - if ($r === false) { |
|
| 1908 | - spip_sql_erreur($serveur); |
|
| 1909 | - } |
|
| 1910 | - |
|
| 1911 | - return $r; |
|
| 1902 | + $f = sql_serveur('demarrer_transaction', $serveur, true); |
|
| 1903 | + if (!is_string($f) or !$f) { |
|
| 1904 | + return false; |
|
| 1905 | + } |
|
| 1906 | + $r = $f($serveur, $option !== false); |
|
| 1907 | + if ($r === false) { |
|
| 1908 | + spip_sql_erreur($serveur); |
|
| 1909 | + } |
|
| 1910 | + |
|
| 1911 | + return $r; |
|
| 1912 | 1912 | } |
| 1913 | 1913 | |
| 1914 | 1914 | ; |
@@ -1933,16 +1933,16 @@ discard block |
||
| 1933 | 1933 | * false en cas d'erreur |
| 1934 | 1934 | **/ |
| 1935 | 1935 | function sql_terminer_transaction($serveur = '', $option = true) { |
| 1936 | - $f = sql_serveur('terminer_transaction', $serveur, true); |
|
| 1937 | - if (!is_string($f) or !$f) { |
|
| 1938 | - return false; |
|
| 1939 | - } |
|
| 1940 | - $r = $f($serveur, $option !== false); |
|
| 1941 | - if ($r === false) { |
|
| 1942 | - spip_sql_erreur($serveur); |
|
| 1943 | - } |
|
| 1944 | - |
|
| 1945 | - return $r; |
|
| 1936 | + $f = sql_serveur('terminer_transaction', $serveur, true); |
|
| 1937 | + if (!is_string($f) or !$f) { |
|
| 1938 | + return false; |
|
| 1939 | + } |
|
| 1940 | + $r = $f($serveur, $option !== false); |
|
| 1941 | + if ($r === false) { |
|
| 1942 | + spip_sql_erreur($serveur); |
|
| 1943 | + } |
|
| 1944 | + |
|
| 1945 | + return $r; |
|
| 1946 | 1946 | } |
| 1947 | 1947 | |
| 1948 | 1948 | ; |
@@ -1969,12 +1969,12 @@ discard block |
||
| 1969 | 1969 | * Valeur hexadécimale attendue par le serveur SQL |
| 1970 | 1970 | **/ |
| 1971 | 1971 | function sql_hex($val, $serveur = '', $option = true) { |
| 1972 | - $f = sql_serveur('hex', $serveur, $option === 'continue' or $option === false); |
|
| 1973 | - if (!is_string($f) or !$f) { |
|
| 1974 | - return false; |
|
| 1975 | - } |
|
| 1972 | + $f = sql_serveur('hex', $serveur, $option === 'continue' or $option === false); |
|
| 1973 | + if (!is_string($f) or !$f) { |
|
| 1974 | + return false; |
|
| 1975 | + } |
|
| 1976 | 1976 | |
| 1977 | - return $f($val); |
|
| 1977 | + return $f($val); |
|
| 1978 | 1978 | } |
| 1979 | 1979 | |
| 1980 | 1980 | /** |
@@ -2000,12 +2000,12 @@ discard block |
||
| 2000 | 2000 | * La chaine echappee |
| 2001 | 2001 | **/ |
| 2002 | 2002 | function sql_quote($val, $serveur = '', $type = '') { |
| 2003 | - $f = sql_serveur('quote', $serveur, true); |
|
| 2004 | - if (!is_string($f) or !$f) { |
|
| 2005 | - $f = '_q'; |
|
| 2006 | - } |
|
| 2003 | + $f = sql_serveur('quote', $serveur, true); |
|
| 2004 | + if (!is_string($f) or !$f) { |
|
| 2005 | + $f = '_q'; |
|
| 2006 | + } |
|
| 2007 | 2007 | |
| 2008 | - return $f($val, $type); |
|
| 2008 | + return $f($val, $type); |
|
| 2009 | 2009 | } |
| 2010 | 2010 | |
| 2011 | 2011 | /** |
@@ -2030,12 +2030,12 @@ discard block |
||
| 2030 | 2030 | * - false si le serveur SQL est indisponible |
| 2031 | 2031 | **/ |
| 2032 | 2032 | function sql_date_proche($champ, $interval, $unite, $serveur = '', $option = true) { |
| 2033 | - $f = sql_serveur('date_proche', $serveur, true); |
|
| 2034 | - if (!is_string($f) or !$f) { |
|
| 2035 | - return false; |
|
| 2036 | - } |
|
| 2033 | + $f = sql_serveur('date_proche', $serveur, true); |
|
| 2034 | + if (!is_string($f) or !$f) { |
|
| 2035 | + return false; |
|
| 2036 | + } |
|
| 2037 | 2037 | |
| 2038 | - return $f($champ, $interval, $unite); |
|
| 2038 | + return $f($champ, $interval, $unite); |
|
| 2039 | 2039 | } |
| 2040 | 2040 | |
| 2041 | 2041 | /** |
@@ -2071,26 +2071,26 @@ discard block |
||
| 2071 | 2071 | * Expression de requête SQL |
| 2072 | 2072 | **/ |
| 2073 | 2073 | function sql_in_quote($champ, $valeurs, $not = '', $serveur = '', $type = '', $option = true) { |
| 2074 | - $quote = sql_serveur('quote', $serveur, true); |
|
| 2075 | - if (!is_string($quote) or !$quote) { |
|
| 2076 | - return false; |
|
| 2077 | - } |
|
| 2078 | - |
|
| 2079 | - // sql_quote produit une chaine dans tous les cas |
|
| 2080 | - $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2081 | - $valeurs = array_unique($valeurs); |
|
| 2082 | - $valeurs = $quote($valeurs, $type); |
|
| 2083 | - |
|
| 2084 | - if (!strlen(trim($valeurs))) { |
|
| 2085 | - return ($not ? '0=0' : '0=1'); |
|
| 2086 | - } |
|
| 2087 | - |
|
| 2088 | - $f = sql_serveur('in', $serveur, $option === 'continue' or $option === false); |
|
| 2089 | - if (!is_string($f) or !$f) { |
|
| 2090 | - return false; |
|
| 2091 | - } |
|
| 2092 | - |
|
| 2093 | - return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2074 | + $quote = sql_serveur('quote', $serveur, true); |
|
| 2075 | + if (!is_string($quote) or !$quote) { |
|
| 2076 | + return false; |
|
| 2077 | + } |
|
| 2078 | + |
|
| 2079 | + // sql_quote produit une chaine dans tous les cas |
|
| 2080 | + $valeurs = array_filter($valeurs, fn($v) => !is_array($v)); |
|
| 2081 | + $valeurs = array_unique($valeurs); |
|
| 2082 | + $valeurs = $quote($valeurs, $type); |
|
| 2083 | + |
|
| 2084 | + if (!strlen(trim($valeurs))) { |
|
| 2085 | + return ($not ? '0=0' : '0=1'); |
|
| 2086 | + } |
|
| 2087 | + |
|
| 2088 | + $f = sql_serveur('in', $serveur, $option === 'continue' or $option === false); |
|
| 2089 | + if (!is_string($f) or !$f) { |
|
| 2090 | + return false; |
|
| 2091 | + } |
|
| 2092 | + |
|
| 2093 | + return $f($champ, $valeurs, $not ? 'NOT' : '', $serveur, $option !== false); |
|
| 2094 | 2094 | } |
| 2095 | 2095 | |
| 2096 | 2096 | /** |
@@ -2107,19 +2107,19 @@ discard block |
||
| 2107 | 2107 | * @param bool $option |
| 2108 | 2108 | */ |
| 2109 | 2109 | function sql_in($champ, $valeurs, $not = '', $serveur = '', $option = true) { |
| 2110 | - $type = ''; |
|
| 2111 | - if (!is_array($valeurs)) { |
|
| 2112 | - $valeurs = strval($valeurs); |
|
| 2113 | - if (isset($valeurs[0]) and $valeurs[0] === ',') { |
|
| 2114 | - $valeurs = substr($valeurs, 1); |
|
| 2115 | - } |
|
| 2116 | - // on explode en tableau pour pouvoir securiser le contenu |
|
| 2117 | - $valeurs = explode(',', $valeurs); |
|
| 2118 | - // et on force un cast de type int donc |
|
| 2119 | - $type = 'int'; |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2110 | + $type = ''; |
|
| 2111 | + if (!is_array($valeurs)) { |
|
| 2112 | + $valeurs = strval($valeurs); |
|
| 2113 | + if (isset($valeurs[0]) and $valeurs[0] === ',') { |
|
| 2114 | + $valeurs = substr($valeurs, 1); |
|
| 2115 | + } |
|
| 2116 | + // on explode en tableau pour pouvoir securiser le contenu |
|
| 2117 | + $valeurs = explode(',', $valeurs); |
|
| 2118 | + // et on force un cast de type int donc |
|
| 2119 | + $type = 'int'; |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + return sql_in_quote($champ, $valeurs, $not, $serveur, $type, $option); |
|
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | 2125 | |
@@ -2160,24 +2160,24 @@ discard block |
||
| 2160 | 2160 | * Expression de requête SQL |
| 2161 | 2161 | **/ |
| 2162 | 2162 | function sql_in_select( |
| 2163 | - $in, |
|
| 2164 | - $select, |
|
| 2165 | - $from = [], |
|
| 2166 | - $where = [], |
|
| 2167 | - $groupby = [], |
|
| 2168 | - $orderby = [], |
|
| 2169 | - $limit = '', |
|
| 2170 | - $having = [], |
|
| 2171 | - $serveur = '' |
|
| 2163 | + $in, |
|
| 2164 | + $select, |
|
| 2165 | + $from = [], |
|
| 2166 | + $where = [], |
|
| 2167 | + $groupby = [], |
|
| 2168 | + $orderby = [], |
|
| 2169 | + $limit = '', |
|
| 2170 | + $having = [], |
|
| 2171 | + $serveur = '' |
|
| 2172 | 2172 | ) { |
| 2173 | - $liste = []; |
|
| 2174 | - $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2175 | - while ($r = sql_fetch($res)) { |
|
| 2176 | - $liste[] = array_shift($r); |
|
| 2177 | - } |
|
| 2178 | - sql_free($res); |
|
| 2179 | - |
|
| 2180 | - return sql_in($in, $liste); |
|
| 2173 | + $liste = []; |
|
| 2174 | + $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 2175 | + while ($r = sql_fetch($res)) { |
|
| 2176 | + $liste[] = array_shift($r); |
|
| 2177 | + } |
|
| 2178 | + sql_free($res); |
|
| 2179 | + |
|
| 2180 | + return sql_in($in, $liste); |
|
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | 2183 | /** |
@@ -2209,29 +2209,29 @@ discard block |
||
| 2209 | 2209 | * Position apres le saut. |
| 2210 | 2210 | */ |
| 2211 | 2211 | function sql_skip($res, $pos, $saut, $count, $serveur = '', $option = true) { |
| 2212 | - // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2213 | - if (($saut = intval($saut)) <= 0) { |
|
| 2214 | - return $pos; |
|
| 2215 | - } |
|
| 2216 | - |
|
| 2217 | - $seek = $pos + $saut; |
|
| 2218 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 2219 | - // et on sort |
|
| 2220 | - if ($seek >= $count) { |
|
| 2221 | - sql_free($res, $serveur, $option); |
|
| 2222 | - |
|
| 2223 | - return $count; |
|
| 2224 | - } |
|
| 2225 | - |
|
| 2226 | - if (sql_seek($res, $seek)) { |
|
| 2227 | - $pos = $seek; |
|
| 2228 | - } else { |
|
| 2229 | - while ($pos < $seek and sql_fetch($res, $serveur, $option)) { |
|
| 2230 | - $pos++; |
|
| 2231 | - } |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - return $pos; |
|
| 2212 | + // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 2213 | + if (($saut = intval($saut)) <= 0) { |
|
| 2214 | + return $pos; |
|
| 2215 | + } |
|
| 2216 | + |
|
| 2217 | + $seek = $pos + $saut; |
|
| 2218 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 2219 | + // et on sort |
|
| 2220 | + if ($seek >= $count) { |
|
| 2221 | + sql_free($res, $serveur, $option); |
|
| 2222 | + |
|
| 2223 | + return $count; |
|
| 2224 | + } |
|
| 2225 | + |
|
| 2226 | + if (sql_seek($res, $seek)) { |
|
| 2227 | + $pos = $seek; |
|
| 2228 | + } else { |
|
| 2229 | + while ($pos < $seek and sql_fetch($res, $serveur, $option)) { |
|
| 2230 | + $pos++; |
|
| 2231 | + } |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + return $pos; |
|
| 2235 | 2235 | } |
| 2236 | 2236 | |
| 2237 | 2237 | |
@@ -2251,7 +2251,7 @@ discard block |
||
| 2251 | 2251 | * True si le champ est de type entier |
| 2252 | 2252 | */ |
| 2253 | 2253 | function sql_test_int($type, $serveur = '', $option = true) { |
| 2254 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2254 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | /** |
@@ -2270,7 +2270,7 @@ discard block |
||
| 2270 | 2270 | * True si le champ est de type entier |
| 2271 | 2271 | */ |
| 2272 | 2272 | function sql_test_date($type, $serveur = '', $option = true) { |
| 2273 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2273 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 2274 | 2274 | } |
| 2275 | 2275 | |
| 2276 | 2276 | /** |
@@ -2292,19 +2292,19 @@ discard block |
||
| 2292 | 2292 | * La date formatee |
| 2293 | 2293 | */ |
| 2294 | 2294 | function sql_format_date($annee = 0, $mois = 0, $jour = 0, $h = 0, $m = 0, $s = 0, $serveur = '') { |
| 2295 | - $annee = sprintf('%04s', $annee); |
|
| 2296 | - $mois = sprintf('%02s', $mois); |
|
| 2297 | - |
|
| 2298 | - if ($annee == '0000') { |
|
| 2299 | - $mois = 0; |
|
| 2300 | - } |
|
| 2301 | - if ($mois == '00') { |
|
| 2302 | - $jour = 0; |
|
| 2303 | - } |
|
| 2304 | - |
|
| 2305 | - return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2306 | - . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2307 | - . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2295 | + $annee = sprintf('%04s', $annee); |
|
| 2296 | + $mois = sprintf('%02s', $mois); |
|
| 2297 | + |
|
| 2298 | + if ($annee == '0000') { |
|
| 2299 | + $mois = 0; |
|
| 2300 | + } |
|
| 2301 | + if ($mois == '00') { |
|
| 2302 | + $jour = 0; |
|
| 2303 | + } |
|
| 2304 | + |
|
| 2305 | + return sprintf('%04u', $annee) . '-' . sprintf('%02u', $mois) . '-' |
|
| 2306 | + . sprintf('%02u', $jour) . ' ' . sprintf('%02u', $h) . ':' |
|
| 2307 | + . sprintf('%02u', $m) . ':' . sprintf('%02u', $s); |
|
| 2308 | 2308 | } |
| 2309 | 2309 | |
| 2310 | 2310 | |
@@ -2327,32 +2327,32 @@ discard block |
||
| 2327 | 2327 | **/ |
| 2328 | 2328 | function description_table($nom, $serveur = '') { |
| 2329 | 2329 | |
| 2330 | - static $trouver_table; |
|
| 2330 | + static $trouver_table; |
|
| 2331 | 2331 | |
| 2332 | - /* toujours utiliser trouver_table |
|
| 2332 | + /* toujours utiliser trouver_table |
|
| 2333 | 2333 | qui renverra la description theorique |
| 2334 | 2334 | car sinon on va se comporter differement selon que la table est declaree |
| 2335 | 2335 | ou non |
| 2336 | 2336 | */ |
| 2337 | - if (!$trouver_table) { |
|
| 2338 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2339 | - } |
|
| 2340 | - if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2341 | - return $desc; |
|
| 2342 | - } |
|
| 2343 | - |
|
| 2344 | - // sauf a l'installation : |
|
| 2345 | - include_spip('base/serial'); |
|
| 2346 | - if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2347 | - return $GLOBALS['tables_principales'][$nom]; |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - include_spip('base/auxiliaires'); |
|
| 2351 | - if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2352 | - return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - return false; |
|
| 2337 | + if (!$trouver_table) { |
|
| 2338 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2339 | + } |
|
| 2340 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 2341 | + return $desc; |
|
| 2342 | + } |
|
| 2343 | + |
|
| 2344 | + // sauf a l'installation : |
|
| 2345 | + include_spip('base/serial'); |
|
| 2346 | + if (isset($GLOBALS['tables_principales'][$nom])) { |
|
| 2347 | + return $GLOBALS['tables_principales'][$nom]; |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + include_spip('base/auxiliaires'); |
|
| 2351 | + if (isset($GLOBALS['tables_auxiliaires'][$nom])) { |
|
| 2352 | + return $GLOBALS['tables_auxiliaires'][$nom]; |
|
| 2353 | + } |
|
| 2354 | + |
|
| 2355 | + return false; |
|
| 2356 | 2356 | } |
| 2357 | 2357 | |
| 2358 | 2358 | /** |
@@ -2365,8 +2365,8 @@ discard block |
||
| 2365 | 2365 | * @return string Table sql éventuellement renommée |
| 2366 | 2366 | */ |
| 2367 | 2367 | function prefixer_table_spip($table, $prefixe) { |
| 2368 | - if ($prefixe) { |
|
| 2369 | - $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2370 | - } |
|
| 2371 | - return $table; |
|
| 2368 | + if ($prefixe) { |
|
| 2369 | + $table = preg_replace('/^spip_/', $prefixe . '_', $table); |
|
| 2370 | + } |
|
| 2371 | + return $table; |
|
| 2372 | 2372 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -43,90 +43,90 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | function _sqlite_init_functions(&$sqlite) { |
| 45 | 45 | |
| 46 | - if (!$sqlite) { |
|
| 47 | - return false; |
|
| 48 | - } |
|
| 46 | + if (!$sqlite) { |
|
| 47 | + return false; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - $fonctions = [ |
|
| 52 | - // A |
|
| 53 | - 'ACOS' => ['acos', 1], |
|
| 54 | - 'ASIN' => ['asin', 1], |
|
| 55 | - 'ATAN' => ['atan', 1], // mysql accepte 2 params comme atan2… hum ? |
|
| 56 | - 'ATAN2' => ['atan2', 2], |
|
| 51 | + $fonctions = [ |
|
| 52 | + // A |
|
| 53 | + 'ACOS' => ['acos', 1], |
|
| 54 | + 'ASIN' => ['asin', 1], |
|
| 55 | + 'ATAN' => ['atan', 1], // mysql accepte 2 params comme atan2… hum ? |
|
| 56 | + 'ATAN2' => ['atan2', 2], |
|
| 57 | 57 | |
| 58 | - // C |
|
| 59 | - 'CEIL' => ['_sqlite_func_ceil', 1], |
|
| 60 | - 'CONCAT' => ['_sqlite_func_concat', -1], |
|
| 61 | - 'COS' => ['cos', 1], |
|
| 58 | + // C |
|
| 59 | + 'CEIL' => ['_sqlite_func_ceil', 1], |
|
| 60 | + 'CONCAT' => ['_sqlite_func_concat', -1], |
|
| 61 | + 'COS' => ['cos', 1], |
|
| 62 | 62 | |
| 63 | - // D |
|
| 64 | - 'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés |
|
| 65 | - 'DAYOFMONTH' => ['_sqlite_func_dayofmonth', 1], |
|
| 66 | - 'DEGREES' => ['rad2deg', 1], |
|
| 63 | + // D |
|
| 64 | + 'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés |
|
| 65 | + 'DAYOFMONTH' => ['_sqlite_func_dayofmonth', 1], |
|
| 66 | + 'DEGREES' => ['rad2deg', 1], |
|
| 67 | 67 | |
| 68 | - // E |
|
| 69 | - 'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi() |
|
| 70 | - 'EXP' => ['exp', 1], |
|
| 68 | + // E |
|
| 69 | + 'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi() |
|
| 70 | + 'EXP' => ['exp', 1], |
|
| 71 | 71 | |
| 72 | - // F |
|
| 73 | - 'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2], |
|
| 74 | - 'FLOOR' => ['_sqlite_func_floor', 1], |
|
| 72 | + // F |
|
| 73 | + 'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2], |
|
| 74 | + 'FLOOR' => ['_sqlite_func_floor', 1], |
|
| 75 | 75 | |
| 76 | - // G |
|
| 77 | - 'GREATEST' => ['_sqlite_func_greatest', -1], |
|
| 76 | + // G |
|
| 77 | + 'GREATEST' => ['_sqlite_func_greatest', -1], |
|
| 78 | 78 | |
| 79 | - // I |
|
| 80 | - 'IF' => ['_sqlite_func_if', 3], |
|
| 81 | - 'INSERT' => ['_sqlite_func_insert', 4], |
|
| 82 | - 'INSTR' => ['_sqlite_func_instr', 2], |
|
| 79 | + // I |
|
| 80 | + 'IF' => ['_sqlite_func_if', 3], |
|
| 81 | + 'INSERT' => ['_sqlite_func_insert', 4], |
|
| 82 | + 'INSTR' => ['_sqlite_func_instr', 2], |
|
| 83 | 83 | |
| 84 | - // L |
|
| 85 | - 'LEAST' => ['_sqlite_func_least', -1], |
|
| 86 | - '_LEFT' => ['_sqlite_func_left', 2], |
|
| 84 | + // L |
|
| 85 | + 'LEAST' => ['_sqlite_func_least', -1], |
|
| 86 | + '_LEFT' => ['_sqlite_func_left', 2], |
|
| 87 | 87 | |
| 88 | - // N |
|
| 89 | - 'NOW' => ['_sqlite_func_now', 0], |
|
| 88 | + // N |
|
| 89 | + 'NOW' => ['_sqlite_func_now', 0], |
|
| 90 | 90 | |
| 91 | - // M |
|
| 92 | - 'MD5' => ['md5', 1], |
|
| 93 | - 'MONTH' => ['_sqlite_func_month', 1], |
|
| 91 | + // M |
|
| 92 | + 'MD5' => ['md5', 1], |
|
| 93 | + 'MONTH' => ['_sqlite_func_month', 1], |
|
| 94 | 94 | |
| 95 | - // P |
|
| 96 | - 'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3], |
|
| 95 | + // P |
|
| 96 | + 'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3], |
|
| 97 | 97 | |
| 98 | - // R |
|
| 99 | - 'RADIANS' => ['deg2rad', 1], |
|
| 100 | - 'RAND' => ['_sqlite_func_rand', 0], // sinon random() v2.4 |
|
| 101 | - 'REGEXP' => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2 |
|
| 102 | - 'RIGHT' => ['_sqlite_func_right', 2], |
|
| 98 | + // R |
|
| 99 | + 'RADIANS' => ['deg2rad', 1], |
|
| 100 | + 'RAND' => ['_sqlite_func_rand', 0], // sinon random() v2.4 |
|
| 101 | + 'REGEXP' => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2 |
|
| 102 | + 'RIGHT' => ['_sqlite_func_right', 2], |
|
| 103 | 103 | |
| 104 | - // S |
|
| 105 | - 'SETTYPE' => ['settype', 2], // CAST present en v3.2.3 |
|
| 106 | - 'SIN' => ['sin', 1], |
|
| 107 | - 'SQRT' => ['sqrt', 1], |
|
| 108 | - 'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 104 | + // S |
|
| 105 | + 'SETTYPE' => ['settype', 2], // CAST present en v3.2.3 |
|
| 106 | + 'SIN' => ['sin', 1], |
|
| 107 | + 'SQRT' => ['sqrt', 1], |
|
| 108 | + 'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 109 | 109 | |
| 110 | - // T |
|
| 111 | - 'TAN' => ['tan', 1], |
|
| 112 | - 'TIMESTAMPDIFF' => ['_sqlite_timestampdiff' /*, 3*/], |
|
| 113 | - 'TO_DAYS' => ['_sqlite_func_to_days', 1], |
|
| 110 | + // T |
|
| 111 | + 'TAN' => ['tan', 1], |
|
| 112 | + 'TIMESTAMPDIFF' => ['_sqlite_timestampdiff' /*, 3*/], |
|
| 113 | + 'TO_DAYS' => ['_sqlite_func_to_days', 1], |
|
| 114 | 114 | |
| 115 | - // U |
|
| 116 | - 'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1], |
|
| 115 | + // U |
|
| 116 | + 'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1], |
|
| 117 | 117 | |
| 118 | - // V |
|
| 119 | - 'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 118 | + // V |
|
| 119 | + 'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 120 | 120 | |
| 121 | - // Y |
|
| 122 | - 'YEAR' => ['_sqlite_func_year', 1] |
|
| 123 | - ]; |
|
| 121 | + // Y |
|
| 122 | + 'YEAR' => ['_sqlite_func_year', 1] |
|
| 123 | + ]; |
|
| 124 | 124 | |
| 125 | - foreach ($fonctions as $f => $r) { |
|
| 126 | - _sqlite_add_function($sqlite, $f, $r); |
|
| 127 | - } |
|
| 125 | + foreach ($fonctions as $f => $r) { |
|
| 126 | + _sqlite_add_function($sqlite, $f, $r); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 129 | + #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | **/ |
| 149 | 149 | function _sqlite_add_function(&$sqlite, &$f, &$r) { |
| 150 | - isset($r[1]) |
|
| 151 | - ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 152 | - : $sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 150 | + isset($r[1]) |
|
| 151 | + ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 152 | + : $sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @return int |
| 160 | 160 | */ |
| 161 | 161 | function _sqlite_func_ceil($a) { |
| 162 | - return ceil($a); |
|
| 162 | + return ceil($a); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @return string |
| 170 | 170 | */ |
| 171 | 171 | function _sqlite_func_concat(...$args) { |
| 172 | - return join('', $args); |
|
| 172 | + return join('', $args); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | 184 | function _sqlite_func_dayofmonth($d) { |
| 185 | - return _sqlite_func_date('d', $d); |
|
| 185 | + return _sqlite_func_date('d', $d); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
@@ -194,15 +194,15 @@ discard block |
||
| 194 | 194 | * @return int |
| 195 | 195 | */ |
| 196 | 196 | function _sqlite_func_find_in_set($num, $set) { |
| 197 | - $rank = 0; |
|
| 198 | - foreach (explode(',', $set) as $v) { |
|
| 199 | - if ($v == $num) { |
|
| 200 | - return (++$rank); |
|
| 201 | - } |
|
| 202 | - $rank++; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return 0; |
|
| 197 | + $rank = 0; |
|
| 198 | + foreach (explode(',', $set) as $v) { |
|
| 199 | + if ($v == $num) { |
|
| 200 | + return (++$rank); |
|
| 201 | + } |
|
| 202 | + $rank++; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return 0; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @return int |
| 213 | 213 | */ |
| 214 | 214 | function _sqlite_func_floor($a) { |
| 215 | - return floor($a); |
|
| 215 | + return floor($a); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @return mixed |
| 226 | 226 | */ |
| 227 | 227 | function _sqlite_func_if($bool, $oui, $non) { |
| 228 | - return ($bool) ? $oui : $non; |
|
| 228 | + return ($bool) ? $oui : $non; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | 244 | function _sqlite_func_insert($s, $index, $longueur, $chaine) { |
| 245 | - return |
|
| 246 | - substr($s, 0, $index) |
|
| 247 | - . $chaine |
|
| 248 | - . substr(substr($s, $index), $longueur); |
|
| 245 | + return |
|
| 246 | + substr($s, 0, $index) |
|
| 247 | + . $chaine |
|
| 248 | + . substr(substr($s, $index), $longueur); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return int |
| 258 | 258 | */ |
| 259 | 259 | function _sqlite_func_instr($s, $search) { |
| 260 | - return strpos($s, $search); |
|
| 260 | + return strpos($s, $search); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * @return int |
| 269 | 269 | */ |
| 270 | 270 | function _sqlite_func_least(...$args) { |
| 271 | - return min($args); |
|
| 271 | + return min($args); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @return int |
| 280 | 280 | */ |
| 281 | 281 | function _sqlite_func_greatest(...$args) { |
| 282 | - return max($args); |
|
| 282 | + return max($args); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | 293 | function _sqlite_func_left($s, $lenght) { |
| 294 | - return substr($s, $lenght); |
|
| 294 | + return substr($s, $lenght); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -301,13 +301,13 @@ discard block |
||
| 301 | 301 | * @return string |
| 302 | 302 | */ |
| 303 | 303 | function _sqlite_func_now($force_refresh = false) { |
| 304 | - static $now = null; |
|
| 305 | - if (is_null($now) or $force_refresh) { |
|
| 306 | - $now = date('Y-m-d H:i:s'); |
|
| 307 | - } |
|
| 304 | + static $now = null; |
|
| 305 | + if (is_null($now) or $force_refresh) { |
|
| 306 | + $now = date('Y-m-d H:i:s'); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG); |
|
| 310 | - return $now; |
|
| 309 | + #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG); |
|
| 310 | + return $now; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @return string |
| 321 | 321 | */ |
| 322 | 322 | function _sqlite_func_month($d) { |
| 323 | - return _sqlite_func_date('m', $d); |
|
| 323 | + return _sqlite_func_date('m', $d); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | |
@@ -333,10 +333,10 @@ discard block |
||
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | 335 | function _sqlite_func_preg_replace($quoi, $cherche, $remplace) { |
| 336 | - $return = preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 336 | + $return = preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 337 | 337 | |
| 338 | - #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 339 | - return $return; |
|
| 338 | + #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 339 | + return $return; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -349,26 +349,26 @@ discard block |
||
| 349 | 349 | * @return string, l'extrait trouve. |
| 350 | 350 | **/ |
| 351 | 351 | function _sqlite_func_extraire_multi($quoi, $lang) { |
| 352 | - if (!defined('_EXTRAIRE_MULTI')) { |
|
| 353 | - include_spip('inc/filtres'); |
|
| 354 | - } |
|
| 355 | - if (!function_exists('approcher_langue')) { |
|
| 356 | - include_spip('inc/lang'); |
|
| 357 | - } |
|
| 358 | - if (preg_match_all(_EXTRAIRE_MULTI, $quoi, $regs, PREG_SET_ORDER)) { |
|
| 359 | - foreach ($regs as $reg) { |
|
| 360 | - // chercher la version de la langue courante |
|
| 361 | - $trads = extraire_trads($reg[1]); |
|
| 362 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 363 | - $trad = $trads[$l]; |
|
| 364 | - } else { |
|
| 365 | - $trad = reset($trads); |
|
| 366 | - } |
|
| 367 | - $quoi = str_replace($reg[0], $trad, $quoi); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return $quoi; |
|
| 352 | + if (!defined('_EXTRAIRE_MULTI')) { |
|
| 353 | + include_spip('inc/filtres'); |
|
| 354 | + } |
|
| 355 | + if (!function_exists('approcher_langue')) { |
|
| 356 | + include_spip('inc/lang'); |
|
| 357 | + } |
|
| 358 | + if (preg_match_all(_EXTRAIRE_MULTI, $quoi, $regs, PREG_SET_ORDER)) { |
|
| 359 | + foreach ($regs as $reg) { |
|
| 360 | + // chercher la version de la langue courante |
|
| 361 | + $trads = extraire_trads($reg[1]); |
|
| 362 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 363 | + $trad = $trads[$l]; |
|
| 364 | + } else { |
|
| 365 | + $trad = reset($trads); |
|
| 366 | + } |
|
| 367 | + $quoi = str_replace($reg[0], $trad, $quoi); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return $quoi; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | * @return float |
| 379 | 379 | */ |
| 380 | 380 | function _sqlite_func_rand() { |
| 381 | - return random_int(0, mt_getrandmax()); |
|
| 381 | + return random_int(0, mt_getrandmax()); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | * @return string |
| 391 | 391 | */ |
| 392 | 392 | function _sqlite_func_right($s, $length) { |
| 393 | - return substr($s, 0 - $length); |
|
| 393 | + return substr($s, 0 - $length); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
@@ -402,17 +402,17 @@ discard block |
||
| 402 | 402 | * @return bool |
| 403 | 403 | */ |
| 404 | 404 | function _sqlite_func_regexp_match($cherche, $quoi) { |
| 405 | - // optimiser un cas tres courant avec les requetes en base |
|
| 406 | - if (!$quoi and !strlen($quoi)) { |
|
| 407 | - return false; |
|
| 408 | - } |
|
| 409 | - // il faut enlever un niveau d'echappement pour être homogène à mysql |
|
| 410 | - $cherche = str_replace('\\\\', '\\', $cherche); |
|
| 411 | - $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
|
| 412 | - $return = preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 413 | - |
|
| 414 | - #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 415 | - return $return; |
|
| 405 | + // optimiser un cas tres courant avec les requetes en base |
|
| 406 | + if (!$quoi and !strlen($quoi)) { |
|
| 407 | + return false; |
|
| 408 | + } |
|
| 409 | + // il faut enlever un niveau d'echappement pour être homogène à mysql |
|
| 410 | + $cherche = str_replace('\\\\', '\\', $cherche); |
|
| 411 | + $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
|
| 412 | + $return = preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 413 | + |
|
| 414 | + #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 415 | + return $return; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
@@ -427,8 +427,8 @@ discard block |
||
| 427 | 427 | * @return string |
| 428 | 428 | */ |
| 429 | 429 | function _sqlite_func_date_format($date, $conv) { |
| 430 | - $conv = _sqlite_func_strftime_format_converter($conv); |
|
| 431 | - return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 430 | + $conv = _sqlite_func_strftime_format_converter($conv); |
|
| 431 | + return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -444,28 +444,28 @@ discard block |
||
| 444 | 444 | * @return void |
| 445 | 445 | */ |
| 446 | 446 | function _sqlite_func_strftime_format_converter(string $conv): string { |
| 447 | - // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y |
|
| 448 | - // on ne sait pas en gérer certains... |
|
| 449 | - static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X']; |
|
| 450 | - static $mysql_to_strftime = [ |
|
| 451 | - '%h' => '%I', |
|
| 452 | - '%i' => '%M', |
|
| 453 | - '%M' => '%B', |
|
| 454 | - '%s' => '%S', |
|
| 455 | - '%u' => '%U', |
|
| 456 | - '%v' => '%V', |
|
| 457 | - '%x' => '%G', |
|
| 458 | - ]; |
|
| 459 | - static $to_strftime = []; |
|
| 460 | - if (!isset($to_strftime[$conv])) { |
|
| 461 | - $count = 0; |
|
| 462 | - str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
|
| 463 | - if ($count > 0) { |
|
| 464 | - spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 465 | - } |
|
| 466 | - $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
|
| 467 | - } |
|
| 468 | - return $to_strftime[$conv]; |
|
| 447 | + // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y |
|
| 448 | + // on ne sait pas en gérer certains... |
|
| 449 | + static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X']; |
|
| 450 | + static $mysql_to_strftime = [ |
|
| 451 | + '%h' => '%I', |
|
| 452 | + '%i' => '%M', |
|
| 453 | + '%M' => '%B', |
|
| 454 | + '%s' => '%S', |
|
| 455 | + '%u' => '%U', |
|
| 456 | + '%v' => '%V', |
|
| 457 | + '%x' => '%G', |
|
| 458 | + ]; |
|
| 459 | + static $to_strftime = []; |
|
| 460 | + if (!isset($to_strftime[$conv])) { |
|
| 461 | + $count = 0; |
|
| 462 | + str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
|
| 463 | + if ($count > 0) { |
|
| 464 | + spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 465 | + } |
|
| 466 | + $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
|
| 467 | + } |
|
| 468 | + return $to_strftime[$conv]; |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | /** |
@@ -479,11 +479,11 @@ discard block |
||
| 479 | 479 | * @return int |
| 480 | 480 | */ |
| 481 | 481 | function _sqlite_func_to_days($d) { |
| 482 | - static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 483 | - $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 482 | + static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 483 | + $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 484 | 484 | |
| 485 | - #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 486 | - return $result; |
|
| 485 | + #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 486 | + return $result; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -495,13 +495,13 @@ discard block |
||
| 495 | 495 | * @return string |
| 496 | 496 | */ |
| 497 | 497 | function _sqlite_func_substring($string, $start, $len = null) { |
| 498 | - // SQL compte a partir de 1, php a partir de 0 |
|
| 499 | - $start = ($start > 0) ? $start - 1 : $start; |
|
| 500 | - if (is_null($len)) { |
|
| 501 | - return substr($string, $start); |
|
| 502 | - } else { |
|
| 503 | - return substr($string, $start, $len); |
|
| 504 | - } |
|
| 498 | + // SQL compte a partir de 1, php a partir de 0 |
|
| 499 | + $start = ($start > 0) ? $start - 1 : $start; |
|
| 500 | + if (is_null($len)) { |
|
| 501 | + return substr($string, $start); |
|
| 502 | + } else { |
|
| 503 | + return substr($string, $start, $len); |
|
| 504 | + } |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
@@ -517,33 +517,33 @@ discard block |
||
| 517 | 517 | * @return int |
| 518 | 518 | */ |
| 519 | 519 | function _sqlite_timestampdiff($unit, $date1, $date2) { |
| 520 | - $d1 = date_create($date1); |
|
| 521 | - $d2 = date_create($date2); |
|
| 522 | - $diff = date_diff($d1, $d2); |
|
| 523 | - $inv = $diff->invert ? -1 : 1; |
|
| 524 | - switch ($unit) { |
|
| 525 | - case 'YEAR': |
|
| 526 | - return $inv * $diff->y; |
|
| 527 | - case 'QUARTER': |
|
| 528 | - return $inv * (4 * $diff->y + intval(floor($diff->m / 3))); |
|
| 529 | - case 'MONTH': |
|
| 530 | - return $inv * (12 * $diff->y + $diff->m); |
|
| 531 | - case 'WEEK': |
|
| 532 | - return $inv * intval(floor($diff->days / 7)); |
|
| 533 | - case 'DAY': |
|
| 534 | - #var_dump($inv*$diff->days); |
|
| 535 | - return $inv * $diff->days; |
|
| 536 | - case 'HOUR': |
|
| 537 | - return $inv * (24 * $diff->days + $diff->h); |
|
| 538 | - case 'MINUTE': |
|
| 539 | - return $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i); |
|
| 540 | - case 'SECOND': |
|
| 541 | - return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s); |
|
| 542 | - case 'MICROSECOND': |
|
| 543 | - return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return 0; |
|
| 520 | + $d1 = date_create($date1); |
|
| 521 | + $d2 = date_create($date2); |
|
| 522 | + $diff = date_diff($d1, $d2); |
|
| 523 | + $inv = $diff->invert ? -1 : 1; |
|
| 524 | + switch ($unit) { |
|
| 525 | + case 'YEAR': |
|
| 526 | + return $inv * $diff->y; |
|
| 527 | + case 'QUARTER': |
|
| 528 | + return $inv * (4 * $diff->y + intval(floor($diff->m / 3))); |
|
| 529 | + case 'MONTH': |
|
| 530 | + return $inv * (12 * $diff->y + $diff->m); |
|
| 531 | + case 'WEEK': |
|
| 532 | + return $inv * intval(floor($diff->days / 7)); |
|
| 533 | + case 'DAY': |
|
| 534 | + #var_dump($inv*$diff->days); |
|
| 535 | + return $inv * $diff->days; |
|
| 536 | + case 'HOUR': |
|
| 537 | + return $inv * (24 * $diff->days + $diff->h); |
|
| 538 | + case 'MINUTE': |
|
| 539 | + return $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i); |
|
| 540 | + case 'SECOND': |
|
| 541 | + return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s); |
|
| 542 | + case 'MICROSECOND': |
|
| 543 | + return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return 0; |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -553,24 +553,24 @@ discard block |
||
| 553 | 553 | * @return int |
| 554 | 554 | */ |
| 555 | 555 | function _sqlite_func_unix_timestamp($d) { |
| 556 | - static $mem = []; |
|
| 557 | - static $n = 0; |
|
| 558 | - if (isset($mem[$d])) { |
|
| 559 | - return $mem[$d]; |
|
| 560 | - } |
|
| 561 | - if ($n++ > 100) { |
|
| 562 | - $mem = []; |
|
| 563 | - $n = 0; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - //2005-12-02 20:53:53 |
|
| 567 | - #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 568 | - if (!$d) { |
|
| 569 | - return $mem[$d] = time(); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // une pile plus grosse n'accelere pas le calcul |
|
| 573 | - return $mem[$d] = strtotime($d); |
|
| 556 | + static $mem = []; |
|
| 557 | + static $n = 0; |
|
| 558 | + if (isset($mem[$d])) { |
|
| 559 | + return $mem[$d]; |
|
| 560 | + } |
|
| 561 | + if ($n++ > 100) { |
|
| 562 | + $mem = []; |
|
| 563 | + $n = 0; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + //2005-12-02 20:53:53 |
|
| 567 | + #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 568 | + if (!$d) { |
|
| 569 | + return $mem[$d] = time(); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // une pile plus grosse n'accelere pas le calcul |
|
| 573 | + return $mem[$d] = strtotime($d); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | * @return string |
| 584 | 584 | */ |
| 585 | 585 | function _sqlite_func_year($d) { |
| 586 | - return _sqlite_func_date('Y', $d); |
|
| 586 | + return _sqlite_func_date('Y', $d); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
@@ -596,20 +596,20 @@ discard block |
||
| 596 | 596 | * @return string |
| 597 | 597 | */ |
| 598 | 598 | function _sqlite_func_date($quoi, $d) { |
| 599 | - static $mem = []; |
|
| 600 | - static $n = 0; |
|
| 601 | - if (isset($mem[$d])) { |
|
| 602 | - return $mem[$d][$quoi]; |
|
| 603 | - } |
|
| 604 | - if ($n++ > 100) { |
|
| 605 | - $mem = []; |
|
| 606 | - $n = 0; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d)); |
|
| 610 | - $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)]; |
|
| 611 | - |
|
| 612 | - return $mem[$d][$quoi]; |
|
| 599 | + static $mem = []; |
|
| 600 | + static $n = 0; |
|
| 601 | + if (isset($mem[$d])) { |
|
| 602 | + return $mem[$d][$quoi]; |
|
| 603 | + } |
|
| 604 | + if ($n++ > 100) { |
|
| 605 | + $mem = []; |
|
| 606 | + $n = 0; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d)); |
|
| 610 | + $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)]; |
|
| 611 | + |
|
| 612 | + return $mem[$d][$quoi]; |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | /** |
@@ -618,5 +618,5 @@ discard block |
||
| 618 | 618 | * @return void |
| 619 | 619 | */ |
| 620 | 620 | function _sqlite_func_vide() { |
| 621 | - return; |
|
| 621 | + return; |
|
| 622 | 622 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * Pile complétée du code compilé |
| 38 | 38 | **/ |
| 39 | 39 | function balise_MENU_LANG($p) { |
| 40 | - return calculer_balise_dynamique($p, 'MENU_LANG', ['lang']); |
|
| 40 | + return calculer_balise_dynamique($p, 'MENU_LANG', ['lang']); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | * string: (vide) si pas de multilinguisme |
| 57 | 57 | */ |
| 58 | 58 | function balise_MENU_LANG_stat($args, $context_compil) { |
| 59 | - if (strpos($GLOBALS['meta']['langues_multilingue'], ',') === false) { |
|
| 60 | - return ''; |
|
| 61 | - } |
|
| 59 | + if (strpos($GLOBALS['meta']['langues_multilingue'], ',') === false) { |
|
| 60 | + return ''; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $args; |
|
| 63 | + return $args; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * Liste : Chemin du squelette, durée du cache, contexte |
| 77 | 77 | **/ |
| 78 | 78 | function balise_MENU_LANG_dyn($opt) { |
| 79 | - include_spip('balise/menu_lang_ecrire'); |
|
| 79 | + include_spip('balise/menu_lang_ecrire'); |
|
| 80 | 80 | |
| 81 | - return menu_lang_pour_tous('var_lang', $opt); |
|
| 81 | + return menu_lang_pour_tous('var_lang', $opt); |
|
| 82 | 82 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 26 | 26 | // ne pas ecraser une definition perso dans mes_options |
| 27 | 27 | if (!isset($GLOBALS['ldap_attributes']) or !is_array($GLOBALS['ldap_attributes'])) { |
| 28 | - $GLOBALS['ldap_attributes'] = [ |
|
| 29 | - 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 30 | - 'nom' => 'cn', |
|
| 31 | - 'email' => 'mail', |
|
| 32 | - 'bio' => 'description' |
|
| 33 | - ]; |
|
| 28 | + $GLOBALS['ldap_attributes'] = [ |
|
| 29 | + 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 30 | + 'nom' => 'cn', |
|
| 31 | + 'email' => 'mail', |
|
| 32 | + 'bio' => 'description' |
|
| 33 | + ]; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -56,50 +56,50 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function auth_ldap_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 58 | 58 | |
| 59 | - #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | - |
|
| 61 | - // Utilisateur connu ? |
|
| 62 | - // si http auth, inutile de reauthentifier: cela |
|
| 63 | - // ne marchera pas avec auth http autre que basic. |
|
| 64 | - $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 65 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | - return []; |
|
| 67 | - } |
|
| 68 | - $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 69 | - |
|
| 70 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | - |
|
| 73 | - if ($r) { |
|
| 74 | - return array_merge($r, $credentials_ldap); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // sinon importer les infos depuis LDAP, |
|
| 78 | - |
|
| 79 | - if ( |
|
| 80 | - $GLOBALS['meta']['ldap_statut_import'] |
|
| 81 | - and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 82 | - ) { |
|
| 83 | - // rajouter le statut indique a l'install |
|
| 84 | - $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 85 | - $desc['login'] = $login; |
|
| 86 | - $desc['source'] = 'ldap'; |
|
| 87 | - $desc['pass'] = ''; |
|
| 88 | - |
|
| 89 | - $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if ($r) { |
|
| 93 | - return array_merge( |
|
| 94 | - $credentials_ldap, |
|
| 95 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // sinon echec |
|
| 100 | - spip_log("Creation de l'auteur '$login' impossible"); |
|
| 101 | - |
|
| 102 | - return []; |
|
| 59 | + #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | + |
|
| 61 | + // Utilisateur connu ? |
|
| 62 | + // si http auth, inutile de reauthentifier: cela |
|
| 63 | + // ne marchera pas avec auth http autre que basic. |
|
| 64 | + $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 65 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | + return []; |
|
| 67 | + } |
|
| 68 | + $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 69 | + |
|
| 70 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | + $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | + |
|
| 73 | + if ($r) { |
|
| 74 | + return array_merge($r, $credentials_ldap); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // sinon importer les infos depuis LDAP, |
|
| 78 | + |
|
| 79 | + if ( |
|
| 80 | + $GLOBALS['meta']['ldap_statut_import'] |
|
| 81 | + and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 82 | + ) { |
|
| 83 | + // rajouter le statut indique a l'install |
|
| 84 | + $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 85 | + $desc['login'] = $login; |
|
| 86 | + $desc['source'] = 'ldap'; |
|
| 87 | + $desc['pass'] = ''; |
|
| 88 | + |
|
| 89 | + $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if ($r) { |
|
| 93 | + return array_merge( |
|
| 94 | + $credentials_ldap, |
|
| 95 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // sinon echec |
|
| 100 | + spip_log("Creation de l'auteur '$login' impossible"); |
|
| 101 | + |
|
| 102 | + return []; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -113,36 +113,36 @@ discard block |
||
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | 115 | function auth_ldap_connect($serveur = '') { |
| 116 | - include_spip('base/connect_sql'); |
|
| 117 | - static $connexions_ldap = []; |
|
| 118 | - if (isset($connexions_ldap[$serveur])) { |
|
| 119 | - return $connexions_ldap[$serveur]; |
|
| 120 | - } |
|
| 121 | - $connexion = spip_connect($serveur); |
|
| 122 | - if (!is_array($connexion['ldap'])) { |
|
| 123 | - if ($connexion['authentification']['ldap']) { |
|
| 124 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 125 | - unset($GLOBALS['ldap_link']); |
|
| 126 | - if (is_readable($f)) { |
|
| 127 | - include_once($f); |
|
| 128 | - }; |
|
| 129 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 130 | - $connexion['ldap'] = [ |
|
| 131 | - 'link' => $GLOBALS['ldap_link'], |
|
| 132 | - 'base' => $GLOBALS['ldap_base'] |
|
| 133 | - ]; |
|
| 134 | - } else { |
|
| 135 | - spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 136 | - } |
|
| 137 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 138 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - spip_log("connection LDAP $serveur inconnue"); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 116 | + include_spip('base/connect_sql'); |
|
| 117 | + static $connexions_ldap = []; |
|
| 118 | + if (isset($connexions_ldap[$serveur])) { |
|
| 119 | + return $connexions_ldap[$serveur]; |
|
| 120 | + } |
|
| 121 | + $connexion = spip_connect($serveur); |
|
| 122 | + if (!is_array($connexion['ldap'])) { |
|
| 123 | + if ($connexion['authentification']['ldap']) { |
|
| 124 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 125 | + unset($GLOBALS['ldap_link']); |
|
| 126 | + if (is_readable($f)) { |
|
| 127 | + include_once($f); |
|
| 128 | + }; |
|
| 129 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 130 | + $connexion['ldap'] = [ |
|
| 131 | + 'link' => $GLOBALS['ldap_link'], |
|
| 132 | + 'base' => $GLOBALS['ldap_base'] |
|
| 133 | + ]; |
|
| 134 | + } else { |
|
| 135 | + spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 136 | + } |
|
| 137 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 138 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + spip_log("connection LDAP $serveur inconnue"); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -156,52 +156,52 @@ discard block |
||
| 156 | 156 | * Le login trouvé ou chaine vide si non trouvé |
| 157 | 157 | */ |
| 158 | 158 | function auth_ldap_search($login, $pass, $checkpass = true, $serveur = '') { |
| 159 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 160 | - $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 161 | - if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 162 | - return ''; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // verifier la connexion |
|
| 166 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 167 | - return ''; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ldap_link = $ldap['link'] ?? null; |
|
| 171 | - $ldap_base = $ldap['base'] ?? null; |
|
| 172 | - $desc = !empty($ldap['attributes']) ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 173 | - |
|
| 174 | - $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 175 | - |
|
| 176 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 177 | - foreach ($logins as $att) { |
|
| 178 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 179 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 180 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 181 | - // (on veut un attribut unique) |
|
| 182 | - |
|
| 183 | - if (is_array($info) and $info['count'] == 1) { |
|
| 184 | - $dn = $info[0]['dn']; |
|
| 185 | - if (!$checkpass) { |
|
| 186 | - return $dn; |
|
| 187 | - } |
|
| 188 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 189 | - return $dn; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($checkpass and !isset($dn)) { |
|
| 195 | - // Si echec, essayer de deviner le DN |
|
| 196 | - foreach ($logins as $att) { |
|
| 197 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 198 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 199 | - return "$att=$login_search, $ldap_base"; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return ''; |
|
| 159 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 160 | + $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 161 | + if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 162 | + return ''; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // verifier la connexion |
|
| 166 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 167 | + return ''; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ldap_link = $ldap['link'] ?? null; |
|
| 171 | + $ldap_base = $ldap['base'] ?? null; |
|
| 172 | + $desc = !empty($ldap['attributes']) ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 173 | + |
|
| 174 | + $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 175 | + |
|
| 176 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 177 | + foreach ($logins as $att) { |
|
| 178 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 179 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 180 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 181 | + // (on veut un attribut unique) |
|
| 182 | + |
|
| 183 | + if (is_array($info) and $info['count'] == 1) { |
|
| 184 | + $dn = $info[0]['dn']; |
|
| 185 | + if (!$checkpass) { |
|
| 186 | + return $dn; |
|
| 187 | + } |
|
| 188 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 189 | + return $dn; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($checkpass and !isset($dn)) { |
|
| 195 | + // Si echec, essayer de deviner le DN |
|
| 196 | + foreach ($logins as $att) { |
|
| 197 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 198 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 199 | + return "$att=$login_search, $ldap_base"; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return ''; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -213,40 +213,40 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function auth_ldap_retrouver($dn, $desc = [], $serveur = '') { |
| 216 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 216 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 217 | 217 | |
| 218 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 219 | - spip_log("ldap $serveur injoignable"); |
|
| 218 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 219 | + spip_log("ldap $serveur injoignable"); |
|
| 220 | 220 | |
| 221 | - return []; |
|
| 222 | - } |
|
| 221 | + return []; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - $ldap_link = $ldap['link']; |
|
| 225 | - if (!$desc) { |
|
| 226 | - $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 227 | - unset($desc['login']); |
|
| 228 | - } |
|
| 229 | - $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 224 | + $ldap_link = $ldap['link']; |
|
| 225 | + if (!$desc) { |
|
| 226 | + $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 227 | + unset($desc['login']); |
|
| 228 | + } |
|
| 229 | + $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 230 | 230 | |
| 231 | - if (!$result) { |
|
| 232 | - return []; |
|
| 233 | - } |
|
| 231 | + if (!$result) { |
|
| 232 | + return []; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 236 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 237 | - if (!is_array($val) or !is_array($val[0])) { |
|
| 238 | - return []; |
|
| 239 | - } |
|
| 240 | - $val = $val[0]; |
|
| 235 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 236 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 237 | + if (!is_array($val) or !is_array($val[0])) { |
|
| 238 | + return []; |
|
| 239 | + } |
|
| 240 | + $val = $val[0]; |
|
| 241 | 241 | |
| 242 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 243 | - include_spip('inc/charsets'); |
|
| 242 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 243 | + include_spip('inc/charsets'); |
|
| 244 | 244 | |
| 245 | - foreach ($desc as $k => $v) { |
|
| 246 | - $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 247 | - } |
|
| 245 | + foreach ($desc as $k => $v) { |
|
| 246 | + $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - return $desc; |
|
| 249 | + return $desc; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | 260 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 261 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 261 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * Message d'erreur si login non valide, chaîne vide sinon |
| 279 | 279 | */ |
| 280 | 280 | function auth_ldap_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 281 | - include_spip('auth/spip'); |
|
| 281 | + include_spip('auth/spip'); |
|
| 282 | 282 | |
| 283 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 283 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * ``` |
| 302 | 302 | */ |
| 303 | 303 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 304 | - return true; |
|
| 304 | + return true; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -319,23 +319,23 @@ discard block |
||
| 319 | 319 | * Informe du succès ou de l'echec du changement du mot de passe |
| 320 | 320 | */ |
| 321 | 321 | function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 322 | - if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 323 | - return false; |
|
| 324 | - } |
|
| 325 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 326 | - return false; |
|
| 327 | - } |
|
| 328 | - $link = $ldap['link']; |
|
| 329 | - include_spip('inc/session'); |
|
| 330 | - $dn = session_get('ldap_dn'); |
|
| 331 | - if ('' == $dn) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | - $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 339 | - |
|
| 340 | - return $success; |
|
| 322 | + if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 325 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + $link = $ldap['link']; |
|
| 329 | + include_spip('inc/session'); |
|
| 330 | + $dn = session_get('ldap_dn'); |
|
| 331 | + if ('' == $dn) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | + $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 339 | + |
|
| 340 | + return $success; |
|
| 341 | 341 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * Pile complétée du code compilé |
| 38 | 38 | **/ |
| 39 | 39 | function balise_MENU_LANG_ECRIRE($p) { |
| 40 | - return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']); |
|
| 40 | + return calculer_balise_dynamique($p, 'MENU_LANG_ECRIRE', ['lang']); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | * - string: Si pas de multilinguisme |
| 57 | 57 | */ |
| 58 | 58 | function balise_MENU_LANG_ECRIRE_stat($args, $context_compil) { |
| 59 | - include_spip('inc/lang'); |
|
| 60 | - if (strpos($GLOBALS['meta']['langues_proposees'], ',') === false) { |
|
| 61 | - return ''; |
|
| 62 | - } |
|
| 59 | + include_spip('inc/lang'); |
|
| 60 | + if (strpos($GLOBALS['meta']['langues_proposees'], ',') === false) { |
|
| 61 | + return ''; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $args; |
|
| 64 | + return $args; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * Liste : Chemin du squelette, durée du cache, contexte |
| 78 | 78 | **/ |
| 79 | 79 | function balise_MENU_LANG_ECRIRE_dyn($opt) { |
| 80 | - return menu_lang_pour_tous('var_lang_ecrire', $opt); |
|
| 80 | + return menu_lang_pour_tous('var_lang_ecrire', $opt); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -97,30 +97,30 @@ discard block |
||
| 97 | 97 | * Liste : Chemin du squelette, durée du cache, contexte |
| 98 | 98 | **/ |
| 99 | 99 | function menu_lang_pour_tous($nom, $default) { |
| 100 | - include_spip('inc/lang'); |
|
| 100 | + include_spip('inc/lang'); |
|
| 101 | 101 | |
| 102 | - if ($GLOBALS['spip_lang'] <> $default) { |
|
| 103 | - $opt = lang_select($default); # et remplace |
|
| 104 | - if ($GLOBALS['spip_lang'] <> $default) { |
|
| 105 | - $default = ''; # annule tout choix par defaut |
|
| 106 | - if ($opt) { |
|
| 107 | - lang_select(); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - } |
|
| 102 | + if ($GLOBALS['spip_lang'] <> $default) { |
|
| 103 | + $opt = lang_select($default); # et remplace |
|
| 104 | + if ($GLOBALS['spip_lang'] <> $default) { |
|
| 105 | + $default = ''; # annule tout choix par defaut |
|
| 106 | + if ($opt) { |
|
| 107 | + lang_select(); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - # lien a partir de / |
|
| 113 | - $cible = parametre_url(self(), 'lang', '', '&'); |
|
| 114 | - $post = generer_url_action('converser', 'redirect=' . rawurlencode($cible), true); |
|
| 112 | + # lien a partir de / |
|
| 113 | + $cible = parametre_url(self(), 'lang', '', '&'); |
|
| 114 | + $post = generer_url_action('converser', 'redirect=' . rawurlencode($cible), true); |
|
| 115 | 115 | |
| 116 | - return [ |
|
| 117 | - 'formulaires/menu_lang', |
|
| 118 | - 3600, |
|
| 119 | - [ |
|
| 120 | - 'nom' => $nom, |
|
| 121 | - 'url' => $post, |
|
| 122 | - 'name' => $nom, |
|
| 123 | - 'default' => $default, |
|
| 124 | - ] |
|
| 125 | - ]; |
|
| 116 | + return [ |
|
| 117 | + 'formulaires/menu_lang', |
|
| 118 | + 3600, |
|
| 119 | + [ |
|
| 120 | + 'nom' => $nom, |
|
| 121 | + 'url' => $post, |
|
| 122 | + 'name' => $nom, |
|
| 123 | + 'default' => $default, |
|
| 124 | + ] |
|
| 125 | + ]; |
|
| 126 | 126 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | include_spip('inc/filtres'); |
| 28 | 28 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @return string Rien. |
| 40 | 40 | **/ |
| 41 | 41 | function filtre_image_dist($t) { |
| 42 | - return ''; |
|
| 42 | + return ''; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return string Rien. |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_audio_dist($t) { |
| 55 | - return ''; |
|
| 55 | + return ''; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @return string Rien. |
| 66 | 66 | **/ |
| 67 | 67 | function filtre_video_dist($t) { |
| 68 | - return ''; |
|
| 68 | + return ''; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @return string Rien. |
| 79 | 79 | **/ |
| 80 | 80 | function filtre_application_dist($t) { |
| 81 | - return ''; |
|
| 81 | + return ''; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return string Rien. |
| 92 | 92 | **/ |
| 93 | 93 | function filtre_message_dist($t) { |
| 94 | - return ''; |
|
| 94 | + return ''; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return string Rien. |
| 105 | 105 | **/ |
| 106 | 106 | function filtre_multipart_dist($t) { |
| 107 | - return ''; |
|
| 107 | + return ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * @return string Contenu échappé. |
| 118 | 118 | **/ |
| 119 | 119 | function filtre_text_dist($t) { |
| 120 | - static $t1 = ['&', '<', '>']; |
|
| 121 | - static $t2 = ['&', '<', '>']; |
|
| 120 | + static $t1 = ['&', '<', '>']; |
|
| 121 | + static $t2 = ['&', '<', '>']; |
|
| 122 | 122 | |
| 123 | - return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 123 | + return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -135,21 +135,21 @@ discard block |
||
| 135 | 135 | * Tableau (formaté en SPIP) |
| 136 | 136 | **/ |
| 137 | 137 | function filtre_text_csv_dist($t) { |
| 138 | - include_spip('inc/csv'); |
|
| 139 | - [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 140 | - foreach ($lignes as &$l) { |
|
| 141 | - $l = join('|', $l); |
|
| 142 | - } |
|
| 143 | - $corps = join("\n", $lignes) . "\n"; |
|
| 144 | - $corps = $caption . |
|
| 145 | - "\n|{{" . |
|
| 146 | - join('}}|{{', $entete) . |
|
| 147 | - '}}|' . |
|
| 148 | - "\n|" . |
|
| 149 | - str_replace("\n", "|\n|", $corps); |
|
| 150 | - include_spip('inc/texte'); |
|
| 151 | - |
|
| 152 | - return propre($corps); |
|
| 138 | + include_spip('inc/csv'); |
|
| 139 | + [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 140 | + foreach ($lignes as &$l) { |
|
| 141 | + $l = join('|', $l); |
|
| 142 | + } |
|
| 143 | + $corps = join("\n", $lignes) . "\n"; |
|
| 144 | + $corps = $caption . |
|
| 145 | + "\n|{{" . |
|
| 146 | + join('}}|{{', $entete) . |
|
| 147 | + '}}|' . |
|
| 148 | + "\n|" . |
|
| 149 | + str_replace("\n", "|\n|", $corps); |
|
| 150 | + include_spip('inc/texte'); |
|
| 151 | + |
|
| 152 | + return propre($corps); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -163,33 +163,33 @@ discard block |
||
| 163 | 163 | * @return string Code html sécurisé ou texte échappé |
| 164 | 164 | **/ |
| 165 | 165 | function filtre_text_html_dist($t) { |
| 166 | - if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 167 | - return appliquer_filtre($t, 'text/plain'); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - [, $h, $t] = $r; |
|
| 171 | - |
|
| 172 | - $style = ''; |
|
| 173 | - // recuperer les styles internes |
|
| 174 | - if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 175 | - $style = join("\n", $r[1]); |
|
| 176 | - } |
|
| 177 | - // ... et externes |
|
| 178 | - |
|
| 179 | - include_spip('inc/distant'); |
|
| 180 | - if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 181 | - foreach ($r[0] as $l) { |
|
| 182 | - preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 183 | - $page = recuperer_url($m[1]); |
|
| 184 | - $page = $page['page'] ?? ''; |
|
| 185 | - $style .= "\n/* $l */\n" |
|
| 186 | - . str_replace('<', '', $page); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 190 | - $t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t)); |
|
| 191 | - |
|
| 192 | - return (!$style ? '' : "\n<style>" . $style . '</style>') . $t; |
|
| 166 | + if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 167 | + return appliquer_filtre($t, 'text/plain'); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + [, $h, $t] = $r; |
|
| 171 | + |
|
| 172 | + $style = ''; |
|
| 173 | + // recuperer les styles internes |
|
| 174 | + if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 175 | + $style = join("\n", $r[1]); |
|
| 176 | + } |
|
| 177 | + // ... et externes |
|
| 178 | + |
|
| 179 | + include_spip('inc/distant'); |
|
| 180 | + if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 181 | + foreach ($r[0] as $l) { |
|
| 182 | + preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 183 | + $page = recuperer_url($m[1]); |
|
| 184 | + $page = $page['page'] ?? ''; |
|
| 185 | + $style .= "\n/* $l */\n" |
|
| 186 | + . str_replace('<', '', $page); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 190 | + $t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t)); |
|
| 191 | + |
|
| 192 | + return (!$style ? '' : "\n<style>" . $style . '</style>') . $t; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return string Code HTML des balises `<param>` |
| 203 | 203 | **/ |
| 204 | 204 | function filtre_audio_x_pn_realaudio($id) { |
| 205 | - return " |
|
| 205 | + return " |
|
| 206 | 206 | <param name='controls' value='PositionSlider' /> |
| 207 | 207 | <param name='controls' value='ImageWindow' /> |
| 208 | 208 | <param name='controls' value='PlayButton' /> |