@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -31,25 +31,25 @@ discard block |
||
| 31 | 31 | * Réparer la base de données |
| 32 | 32 | */ |
| 33 | 33 | function exec_base_repair_dist() { |
| 34 | - $action = null; |
|
| 35 | - $ok = false; |
|
| 36 | - if (!spip_connect()) { |
|
| 37 | - $message = _T('titre_probleme_technique'); |
|
| 38 | - } else { |
|
| 39 | - $version_sql = sql_version(); |
|
| 40 | - if (!$version_sql) { |
|
| 41 | - $message = _T('avis_erreur_connexion_mysql'); |
|
| 42 | - } else { |
|
| 43 | - $message = _T('texte_requetes_echouent'); |
|
| 44 | - $ok = true; |
|
| 45 | - } |
|
| 46 | - $action = _T('texte_tenter_reparation'); |
|
| 47 | - } |
|
| 48 | - if ($ok) { |
|
| 49 | - $admin = charger_fonction('admin', 'inc'); |
|
| 50 | - echo $admin('repair', $action, $message, true); |
|
| 51 | - } else { |
|
| 52 | - include_spip('inc/minipres'); |
|
| 53 | - echo minipres(_T('titre_reparation'), "<p>$message</p>"); |
|
| 54 | - } |
|
| 34 | + $action = null; |
|
| 35 | + $ok = false; |
|
| 36 | + if (!spip_connect()) { |
|
| 37 | + $message = _T('titre_probleme_technique'); |
|
| 38 | + } else { |
|
| 39 | + $version_sql = sql_version(); |
|
| 40 | + if (!$version_sql) { |
|
| 41 | + $message = _T('avis_erreur_connexion_mysql'); |
|
| 42 | + } else { |
|
| 43 | + $message = _T('texte_requetes_echouent'); |
|
| 44 | + $ok = true; |
|
| 45 | + } |
|
| 46 | + $action = _T('texte_tenter_reparation'); |
|
| 47 | + } |
|
| 48 | + if ($ok) { |
|
| 49 | + $admin = charger_fonction('admin', 'inc'); |
|
| 50 | + echo $admin('repair', $action, $message, true); |
|
| 51 | + } else { |
|
| 52 | + include_spip('inc/minipres'); |
|
| 53 | + echo minipres(_T('titre_reparation'), "<p>$message</p>"); |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -28,29 +28,29 @@ discard block |
||
| 28 | 28 | * Demander à mettre à jour la base de données |
| 29 | 29 | */ |
| 30 | 30 | function exec_demande_mise_a_jour_dist() { |
| 31 | - // on fait la verif du path avant tout, |
|
| 32 | - // et l'installation des qu'on est dans la colonne principale |
|
| 33 | - // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 34 | - // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 35 | - include_spip('inc/plugin'); |
|
| 36 | - if (actualise_plugins_actifs()) { |
|
| 37 | - include_spip('inc/headers'); |
|
| 38 | - redirige_par_entete(self()); |
|
| 39 | - } |
|
| 31 | + // on fait la verif du path avant tout, |
|
| 32 | + // et l'installation des qu'on est dans la colonne principale |
|
| 33 | + // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 34 | + // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 35 | + include_spip('inc/plugin'); |
|
| 36 | + if (actualise_plugins_actifs()) { |
|
| 37 | + include_spip('inc/headers'); |
|
| 38 | + redirige_par_entete(self()); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - include_spip('inc/presentation'); |
|
| 42 | - include_spip('inc/filtres_boites'); |
|
| 43 | - $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 44 | - echo $commencer_page('', '', '', '', true, false, false); |
|
| 41 | + include_spip('inc/presentation'); |
|
| 42 | + include_spip('inc/filtres_boites'); |
|
| 43 | + $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 44 | + echo $commencer_page('', '', '', '', true, false, false); |
|
| 45 | 45 | |
| 46 | - echo debut_grand_cadre(); |
|
| 47 | - echo boite_ouvrir(_T('info_message_technique'), 'notice'); |
|
| 48 | - echo '<p>' . _T('info_procedure_maj_version') . '</p>', |
|
| 49 | - '<p>' . _T('info_administrateur_site_01') . '</p>'; |
|
| 50 | - echo bouton_action(_T('bouton_mettre_a_jour_base'), generer_url_ecrire('upgrade', 'reinstall=non')); |
|
| 51 | - echo boite_fermer(); |
|
| 52 | - // masquer les erreurs sql sur cette page car proviennent de la base pas a jour ! |
|
| 53 | - echo '<style type="text/css">#debug-nav {display: none;}</style>'; |
|
| 54 | - echo fin_grand_cadre(); |
|
| 55 | - echo fin_page(); |
|
| 46 | + echo debut_grand_cadre(); |
|
| 47 | + echo boite_ouvrir(_T('info_message_technique'), 'notice'); |
|
| 48 | + echo '<p>' . _T('info_procedure_maj_version') . '</p>', |
|
| 49 | + '<p>' . _T('info_administrateur_site_01') . '</p>'; |
|
| 50 | + echo bouton_action(_T('bouton_mettre_a_jour_base'), generer_url_ecrire('upgrade', 'reinstall=non')); |
|
| 51 | + echo boite_fermer(); |
|
| 52 | + // masquer les erreurs sql sur cette page car proviennent de la base pas a jour ! |
|
| 53 | + echo '<style type="text/css">#debug-nav {display: none;}</style>'; |
|
| 54 | + echo fin_grand_cadre(); |
|
| 55 | + echo fin_page(); |
|
| 56 | 56 | } |
@@ -45,8 +45,8 @@ |
||
| 45 | 45 | |
| 46 | 46 | echo debut_grand_cadre(); |
| 47 | 47 | echo boite_ouvrir(_T('info_message_technique'), 'notice'); |
| 48 | - echo '<p>' . _T('info_procedure_maj_version') . '</p>', |
|
| 49 | - '<p>' . _T('info_administrateur_site_01') . '</p>'; |
|
| 48 | + echo '<p>'._T('info_procedure_maj_version').'</p>', |
|
| 49 | + '<p>'._T('info_administrateur_site_01').'</p>'; |
|
| 50 | 50 | echo bouton_action(_T('bouton_mettre_a_jour_base'), generer_url_ecrire('upgrade', 'reinstall=non')); |
| 51 | 51 | echo boite_fermer(); |
| 52 | 52 | // masquer les erreurs sql sur cette page car proviennent de la base pas a jour ! |
@@ -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 | /** |
@@ -25,25 +25,25 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | function exec_404_dist() { |
| 27 | 27 | |
| 28 | - $exec = _request('exec'); |
|
| 28 | + $exec = _request('exec'); |
|
| 29 | 29 | |
| 30 | - $titre = "exec_$exec"; |
|
| 31 | - $navigation = ''; |
|
| 32 | - $extra = ''; |
|
| 30 | + $titre = "exec_$exec"; |
|
| 31 | + $navigation = ''; |
|
| 32 | + $extra = ''; |
|
| 33 | 33 | |
| 34 | - include_spip('inc/presentation'); // alleger les inclusions avec un inc/presentation_mini |
|
| 35 | - $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 36 | - echo $commencer_page($titre); |
|
| 34 | + include_spip('inc/presentation'); // alleger les inclusions avec un inc/presentation_mini |
|
| 35 | + $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 36 | + echo $commencer_page($titre); |
|
| 37 | 37 | |
| 38 | - echo debut_gauche(); |
|
| 39 | - echo pipeline('affiche_gauche', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 38 | + echo debut_gauche(); |
|
| 39 | + echo pipeline('affiche_gauche', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 40 | 40 | |
| 41 | - echo creer_colonne_droite(); |
|
| 42 | - echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 41 | + echo creer_colonne_droite(); |
|
| 42 | + echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 43 | 43 | |
| 44 | - echo debut_droite(); |
|
| 45 | - echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>'; |
|
| 46 | - echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 44 | + echo debut_droite(); |
|
| 45 | + echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>'; |
|
| 46 | + echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
|
| 47 | 47 | |
| 48 | - echo fin_gauche(), fin_page(); |
|
| 48 | + echo fin_gauche(), fin_page(); |
|
| 49 | 49 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | echo pipeline('affiche_droite', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
| 43 | 43 | |
| 44 | 44 | echo debut_droite(); |
| 45 | - echo "<h1 class='grostitre'>" . _T('fichier_introuvable', ['fichier' => $exec]) . '</h1>'; |
|
| 45 | + echo "<h1 class='grostitre'>"._T('fichier_introuvable', ['fichier' => $exec]).'</h1>'; |
|
| 46 | 46 | echo pipeline('affiche_milieu', ['args' => ['exec' => '404', 'exec_erreur' => $exec], 'data' => '']); |
| 47 | 47 | |
| 48 | 48 | echo fin_gauche(), fin_page(); |
@@ -87,12 +87,12 @@ |
||
| 87 | 87 | } |
| 88 | 88 | // si une seule colonne, en faire le titre |
| 89 | 89 | if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
| 90 | - $caption = "\n||" . $l[1] . '|'; |
|
| 90 | + $caption = "\n||".$l[1].'|'; |
|
| 91 | 91 | [$entete, $corps] = explode("\n", $corps, 2); |
| 92 | 92 | } |
| 93 | 93 | // si premiere colonne vide, le raccourci doit quand meme produire <th... |
| 94 | 94 | if ($entete[0] == $sep) { |
| 95 | - $entete = ' ' . $entete; |
|
| 95 | + $entete = ' '.$entete; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | $lignes = explode("\n", $corps); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -32,117 +32,117 @@ discard block |
||
| 32 | 32 | **/ |
| 33 | 33 | function analyse_csv($t) { |
| 34 | 34 | |
| 35 | - // Quel est le séparateur ? |
|
| 36 | - $virg = substr_count($t, ','); |
|
| 37 | - $pvirg = substr_count($t, ';'); |
|
| 38 | - $tab = substr_count($t, "\t"); |
|
| 39 | - if ($virg > $pvirg) { |
|
| 40 | - $sep = ','; |
|
| 41 | - $hs = ','; |
|
| 42 | - } else { |
|
| 43 | - $sep = ';'; |
|
| 44 | - $hs = ';'; |
|
| 45 | - $virg = $pvirg; |
|
| 46 | - } |
|
| 47 | - // un certain nombre de tab => le séparateur est tab |
|
| 48 | - if ($tab > $virg / 10) { |
|
| 49 | - $sep = "\t"; |
|
| 50 | - $hs = "\t"; |
|
| 51 | - } |
|
| 35 | + // Quel est le séparateur ? |
|
| 36 | + $virg = substr_count($t, ','); |
|
| 37 | + $pvirg = substr_count($t, ';'); |
|
| 38 | + $tab = substr_count($t, "\t"); |
|
| 39 | + if ($virg > $pvirg) { |
|
| 40 | + $sep = ','; |
|
| 41 | + $hs = ','; |
|
| 42 | + } else { |
|
| 43 | + $sep = ';'; |
|
| 44 | + $hs = ';'; |
|
| 45 | + $virg = $pvirg; |
|
| 46 | + } |
|
| 47 | + // un certain nombre de tab => le séparateur est tab |
|
| 48 | + if ($tab > $virg / 10) { |
|
| 49 | + $sep = "\t"; |
|
| 50 | + $hs = "\t"; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // un separateur suivi de 3 guillemets attention ! |
|
| 54 | - // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 55 | - // on substitue un # et on remplacera a la fin |
|
| 56 | - $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 57 | - $t = str_replace('""', '"#', $t); |
|
| 58 | - preg_match_all('/"[^"]*"/', $t, $r); |
|
| 59 | - foreach ($r[0] as $cell) { |
|
| 60 | - $t = str_replace( |
|
| 61 | - $cell, |
|
| 62 | - str_replace( |
|
| 63 | - $sep, |
|
| 64 | - $hs, |
|
| 65 | - str_replace( |
|
| 66 | - "\n", |
|
| 67 | - '``**``', // échapper les saut de lignes, on les remettra après. |
|
| 68 | - substr((string) $cell, 1, -1) |
|
| 69 | - ) |
|
| 70 | - ), |
|
| 71 | - $t |
|
| 72 | - ); |
|
| 73 | - } |
|
| 53 | + // un separateur suivi de 3 guillemets attention ! |
|
| 54 | + // attention au ; ou , suceptible d'etre confondu avec un separateur |
|
| 55 | + // on substitue un # et on remplacera a la fin |
|
| 56 | + $t = preg_replace("/([\n$sep])\"\"\"/", '\\1""#', $t); |
|
| 57 | + $t = str_replace('""', '"#', $t); |
|
| 58 | + preg_match_all('/"[^"]*"/', $t, $r); |
|
| 59 | + foreach ($r[0] as $cell) { |
|
| 60 | + $t = str_replace( |
|
| 61 | + $cell, |
|
| 62 | + str_replace( |
|
| 63 | + $sep, |
|
| 64 | + $hs, |
|
| 65 | + str_replace( |
|
| 66 | + "\n", |
|
| 67 | + '``**``', // échapper les saut de lignes, on les remettra après. |
|
| 68 | + substr((string) $cell, 1, -1) |
|
| 69 | + ) |
|
| 70 | + ), |
|
| 71 | + $t |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $t = preg_replace( |
|
| 76 | - '/\r?\n/', |
|
| 77 | - "\n", |
|
| 78 | - preg_replace('/[\r\n]+/', "\n", $t) |
|
| 79 | - ); |
|
| 75 | + $t = preg_replace( |
|
| 76 | + '/\r?\n/', |
|
| 77 | + "\n", |
|
| 78 | + preg_replace('/[\r\n]+/', "\n", $t) |
|
| 79 | + ); |
|
| 80 | 80 | |
| 81 | - [$entete, $corps] = explode("\n", $t, 2); |
|
| 82 | - $caption = ''; |
|
| 83 | - // sauter la ligne de tete formee seulement de separateurs |
|
| 84 | - if (substr_count($entete, $sep) === strlen($entete)) { |
|
| 85 | - [$entete, $corps] = explode("\n", $corps, 2); |
|
| 86 | - } |
|
| 87 | - // si une seule colonne, en faire le titre |
|
| 88 | - if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 89 | - $caption = "\n||" . $l[1] . '|'; |
|
| 90 | - [$entete, $corps] = explode("\n", $corps, 2); |
|
| 91 | - } |
|
| 92 | - // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 93 | - if ($entete[0] == $sep) { |
|
| 94 | - $entete = ' ' . $entete; |
|
| 95 | - } |
|
| 81 | + [$entete, $corps] = explode("\n", $t, 2); |
|
| 82 | + $caption = ''; |
|
| 83 | + // sauter la ligne de tete formee seulement de separateurs |
|
| 84 | + if (substr_count($entete, $sep) === strlen($entete)) { |
|
| 85 | + [$entete, $corps] = explode("\n", $corps, 2); |
|
| 86 | + } |
|
| 87 | + // si une seule colonne, en faire le titre |
|
| 88 | + if (preg_match("/^([^$sep]+)$sep+\$/", $entete, $l)) { |
|
| 89 | + $caption = "\n||" . $l[1] . '|'; |
|
| 90 | + [$entete, $corps] = explode("\n", $corps, 2); |
|
| 91 | + } |
|
| 92 | + // si premiere colonne vide, le raccourci doit quand meme produire <th... |
|
| 93 | + if ($entete[0] == $sep) { |
|
| 94 | + $entete = ' ' . $entete; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $lignes = explode("\n", $corps); |
|
| 97 | + $lignes = explode("\n", $corps); |
|
| 98 | 98 | |
| 99 | - // retrait des lignes vides finales |
|
| 100 | - while ( |
|
| 101 | - $lignes !== [] && preg_match("/^$sep*$/", $lignes[count($lignes) - 1]) |
|
| 102 | - ) { |
|
| 103 | - unset($lignes[count($lignes) - 1]); |
|
| 104 | - } |
|
| 105 | - // calcul du nombre de colonne a chaque ligne |
|
| 106 | - $nbcols = []; |
|
| 107 | - $max = $mil = substr_count($entete, $sep); |
|
| 108 | - foreach ($lignes as $k => $v) { |
|
| 109 | - if ($max !== ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 110 | - if ($max > $nbcols[$k]) { |
|
| 111 | - $mil = $nbcols[$k]; |
|
| 112 | - } else { |
|
| 113 | - $mil = $max; |
|
| 114 | - $max = $nbcols[$k]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - // Si pas le meme nombre, cadrer au nombre max |
|
| 119 | - if ($mil !== $max) { |
|
| 120 | - foreach ($nbcols as $k => $v) { |
|
| 121 | - if ($v < $max) { |
|
| 122 | - $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - // et retirer les colonnes integralement vides |
|
| 127 | - while (true) { |
|
| 128 | - $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 129 | - foreach ($lignes as $v) { |
|
| 130 | - $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 131 | - } |
|
| 132 | - if (!$nbcols) { |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - $entete = substr($entete, 0, -1); |
|
| 136 | - foreach ($lignes as $k => $v) { |
|
| 137 | - $lignes[$k] = substr($v, 0, -1); |
|
| 138 | - } |
|
| 139 | - } |
|
| 99 | + // retrait des lignes vides finales |
|
| 100 | + while ( |
|
| 101 | + $lignes !== [] && preg_match("/^$sep*$/", $lignes[count($lignes) - 1]) |
|
| 102 | + ) { |
|
| 103 | + unset($lignes[count($lignes) - 1]); |
|
| 104 | + } |
|
| 105 | + // calcul du nombre de colonne a chaque ligne |
|
| 106 | + $nbcols = []; |
|
| 107 | + $max = $mil = substr_count($entete, $sep); |
|
| 108 | + foreach ($lignes as $k => $v) { |
|
| 109 | + if ($max !== ($nbcols[$k] = substr_count($v, $sep))) { |
|
| 110 | + if ($max > $nbcols[$k]) { |
|
| 111 | + $mil = $nbcols[$k]; |
|
| 112 | + } else { |
|
| 113 | + $mil = $max; |
|
| 114 | + $max = $nbcols[$k]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + // Si pas le meme nombre, cadrer au nombre max |
|
| 119 | + if ($mil !== $max) { |
|
| 120 | + foreach ($nbcols as $k => $v) { |
|
| 121 | + if ($v < $max) { |
|
| 122 | + $lignes[$k] .= str_repeat($sep, $max - $v); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + // et retirer les colonnes integralement vides |
|
| 127 | + while (true) { |
|
| 128 | + $nbcols = ($entete[strlen($entete) - 1] === $sep); |
|
| 129 | + foreach ($lignes as $v) { |
|
| 130 | + $nbcols &= ($v[strlen($v) - 1] === $sep); |
|
| 131 | + } |
|
| 132 | + if (!$nbcols) { |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + $entete = substr($entete, 0, -1); |
|
| 136 | + foreach ($lignes as $k => $v) { |
|
| 137 | + $lignes[$k] = substr($v, 0, -1); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - foreach ($lignes as &$l) { |
|
| 142 | - $l = str_replace('"#', '"', $l); |
|
| 143 | - $l = str_replace('``**``', "\n", $l); |
|
| 144 | - $l = explode($sep, $l); |
|
| 145 | - } |
|
| 141 | + foreach ($lignes as &$l) { |
|
| 142 | + $l = str_replace('"#', '"', $l); |
|
| 143 | + $l = str_replace('``**``', "\n", $l); |
|
| 144 | + $l = explode($sep, $l); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return [explode($sep, $entete), $lignes, $caption]; |
|
| 147 | + return [explode($sep, $entete), $lignes, $caption]; |
|
| 148 | 148 | } |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | foreach (['script', 'iframe'] as $tag) { |
| 106 | 106 | if ( |
| 107 | 107 | stripos($t, (string) "<$tag") !== false |
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | + and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | 109 | ) { |
| 110 | 110 | foreach ($r as $regs) { |
| 111 | 111 | $t = str_replace( |
| 112 | 112 | $regs[0], |
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 113 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 114 | 114 | $t |
| 115 | 115 | ); |
| 116 | 116 | } |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // echapper les tags asp/php |
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 166 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 167 | 167 | |
| 168 | 168 | // echapper le php |
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 169 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 170 | 170 | |
| 171 | 171 | // echapper le < script language=php > |
| 172 | 172 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -188,10 +188,10 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | // Reinserer les echappements des modeles |
| 190 | 190 | if (defined('_PROTEGE_JS_MODELES')) { |
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 191 | + $t = echappe_retour($t, 'javascript'._PROTEGE_JS_MODELES); |
|
| 192 | 192 | } |
| 193 | 193 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 194 | + $t = echappe_retour($t, 'php'._PROTEGE_PHP_MODELES); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 290 | 290 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 291 | 291 | |
| 292 | -define('_TYPO_BALISE', ',</?[a-z!][^<>]*[' . preg_quote(_TYPO_PROTEGER) . '][^<>]*>,imsS'); |
|
| 292 | +define('_TYPO_BALISE', ',</?[a-z!][^<>]*['.preg_quote(_TYPO_PROTEGER).'][^<>]*>,imsS'); |
|
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * Corrige la typographie |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/texte_mini'); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @return array Tablea ('','') |
| 34 | 34 | */ |
| 35 | 35 | function definir_raccourcis_alineas() { |
| 36 | - return ['', '']; |
|
| 36 | + return ['', '']; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @return string |
| 47 | 47 | */ |
| 48 | 48 | function traiter_tableau($bloc) { |
| 49 | - return $bloc; |
|
| 49 | + return $bloc; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @return string |
| 61 | 61 | */ |
| 62 | 62 | function traiter_listes($texte) { |
| 63 | - return $texte; |
|
| 63 | + return $texte; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -76,16 +76,16 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | function traiter_raccourcis($letexte) { |
| 78 | 78 | |
| 79 | - // Appeler les fonctions de pre_traitement |
|
| 80 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 79 | + // Appeler les fonctions de pre_traitement |
|
| 80 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 81 | 81 | |
| 82 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 83 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 82 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 83 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 84 | 84 | |
| 85 | - // Appeler les fonctions de post-traitement |
|
| 86 | - $letexte = pipeline('post_propre', $letexte); |
|
| 85 | + // Appeler les fonctions de post-traitement |
|
| 86 | + $letexte = pipeline('post_propre', $letexte); |
|
| 87 | 87 | |
| 88 | - return $letexte; |
|
| 88 | + return $letexte; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /************************************************************************************************************************* |
@@ -101,22 +101,22 @@ discard block |
||
| 101 | 101 | * @return string |
| 102 | 102 | */ |
| 103 | 103 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 104 | - foreach (['script', 'iframe'] as $tag) { |
|
| 105 | - if ( |
|
| 106 | - stripos($t, (string) "<$tag") !== false |
|
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | - ) { |
|
| 109 | - foreach ($r as $regs) { |
|
| 110 | - $t = str_replace( |
|
| 111 | - $regs[0], |
|
| 112 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 113 | - $t |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - return $t; |
|
| 104 | + foreach (['script', 'iframe'] as $tag) { |
|
| 105 | + if ( |
|
| 106 | + stripos($t, (string) "<$tag") !== false |
|
| 107 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | + ) { |
|
| 109 | + foreach ($r as $regs) { |
|
| 110 | + $t = str_replace( |
|
| 111 | + $regs[0], |
|
| 112 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 113 | + $t |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + return $t; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
@@ -145,55 +145,55 @@ discard block |
||
| 145 | 145 | * Code protégé |
| 146 | 146 | **/ |
| 147 | 147 | function interdire_scripts($arg, $mode_filtre = null) { |
| 148 | - // on memorise le resultat sur les arguments non triviaux |
|
| 149 | - static $dejavu = []; |
|
| 150 | - |
|
| 151 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 152 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 153 | - return $arg; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 157 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 161 | - return $dejavu[$mode_filtre][$arg]; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // echapper les tags asp/php |
|
| 165 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 166 | - |
|
| 167 | - // echapper le php |
|
| 168 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 169 | - |
|
| 170 | - // echapper le < script language=php > |
|
| 171 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 172 | - |
|
| 173 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 174 | - switch ($mode_filtre) { |
|
| 175 | - case 0: |
|
| 176 | - if (!_DIR_RESTREINT) { |
|
| 177 | - $t = echappe_js($t); |
|
| 178 | - } |
|
| 179 | - break; |
|
| 180 | - case -1: |
|
| 181 | - $t = echappe_js($t); |
|
| 182 | - break; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // pas de <base href /> svp ! |
|
| 186 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 187 | - |
|
| 188 | - // Reinserer les echappements des modeles |
|
| 189 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 190 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 191 | - } |
|
| 192 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 193 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 148 | + // on memorise le resultat sur les arguments non triviaux |
|
| 149 | + static $dejavu = []; |
|
| 150 | + |
|
| 151 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 152 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 153 | + return $arg; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 157 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 161 | + return $dejavu[$mode_filtre][$arg]; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // echapper les tags asp/php |
|
| 165 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 166 | + |
|
| 167 | + // echapper le php |
|
| 168 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 169 | + |
|
| 170 | + // echapper le < script language=php > |
|
| 171 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 172 | + |
|
| 173 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 174 | + switch ($mode_filtre) { |
|
| 175 | + case 0: |
|
| 176 | + if (!_DIR_RESTREINT) { |
|
| 177 | + $t = echappe_js($t); |
|
| 178 | + } |
|
| 179 | + break; |
|
| 180 | + case -1: |
|
| 181 | + $t = echappe_js($t); |
|
| 182 | + break; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // pas de <base href /> svp ! |
|
| 186 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 187 | + |
|
| 188 | + // Reinserer les echappements des modeles |
|
| 189 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 190 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 191 | + } |
|
| 192 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 193 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -222,66 +222,66 @@ discard block |
||
| 222 | 222 | * texte transformé |
| 223 | 223 | **/ |
| 224 | 224 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 225 | - // Plus vite ! |
|
| 226 | - if (!$letexte) { |
|
| 227 | - return $letexte; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 231 | - // prive etant historiquement ecrit sans argment $connect |
|
| 232 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 233 | - // ou il faut passer interdire_script explicitement |
|
| 234 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 235 | - // ne seront pas perturbes |
|
| 236 | - $interdire_script = false; |
|
| 237 | - if (is_null($connect)) { |
|
| 238 | - $connect = ''; |
|
| 239 | - $interdire_script = true; |
|
| 240 | - $env['espace_prive'] = test_espace_prive(); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // Echapper les codes <html> etc |
|
| 244 | - if ($echapper) { |
|
| 245 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // |
|
| 249 | - // Installer les modeles, notamment images et documents ; |
|
| 250 | - // |
|
| 251 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 252 | - // cf. inc/lien |
|
| 253 | - |
|
| 254 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 255 | - if ($letexte != $mem) { |
|
| 256 | - $echapper = true; |
|
| 257 | - } |
|
| 258 | - unset($mem); |
|
| 259 | - |
|
| 260 | - $letexte = corriger_typo($letexte); |
|
| 261 | - $letexte = echapper_faux_tags($letexte); |
|
| 262 | - |
|
| 263 | - // reintegrer les echappements |
|
| 264 | - if ($echapper) { |
|
| 265 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 269 | - if ($interdire_script) { |
|
| 270 | - $letexte = interdire_scripts($letexte); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 274 | - // https://core.spip.net/issues/3371 |
|
| 275 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 276 | - // https://core.spip.net/issues/4166 |
|
| 277 | - if ( |
|
| 278 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 279 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 280 | - ) { |
|
| 281 | - $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $letexte; |
|
| 225 | + // Plus vite ! |
|
| 226 | + if (!$letexte) { |
|
| 227 | + return $letexte; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 231 | + // prive etant historiquement ecrit sans argment $connect |
|
| 232 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 233 | + // ou il faut passer interdire_script explicitement |
|
| 234 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 235 | + // ne seront pas perturbes |
|
| 236 | + $interdire_script = false; |
|
| 237 | + if (is_null($connect)) { |
|
| 238 | + $connect = ''; |
|
| 239 | + $interdire_script = true; |
|
| 240 | + $env['espace_prive'] = test_espace_prive(); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // Echapper les codes <html> etc |
|
| 244 | + if ($echapper) { |
|
| 245 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // |
|
| 249 | + // Installer les modeles, notamment images et documents ; |
|
| 250 | + // |
|
| 251 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 252 | + // cf. inc/lien |
|
| 253 | + |
|
| 254 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 255 | + if ($letexte != $mem) { |
|
| 256 | + $echapper = true; |
|
| 257 | + } |
|
| 258 | + unset($mem); |
|
| 259 | + |
|
| 260 | + $letexte = corriger_typo($letexte); |
|
| 261 | + $letexte = echapper_faux_tags($letexte); |
|
| 262 | + |
|
| 263 | + // reintegrer les echappements |
|
| 264 | + if ($echapper) { |
|
| 265 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 269 | + if ($interdire_script) { |
|
| 270 | + $letexte = interdire_scripts($letexte); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 274 | + // https://core.spip.net/issues/3371 |
|
| 275 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 276 | + // https://core.spip.net/issues/4166 |
|
| 277 | + if ( |
|
| 278 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 279 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 280 | + ) { |
|
| 281 | + $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $letexte; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Correcteur typographique |
@@ -306,57 +306,57 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | function corriger_typo($letexte, $lang = '') { |
| 308 | 308 | |
| 309 | - // Plus vite ! |
|
| 310 | - if (!$letexte) { |
|
| 311 | - return $letexte; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 315 | - |
|
| 316 | - // Caracteres de controle "illegaux" |
|
| 317 | - $letexte = corriger_caracteres($letexte); |
|
| 318 | - |
|
| 319 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 320 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 321 | - foreach ($regs as $reg) { |
|
| 322 | - $insert = $reg[0]; |
|
| 323 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 324 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 325 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 326 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - // trouver les blocs idiomes et les traiter à part |
|
| 331 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 332 | - $ei = ($ei !== $letexte); |
|
| 333 | - |
|
| 334 | - // trouver les blocs multi et les traiter a part |
|
| 335 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 336 | - $em = ($em !== $letexte); |
|
| 337 | - |
|
| 338 | - // Charger & appliquer les fonctions de typographie |
|
| 339 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 340 | - $letexte = $typographie($letexte); |
|
| 341 | - |
|
| 342 | - // Les citations en une autre langue, s'il y a lieu |
|
| 343 | - if ($em) { |
|
| 344 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 345 | - } |
|
| 346 | - if ($ei) { |
|
| 347 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - // Retablir les caracteres proteges |
|
| 351 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 352 | - |
|
| 353 | - // pipeline |
|
| 354 | - $letexte = pipeline('post_typo', $letexte); |
|
| 355 | - |
|
| 356 | - # un message pour abs_url - on est passe en mode texte |
|
| 357 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 358 | - |
|
| 359 | - return $letexte; |
|
| 309 | + // Plus vite ! |
|
| 310 | + if (!$letexte) { |
|
| 311 | + return $letexte; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 315 | + |
|
| 316 | + // Caracteres de controle "illegaux" |
|
| 317 | + $letexte = corriger_caracteres($letexte); |
|
| 318 | + |
|
| 319 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 320 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 321 | + foreach ($regs as $reg) { |
|
| 322 | + $insert = $reg[0]; |
|
| 323 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 324 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 325 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 326 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + // trouver les blocs idiomes et les traiter à part |
|
| 331 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 332 | + $ei = ($ei !== $letexte); |
|
| 333 | + |
|
| 334 | + // trouver les blocs multi et les traiter a part |
|
| 335 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 336 | + $em = ($em !== $letexte); |
|
| 337 | + |
|
| 338 | + // Charger & appliquer les fonctions de typographie |
|
| 339 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 340 | + $letexte = $typographie($letexte); |
|
| 341 | + |
|
| 342 | + // Les citations en une autre langue, s'il y a lieu |
|
| 343 | + if ($em) { |
|
| 344 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 345 | + } |
|
| 346 | + if ($ei) { |
|
| 347 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + // Retablir les caracteres proteges |
|
| 351 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 352 | + |
|
| 353 | + // pipeline |
|
| 354 | + $letexte = pipeline('post_typo', $letexte); |
|
| 355 | + |
|
| 356 | + # un message pour abs_url - on est passe en mode texte |
|
| 357 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 358 | + |
|
| 359 | + return $letexte; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | * @return string |
| 373 | 373 | */ |
| 374 | 374 | function paragrapher($letexte, $forcer = true) { |
| 375 | - return $letexte; |
|
| 375 | + return $letexte; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | * @return string texte |
| 385 | 385 | **/ |
| 386 | 386 | function traiter_retours_chariots($letexte) { |
| 387 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 388 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 389 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 387 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 388 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 389 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 390 | 390 | |
| 391 | - return $letexte; |
|
| 391 | + return $letexte; |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | |
@@ -414,41 +414,41 @@ discard block |
||
| 414 | 414 | * texte transformé |
| 415 | 415 | **/ |
| 416 | 416 | function propre($t, $connect = null, $env = []) { |
| 417 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 418 | - // prive etant historiquement ecrits sans argment $connect |
|
| 419 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 420 | - // ou il faut passer interdire_script explicitement |
|
| 421 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 422 | - // ne seront pas perturbes |
|
| 423 | - // FIXME: Trouver une solution pour avoir un type (string) unique sur $connect. |
|
| 424 | - $interdire_script = false; |
|
| 425 | - if (is_null($connect)) { |
|
| 426 | - $connect = ''; |
|
| 427 | - $interdire_script = true; |
|
| 428 | - $env['espace_prive'] = true; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if (!$t) { |
|
| 432 | - return strval($t); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 436 | - // avant echappement des balises <html> |
|
| 437 | - // https://core.spip.net/issues/3371 |
|
| 438 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 439 | - // https://core.spip.net/issues/4166 |
|
| 440 | - if ( |
|
| 441 | - $interdire_script |
|
| 442 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 443 | - or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | - or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 445 | - ) { |
|
| 446 | - $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 447 | - } |
|
| 448 | - $t = echappe_html($t); |
|
| 449 | - $t = expanser_liens($t, $connect ?? '', $env); |
|
| 450 | - $t = traiter_raccourcis($t); |
|
| 451 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 452 | - |
|
| 453 | - return $t; |
|
| 417 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 418 | + // prive etant historiquement ecrits sans argment $connect |
|
| 419 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 420 | + // ou il faut passer interdire_script explicitement |
|
| 421 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 422 | + // ne seront pas perturbes |
|
| 423 | + // FIXME: Trouver une solution pour avoir un type (string) unique sur $connect. |
|
| 424 | + $interdire_script = false; |
|
| 425 | + if (is_null($connect)) { |
|
| 426 | + $connect = ''; |
|
| 427 | + $interdire_script = true; |
|
| 428 | + $env['espace_prive'] = true; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if (!$t) { |
|
| 432 | + return strval($t); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 436 | + // avant echappement des balises <html> |
|
| 437 | + // https://core.spip.net/issues/3371 |
|
| 438 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 439 | + // https://core.spip.net/issues/4166 |
|
| 440 | + if ( |
|
| 441 | + $interdire_script |
|
| 442 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 443 | + or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | + or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 445 | + ) { |
|
| 446 | + $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 447 | + } |
|
| 448 | + $t = echappe_html($t); |
|
| 449 | + $t = expanser_liens($t, $connect ?? '', $env); |
|
| 450 | + $t = traiter_raccourcis($t); |
|
| 451 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 452 | + |
|
| 453 | + return $t; |
|
| 454 | 454 | } |
@@ -204,8 +204,8 @@ discard block |
||
| 204 | 204 | $hsl = _couleur_hex_to_hsl($couleur); |
| 205 | 205 | $hsl = [ |
| 206 | 206 | 'h' => round($hsl['h'] * 360), |
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 207 | + 's' => round($hsl['s'] * 100).'%', |
|
| 208 | + 'l' => round($hsl['l'] * 100).'%' |
|
| 209 | 209 | ]; |
| 210 | 210 | if ($format === null) { |
| 211 | 211 | return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
@@ -384,11 +384,11 @@ discard block |
||
| 384 | 384 | $process = 'AUTO' |
| 385 | 385 | ) { |
| 386 | 386 | // PHP 7+ type hint |
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 387 | + $img = (string) $img; |
|
| 388 | + $taille_x = (int) $taille_x; |
|
| 389 | + $taille_y = (int) $taille_y; |
|
| 390 | + $force = (bool) $force; |
|
| 391 | + $process = (string) $process; |
|
| 392 | 392 | |
| 393 | 393 | if (!$img) { |
| 394 | 394 | return ''; |
@@ -465,11 +465,11 @@ discard block |
||
| 465 | 465 | $process = 'AUTO' |
| 466 | 466 | ) { |
| 467 | 467 | // PHP 7+ type hint |
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 468 | + $img = (string) $img; |
|
| 469 | + $taille = (int) $taille; |
|
| 470 | + $taille_y = (int) $taille_y; |
|
| 471 | + $force = (bool) $force; |
|
| 472 | + $process = (string) $process; |
|
| 473 | 473 | |
| 474 | 474 | // Determiner la taille x,y maxi |
| 475 | 475 | // prendre le reglage de previsu par defaut |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $background_color = 'white' |
| 513 | 513 | ) { |
| 514 | 514 | if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 515 | + return image_reduire(image_recadre($im, $width.':'.$height, '-', $position, $background_color), $width, $height); |
|
| 516 | 516 | } else { return image_passe_partout($im, $width, $height); |
| 517 | 517 | } |
| 518 | 518 | } |
@@ -533,9 +533,9 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | 535 | // PHP 7+ type hint |
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 536 | + $img = (string) $img; |
|
| 537 | + $val = (int) $val; |
|
| 538 | + $force = (bool) $force; |
|
| 539 | 539 | |
| 540 | 540 | [$hauteur, $largeur] = taille_image($img); |
| 541 | 541 | |
@@ -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 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 23 | 23 | |
@@ -30,161 +30,161 @@ discard block |
||
| 30 | 30 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 31 | 31 | */ |
| 32 | 32 | function couleur_html_to_hex($couleur) { |
| 33 | - $couleurs_html = [ |
|
| 34 | - 'aliceblue' => 'F0F8FF', |
|
| 35 | - 'antiquewhite' => 'FAEBD7', |
|
| 36 | - 'aqua' => '00FFFF', |
|
| 37 | - 'aquamarine' => '7FFFD4', |
|
| 38 | - 'azure' => 'F0FFFF', |
|
| 39 | - 'beige' => 'F5F5DC', |
|
| 40 | - 'bisque' => 'FFE4C4', |
|
| 41 | - 'black' => '000000', |
|
| 42 | - 'blanchedalmond' => 'FFEBCD', |
|
| 43 | - 'blue' => '0000FF', |
|
| 44 | - 'blueviolet' => '8A2BE2', |
|
| 45 | - 'brown' => 'A52A2A', |
|
| 46 | - 'burlywood' => 'DEB887', |
|
| 47 | - 'cadetblue' => '5F9EA0', |
|
| 48 | - 'chartreuse' => '7FFF00', |
|
| 49 | - 'chocolate' => 'D2691E', |
|
| 50 | - 'coral' => 'FF7F50', |
|
| 51 | - 'cornflowerblue' => '6495ED', |
|
| 52 | - 'cornsilk' => 'FFF8DC', |
|
| 53 | - 'crimson' => 'DC143C', |
|
| 54 | - 'cyan' => '00FFFF', |
|
| 55 | - 'darkblue' => '00008B', |
|
| 56 | - 'darkcyan' => '008B8B', |
|
| 57 | - 'darkgoldenrod' => 'B8860B', |
|
| 58 | - 'darkgray' => 'A9A9A9', |
|
| 59 | - 'darkgreen' => '006400', |
|
| 60 | - 'darkgrey' => 'A9A9A9', |
|
| 61 | - 'darkkhaki' => 'BDB76B', |
|
| 62 | - 'darkmagenta' => '8B008B', |
|
| 63 | - 'darkolivegreen' => '556B2F', |
|
| 64 | - 'darkorange' => 'FF8C00', |
|
| 65 | - 'darkorchid' => '9932CC', |
|
| 66 | - 'darkred' => '8B0000', |
|
| 67 | - 'darksalmon' => 'E9967A', |
|
| 68 | - 'darkseagreen' => '8FBC8F', |
|
| 69 | - 'darkslateblue' => '483D8B', |
|
| 70 | - 'darkslategray' => '2F4F4F', |
|
| 71 | - 'darkslategrey' => '2F4F4F', |
|
| 72 | - 'darkturquoise' => '00CED1', |
|
| 73 | - 'darkviolet' => '9400D3', |
|
| 74 | - 'deeppink' => 'FF1493', |
|
| 75 | - 'deepskyblue' => '00BFFF', |
|
| 76 | - 'dimgray' => '696969', |
|
| 77 | - 'dimgrey' => '696969', |
|
| 78 | - 'dodgerblue' => '1E90FF', |
|
| 79 | - 'firebrick' => 'B22222', |
|
| 80 | - 'floralwhite' => 'FFFAF0', |
|
| 81 | - 'forestgreen' => '228B22', |
|
| 82 | - 'fuchsia' => 'FF00FF', |
|
| 83 | - 'gainsboro' => 'DCDCDC', |
|
| 84 | - 'ghostwhite' => 'F8F8FF', |
|
| 85 | - 'gold' => 'FFD700', |
|
| 86 | - 'goldenrod' => 'DAA520', |
|
| 87 | - 'gray' => '808080', |
|
| 88 | - 'green' => '008000', |
|
| 89 | - 'greenyellow' => 'ADFF2F', |
|
| 90 | - 'grey' => '808080', |
|
| 91 | - 'honeydew' => 'F0FFF0', |
|
| 92 | - 'hotpink' => 'FF69B4', |
|
| 93 | - 'indianred' => 'CD5C5C', |
|
| 94 | - 'indigo' => '4B0082', |
|
| 95 | - 'ivory' => 'FFFFF0', |
|
| 96 | - 'khaki' => 'F0E68C', |
|
| 97 | - 'lavender' => 'E6E6FA', |
|
| 98 | - 'lavenderblush' => 'FFF0F5', |
|
| 99 | - 'lawngreen' => '7CFC00', |
|
| 100 | - 'lemonchiffon' => 'FFFACD', |
|
| 101 | - 'lightblue' => 'ADD8E6', |
|
| 102 | - 'lightcoral' => 'F08080', |
|
| 103 | - 'lightcyan' => 'E0FFFF', |
|
| 104 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 105 | - 'lightgray' => 'D3D3D3', |
|
| 106 | - 'lightgreen' => '90EE90', |
|
| 107 | - 'lightgrey' => 'D3D3D3', |
|
| 108 | - 'lightpink' => 'FFB6C1', |
|
| 109 | - 'lightsalmon' => 'FFA07A', |
|
| 110 | - 'lightseagreen' => '20B2AA', |
|
| 111 | - 'lightskyblue' => '87CEFA', |
|
| 112 | - 'lightslategray' => '778899', |
|
| 113 | - 'lightslategrey' => '778899', |
|
| 114 | - 'lightsteelblue' => 'B0C4DE', |
|
| 115 | - 'lightyellow' => 'FFFFE0', |
|
| 116 | - 'lime' => '00FF00', |
|
| 117 | - 'limegreen' => '32CD32', |
|
| 118 | - 'linen' => 'FAF0E6', |
|
| 119 | - 'magenta' => 'FF00FF', |
|
| 120 | - 'maroon' => '800000', |
|
| 121 | - 'mediumaquamarine' => '66CDAA', |
|
| 122 | - 'mediumblue' => '0000CD', |
|
| 123 | - 'mediumorchid' => 'BA55D3', |
|
| 124 | - 'mediumpurple' => '9370DB', |
|
| 125 | - 'mediumseagreen' => '3CB371', |
|
| 126 | - 'mediumslateblue' => '7B68EE', |
|
| 127 | - 'mediumspringgreen' => '00FA9A', |
|
| 128 | - 'mediumturquoise' => '48D1CC', |
|
| 129 | - 'mediumvioletred' => 'C71585', |
|
| 130 | - 'midnightblue' => '191970', |
|
| 131 | - 'mintcream' => 'F5FFFA', |
|
| 132 | - 'mistyrose' => 'FFE4E1', |
|
| 133 | - 'moccasin' => 'FFE4B5', |
|
| 134 | - 'navajowhite' => 'FFDEAD', |
|
| 135 | - 'navy' => '000080', |
|
| 136 | - 'oldlace' => 'FDF5E6', |
|
| 137 | - 'olive' => '808000', |
|
| 138 | - 'olivedrab' => '6B8E23', |
|
| 139 | - 'orange' => 'FFA500', |
|
| 140 | - 'orangered' => 'FF4500', |
|
| 141 | - 'orchid' => 'DA70D6', |
|
| 142 | - 'palegoldenrod' => 'EEE8AA', |
|
| 143 | - 'palegreen' => '98FB98', |
|
| 144 | - 'paleturquoise' => 'AFEEEE', |
|
| 145 | - 'palevioletred' => 'DB7093', |
|
| 146 | - 'papayawhip' => 'FFEFD5', |
|
| 147 | - 'peachpuff' => 'FFDAB9', |
|
| 148 | - 'peru' => 'CD853F', |
|
| 149 | - 'pink' => 'FFC0CB', |
|
| 150 | - 'plum' => 'DDA0DD', |
|
| 151 | - 'powderblue' => 'B0E0E6', |
|
| 152 | - 'purple' => '800080', |
|
| 153 | - 'rebeccapurple' => '663399', |
|
| 154 | - 'red' => 'FF0000', |
|
| 155 | - 'rosybrown' => 'BC8F8F', |
|
| 156 | - 'royalblue' => '4169E1', |
|
| 157 | - 'saddlebrown' => '8B4513', |
|
| 158 | - 'salmon' => 'FA8072', |
|
| 159 | - 'sandybrown' => 'F4A460', |
|
| 160 | - 'seagreen' => '2E8B57', |
|
| 161 | - 'seashell' => 'FFF5EE', |
|
| 162 | - 'sienna' => 'A0522D', |
|
| 163 | - 'silver' => 'C0C0C0', |
|
| 164 | - 'skyblue' => '87CEEB', |
|
| 165 | - 'slateblue' => '6A5ACD', |
|
| 166 | - 'slategray' => '708090', |
|
| 167 | - 'slategrey' => '708090', |
|
| 168 | - 'snow' => 'FFFAFA', |
|
| 169 | - 'springgreen' => '00FF7F', |
|
| 170 | - 'steelblue' => '4682B4', |
|
| 171 | - 'tan' => 'D2B48C', |
|
| 172 | - 'teal' => '008080', |
|
| 173 | - 'thistle' => 'D8BFD8', |
|
| 174 | - 'tomato' => 'FF6347', |
|
| 175 | - 'turquoise' => '40E0D0', |
|
| 176 | - 'violet' => 'EE82EE', |
|
| 177 | - 'wheat' => 'F5DEB3', |
|
| 178 | - 'white' => 'FFFFFF', |
|
| 179 | - 'whitesmoke' => 'F5F5F5', |
|
| 180 | - 'yellow' => 'FFFF00', |
|
| 181 | - 'yellowgreen' => '9ACD32', |
|
| 182 | - ]; |
|
| 183 | - if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 184 | - return $couleurs_html[$lc]; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $couleur; |
|
| 33 | + $couleurs_html = [ |
|
| 34 | + 'aliceblue' => 'F0F8FF', |
|
| 35 | + 'antiquewhite' => 'FAEBD7', |
|
| 36 | + 'aqua' => '00FFFF', |
|
| 37 | + 'aquamarine' => '7FFFD4', |
|
| 38 | + 'azure' => 'F0FFFF', |
|
| 39 | + 'beige' => 'F5F5DC', |
|
| 40 | + 'bisque' => 'FFE4C4', |
|
| 41 | + 'black' => '000000', |
|
| 42 | + 'blanchedalmond' => 'FFEBCD', |
|
| 43 | + 'blue' => '0000FF', |
|
| 44 | + 'blueviolet' => '8A2BE2', |
|
| 45 | + 'brown' => 'A52A2A', |
|
| 46 | + 'burlywood' => 'DEB887', |
|
| 47 | + 'cadetblue' => '5F9EA0', |
|
| 48 | + 'chartreuse' => '7FFF00', |
|
| 49 | + 'chocolate' => 'D2691E', |
|
| 50 | + 'coral' => 'FF7F50', |
|
| 51 | + 'cornflowerblue' => '6495ED', |
|
| 52 | + 'cornsilk' => 'FFF8DC', |
|
| 53 | + 'crimson' => 'DC143C', |
|
| 54 | + 'cyan' => '00FFFF', |
|
| 55 | + 'darkblue' => '00008B', |
|
| 56 | + 'darkcyan' => '008B8B', |
|
| 57 | + 'darkgoldenrod' => 'B8860B', |
|
| 58 | + 'darkgray' => 'A9A9A9', |
|
| 59 | + 'darkgreen' => '006400', |
|
| 60 | + 'darkgrey' => 'A9A9A9', |
|
| 61 | + 'darkkhaki' => 'BDB76B', |
|
| 62 | + 'darkmagenta' => '8B008B', |
|
| 63 | + 'darkolivegreen' => '556B2F', |
|
| 64 | + 'darkorange' => 'FF8C00', |
|
| 65 | + 'darkorchid' => '9932CC', |
|
| 66 | + 'darkred' => '8B0000', |
|
| 67 | + 'darksalmon' => 'E9967A', |
|
| 68 | + 'darkseagreen' => '8FBC8F', |
|
| 69 | + 'darkslateblue' => '483D8B', |
|
| 70 | + 'darkslategray' => '2F4F4F', |
|
| 71 | + 'darkslategrey' => '2F4F4F', |
|
| 72 | + 'darkturquoise' => '00CED1', |
|
| 73 | + 'darkviolet' => '9400D3', |
|
| 74 | + 'deeppink' => 'FF1493', |
|
| 75 | + 'deepskyblue' => '00BFFF', |
|
| 76 | + 'dimgray' => '696969', |
|
| 77 | + 'dimgrey' => '696969', |
|
| 78 | + 'dodgerblue' => '1E90FF', |
|
| 79 | + 'firebrick' => 'B22222', |
|
| 80 | + 'floralwhite' => 'FFFAF0', |
|
| 81 | + 'forestgreen' => '228B22', |
|
| 82 | + 'fuchsia' => 'FF00FF', |
|
| 83 | + 'gainsboro' => 'DCDCDC', |
|
| 84 | + 'ghostwhite' => 'F8F8FF', |
|
| 85 | + 'gold' => 'FFD700', |
|
| 86 | + 'goldenrod' => 'DAA520', |
|
| 87 | + 'gray' => '808080', |
|
| 88 | + 'green' => '008000', |
|
| 89 | + 'greenyellow' => 'ADFF2F', |
|
| 90 | + 'grey' => '808080', |
|
| 91 | + 'honeydew' => 'F0FFF0', |
|
| 92 | + 'hotpink' => 'FF69B4', |
|
| 93 | + 'indianred' => 'CD5C5C', |
|
| 94 | + 'indigo' => '4B0082', |
|
| 95 | + 'ivory' => 'FFFFF0', |
|
| 96 | + 'khaki' => 'F0E68C', |
|
| 97 | + 'lavender' => 'E6E6FA', |
|
| 98 | + 'lavenderblush' => 'FFF0F5', |
|
| 99 | + 'lawngreen' => '7CFC00', |
|
| 100 | + 'lemonchiffon' => 'FFFACD', |
|
| 101 | + 'lightblue' => 'ADD8E6', |
|
| 102 | + 'lightcoral' => 'F08080', |
|
| 103 | + 'lightcyan' => 'E0FFFF', |
|
| 104 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 105 | + 'lightgray' => 'D3D3D3', |
|
| 106 | + 'lightgreen' => '90EE90', |
|
| 107 | + 'lightgrey' => 'D3D3D3', |
|
| 108 | + 'lightpink' => 'FFB6C1', |
|
| 109 | + 'lightsalmon' => 'FFA07A', |
|
| 110 | + 'lightseagreen' => '20B2AA', |
|
| 111 | + 'lightskyblue' => '87CEFA', |
|
| 112 | + 'lightslategray' => '778899', |
|
| 113 | + 'lightslategrey' => '778899', |
|
| 114 | + 'lightsteelblue' => 'B0C4DE', |
|
| 115 | + 'lightyellow' => 'FFFFE0', |
|
| 116 | + 'lime' => '00FF00', |
|
| 117 | + 'limegreen' => '32CD32', |
|
| 118 | + 'linen' => 'FAF0E6', |
|
| 119 | + 'magenta' => 'FF00FF', |
|
| 120 | + 'maroon' => '800000', |
|
| 121 | + 'mediumaquamarine' => '66CDAA', |
|
| 122 | + 'mediumblue' => '0000CD', |
|
| 123 | + 'mediumorchid' => 'BA55D3', |
|
| 124 | + 'mediumpurple' => '9370DB', |
|
| 125 | + 'mediumseagreen' => '3CB371', |
|
| 126 | + 'mediumslateblue' => '7B68EE', |
|
| 127 | + 'mediumspringgreen' => '00FA9A', |
|
| 128 | + 'mediumturquoise' => '48D1CC', |
|
| 129 | + 'mediumvioletred' => 'C71585', |
|
| 130 | + 'midnightblue' => '191970', |
|
| 131 | + 'mintcream' => 'F5FFFA', |
|
| 132 | + 'mistyrose' => 'FFE4E1', |
|
| 133 | + 'moccasin' => 'FFE4B5', |
|
| 134 | + 'navajowhite' => 'FFDEAD', |
|
| 135 | + 'navy' => '000080', |
|
| 136 | + 'oldlace' => 'FDF5E6', |
|
| 137 | + 'olive' => '808000', |
|
| 138 | + 'olivedrab' => '6B8E23', |
|
| 139 | + 'orange' => 'FFA500', |
|
| 140 | + 'orangered' => 'FF4500', |
|
| 141 | + 'orchid' => 'DA70D6', |
|
| 142 | + 'palegoldenrod' => 'EEE8AA', |
|
| 143 | + 'palegreen' => '98FB98', |
|
| 144 | + 'paleturquoise' => 'AFEEEE', |
|
| 145 | + 'palevioletred' => 'DB7093', |
|
| 146 | + 'papayawhip' => 'FFEFD5', |
|
| 147 | + 'peachpuff' => 'FFDAB9', |
|
| 148 | + 'peru' => 'CD853F', |
|
| 149 | + 'pink' => 'FFC0CB', |
|
| 150 | + 'plum' => 'DDA0DD', |
|
| 151 | + 'powderblue' => 'B0E0E6', |
|
| 152 | + 'purple' => '800080', |
|
| 153 | + 'rebeccapurple' => '663399', |
|
| 154 | + 'red' => 'FF0000', |
|
| 155 | + 'rosybrown' => 'BC8F8F', |
|
| 156 | + 'royalblue' => '4169E1', |
|
| 157 | + 'saddlebrown' => '8B4513', |
|
| 158 | + 'salmon' => 'FA8072', |
|
| 159 | + 'sandybrown' => 'F4A460', |
|
| 160 | + 'seagreen' => '2E8B57', |
|
| 161 | + 'seashell' => 'FFF5EE', |
|
| 162 | + 'sienna' => 'A0522D', |
|
| 163 | + 'silver' => 'C0C0C0', |
|
| 164 | + 'skyblue' => '87CEEB', |
|
| 165 | + 'slateblue' => '6A5ACD', |
|
| 166 | + 'slategray' => '708090', |
|
| 167 | + 'slategrey' => '708090', |
|
| 168 | + 'snow' => 'FFFAFA', |
|
| 169 | + 'springgreen' => '00FF7F', |
|
| 170 | + 'steelblue' => '4682B4', |
|
| 171 | + 'tan' => 'D2B48C', |
|
| 172 | + 'teal' => '008080', |
|
| 173 | + 'thistle' => 'D8BFD8', |
|
| 174 | + 'tomato' => 'FF6347', |
|
| 175 | + 'turquoise' => '40E0D0', |
|
| 176 | + 'violet' => 'EE82EE', |
|
| 177 | + 'wheat' => 'F5DEB3', |
|
| 178 | + 'white' => 'FFFFFF', |
|
| 179 | + 'whitesmoke' => 'F5F5F5', |
|
| 180 | + 'yellow' => 'FFFF00', |
|
| 181 | + 'yellowgreen' => '9ACD32', |
|
| 182 | + ]; |
|
| 183 | + if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 184 | + return $couleurs_html[$lc]; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $couleur; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -200,16 +200,16 @@ discard block |
||
| 200 | 200 | * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée |
| 201 | 201 | */ |
| 202 | 202 | function couleur_hex_to_hsl($couleur, $format = null) { |
| 203 | - $hsl = _couleur_hex_to_hsl($couleur); |
|
| 204 | - $hsl = [ |
|
| 205 | - 'h' => round($hsl['h'] * 360), |
|
| 206 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 207 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 208 | - ]; |
|
| 209 | - if ($format === null) { |
|
| 210 | - return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 211 | - } |
|
| 212 | - return str_replace(array_keys($hsl), $hsl, $format); |
|
| 203 | + $hsl = _couleur_hex_to_hsl($couleur); |
|
| 204 | + $hsl = [ |
|
| 205 | + 'h' => round($hsl['h'] * 360), |
|
| 206 | + 's' => round($hsl['s'] * 100) . '%', |
|
| 207 | + 'l' => round($hsl['l'] * 100) . '%' |
|
| 208 | + ]; |
|
| 209 | + if ($format === null) { |
|
| 210 | + return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 211 | + } |
|
| 212 | + return str_replace(array_keys($hsl), $hsl, $format); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -226,16 +226,16 @@ discard block |
||
| 226 | 226 | * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée |
| 227 | 227 | */ |
| 228 | 228 | function couleur_hex_to_rgb($couleur, $format = null) { |
| 229 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 230 | - $rgb = [ |
|
| 231 | - 'r' => $rgb['red'], |
|
| 232 | - 'g' => $rgb['green'], |
|
| 233 | - 'b' => $rgb['blue'], |
|
| 234 | - ]; |
|
| 235 | - if ($format === null) { |
|
| 236 | - return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 237 | - } |
|
| 238 | - return str_replace(array_keys($rgb), $rgb, $format); |
|
| 229 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 230 | + $rgb = [ |
|
| 231 | + 'r' => $rgb['red'], |
|
| 232 | + 'g' => $rgb['green'], |
|
| 233 | + 'b' => $rgb['blue'], |
|
| 234 | + ]; |
|
| 235 | + if ($format === null) { |
|
| 236 | + return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 237 | + } |
|
| 238 | + return str_replace(array_keys($rgb), $rgb, $format); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -251,13 +251,13 @@ discard block |
||
| 251 | 251 | * Code hexadécimal de la couleur plus foncée |
| 252 | 252 | */ |
| 253 | 253 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 254 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 254 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 255 | 255 | |
| 256 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 257 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 258 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 256 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 257 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 258 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 259 | 259 | |
| 260 | - return _couleur_dec_to_hex($red, $green, $blue); |
|
| 260 | + return _couleur_dec_to_hex($red, $green, $blue); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | * Code hexadécimal de la couleur éclaircie |
| 274 | 274 | */ |
| 275 | 275 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 276 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 276 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 277 | 277 | |
| 278 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 279 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 280 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 278 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 279 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 280 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 281 | 281 | |
| 282 | - return _couleur_dec_to_hex($red, $green, $blue); |
|
| 282 | + return _couleur_dec_to_hex($red, $green, $blue); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -302,28 +302,28 @@ discard block |
||
| 302 | 302 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 303 | 303 | */ |
| 304 | 304 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 305 | - if (!$img) { |
|
| 306 | - return $img; |
|
| 307 | - } |
|
| 308 | - [$h, $l] = taille_image($img); |
|
| 309 | - $select = true; |
|
| 310 | - if ($l < $width_min || $l > $width_max || $h < $height_min || $h > $height_max) { |
|
| 311 | - $select = false; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $class = extraire_attribut($img, 'class'); |
|
| 315 | - $p = strpos((string) $class, 'filtre_inactif'); |
|
| 316 | - if ($select == false && $p === false) { |
|
| 317 | - $class .= ' filtre_inactif'; |
|
| 318 | - $img = inserer_attribut($img, 'class', $class); |
|
| 319 | - } |
|
| 320 | - if ($select == true && $p !== false) { |
|
| 321 | - // no_image_filtrer : historique, a virer |
|
| 322 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', (string) $class); |
|
| 323 | - $img = inserer_attribut($img, 'class', $class); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return $img; |
|
| 305 | + if (!$img) { |
|
| 306 | + return $img; |
|
| 307 | + } |
|
| 308 | + [$h, $l] = taille_image($img); |
|
| 309 | + $select = true; |
|
| 310 | + if ($l < $width_min || $l > $width_max || $h < $height_min || $h > $height_max) { |
|
| 311 | + $select = false; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $class = extraire_attribut($img, 'class'); |
|
| 315 | + $p = strpos((string) $class, 'filtre_inactif'); |
|
| 316 | + if ($select == false && $p === false) { |
|
| 317 | + $class .= ' filtre_inactif'; |
|
| 318 | + $img = inserer_attribut($img, 'class', $class); |
|
| 319 | + } |
|
| 320 | + if ($select == true && $p !== false) { |
|
| 321 | + // no_image_filtrer : historique, a virer |
|
| 322 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', (string) $class); |
|
| 323 | + $img = inserer_attribut($img, 'class', $class); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return $img; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -371,45 +371,45 @@ discard block |
||
| 371 | 371 | * Code HTML de l'image ou du texte. |
| 372 | 372 | **/ |
| 373 | 373 | function image_passe_partout( |
| 374 | - $img, |
|
| 375 | - $taille_x = -1, |
|
| 376 | - $taille_y = -1, |
|
| 377 | - $force = false, |
|
| 378 | - $cherche_image = false, |
|
| 379 | - $process = 'AUTO' |
|
| 374 | + $img, |
|
| 375 | + $taille_x = -1, |
|
| 376 | + $taille_y = -1, |
|
| 377 | + $force = false, |
|
| 378 | + $cherche_image = false, |
|
| 379 | + $process = 'AUTO' |
|
| 380 | 380 | ) { |
| 381 | - // PHP 7+ type hint |
|
| 382 | - $img = (string)$img; |
|
| 383 | - $taille_x = (int)$taille_x; |
|
| 384 | - $taille_y = (int)$taille_y; |
|
| 385 | - $force = (bool)$force; |
|
| 386 | - $process = (string)$process; |
|
| 387 | - |
|
| 388 | - if (!$img) { |
|
| 389 | - return ''; |
|
| 390 | - } |
|
| 391 | - [$hauteur, $largeur] = taille_image($img); |
|
| 392 | - if ($taille_x === -1) { |
|
| 393 | - $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 394 | - } |
|
| 395 | - if ($taille_y === -1) { |
|
| 396 | - $taille_y = $taille_x; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if ($taille_x === 0 && $taille_y > 0) { |
|
| 400 | - $taille_x = 1; |
|
| 401 | - } # {0,300} -> c'est 300 qui compte |
|
| 402 | - elseif ($taille_x > 0 && $taille_y === 0) { |
|
| 403 | - $taille_y = 1; |
|
| 404 | - } # {300,0} -> c'est 300 qui compte |
|
| 405 | - elseif ($taille_x == 0 && $taille_y === 0) { |
|
| 406 | - return ''; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 410 | - $fonction = ['image_passe_partout', func_get_args()]; |
|
| 411 | - |
|
| 412 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 381 | + // PHP 7+ type hint |
|
| 382 | + $img = (string)$img; |
|
| 383 | + $taille_x = (int)$taille_x; |
|
| 384 | + $taille_y = (int)$taille_y; |
|
| 385 | + $force = (bool)$force; |
|
| 386 | + $process = (string)$process; |
|
| 387 | + |
|
| 388 | + if (!$img) { |
|
| 389 | + return ''; |
|
| 390 | + } |
|
| 391 | + [$hauteur, $largeur] = taille_image($img); |
|
| 392 | + if ($taille_x === -1) { |
|
| 393 | + $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 394 | + } |
|
| 395 | + if ($taille_y === -1) { |
|
| 396 | + $taille_y = $taille_x; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if ($taille_x === 0 && $taille_y > 0) { |
|
| 400 | + $taille_x = 1; |
|
| 401 | + } # {0,300} -> c'est 300 qui compte |
|
| 402 | + elseif ($taille_x > 0 && $taille_y === 0) { |
|
| 403 | + $taille_y = 1; |
|
| 404 | + } # {300,0} -> c'est 300 qui compte |
|
| 405 | + elseif ($taille_x == 0 && $taille_y === 0) { |
|
| 406 | + return ''; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 410 | + $fonction = ['image_passe_partout', func_get_args()]; |
|
| 411 | + |
|
| 412 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -452,44 +452,44 @@ discard block |
||
| 452 | 452 | * Code HTML de l'image ou du texte. |
| 453 | 453 | **/ |
| 454 | 454 | function image_reduire( |
| 455 | - $img, |
|
| 456 | - $taille = -1, |
|
| 457 | - $taille_y = -1, |
|
| 458 | - $force = false, |
|
| 459 | - $cherche_image = false, |
|
| 460 | - $process = 'AUTO' |
|
| 455 | + $img, |
|
| 456 | + $taille = -1, |
|
| 457 | + $taille_y = -1, |
|
| 458 | + $force = false, |
|
| 459 | + $cherche_image = false, |
|
| 460 | + $process = 'AUTO' |
|
| 461 | 461 | ) { |
| 462 | - // PHP 7+ type hint |
|
| 463 | - $img = (string)$img; |
|
| 464 | - $taille = (int)$taille; |
|
| 465 | - $taille_y = (int)$taille_y; |
|
| 466 | - $force = (bool)$force; |
|
| 467 | - $process = (string)$process; |
|
| 468 | - |
|
| 469 | - // Determiner la taille x,y maxi |
|
| 470 | - // prendre le reglage de previsu par defaut |
|
| 471 | - if ($taille === -1) { |
|
| 472 | - $taille = (isset($GLOBALS['meta']['taille_preview']) && (int) $GLOBALS['meta']['taille_preview']) |
|
| 473 | - ? (int) $GLOBALS['meta']['taille_preview'] |
|
| 474 | - : 150; |
|
| 475 | - } |
|
| 476 | - if ($taille_y === -1) { |
|
| 477 | - $taille_y = $taille; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - if ($taille === 0 && $taille_y > 0) { |
|
| 481 | - $taille = 10000; |
|
| 482 | - } # {0,300} -> c'est 300 qui compte |
|
| 483 | - elseif ($taille > 0 && $taille_y === 0) { |
|
| 484 | - $taille_y = 10000; |
|
| 485 | - } # {300,0} -> c'est 300 qui compte |
|
| 486 | - elseif ($taille == 0 && $taille_y === 0) { |
|
| 487 | - return ''; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $fonction = ['image_reduire', func_get_args()]; |
|
| 491 | - |
|
| 492 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 462 | + // PHP 7+ type hint |
|
| 463 | + $img = (string)$img; |
|
| 464 | + $taille = (int)$taille; |
|
| 465 | + $taille_y = (int)$taille_y; |
|
| 466 | + $force = (bool)$force; |
|
| 467 | + $process = (string)$process; |
|
| 468 | + |
|
| 469 | + // Determiner la taille x,y maxi |
|
| 470 | + // prendre le reglage de previsu par defaut |
|
| 471 | + if ($taille === -1) { |
|
| 472 | + $taille = (isset($GLOBALS['meta']['taille_preview']) && (int) $GLOBALS['meta']['taille_preview']) |
|
| 473 | + ? (int) $GLOBALS['meta']['taille_preview'] |
|
| 474 | + : 150; |
|
| 475 | + } |
|
| 476 | + if ($taille_y === -1) { |
|
| 477 | + $taille_y = $taille; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + if ($taille === 0 && $taille_y > 0) { |
|
| 481 | + $taille = 10000; |
|
| 482 | + } # {0,300} -> c'est 300 qui compte |
|
| 483 | + elseif ($taille > 0 && $taille_y === 0) { |
|
| 484 | + $taille_y = 10000; |
|
| 485 | + } # {300,0} -> c'est 300 qui compte |
|
| 486 | + elseif ($taille == 0 && $taille_y === 0) { |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $fonction = ['image_reduire', func_get_args()]; |
|
| 491 | + |
|
| 492 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -500,16 +500,16 @@ discard block |
||
| 500 | 500 | * |
| 501 | 501 | **/ |
| 502 | 502 | function image_recadre_avec_fallback( |
| 503 | - $im, |
|
| 504 | - $width, |
|
| 505 | - $height = '-', |
|
| 506 | - $position = 'focus', |
|
| 507 | - $background_color = 'white' |
|
| 503 | + $im, |
|
| 504 | + $width, |
|
| 505 | + $height = '-', |
|
| 506 | + $position = 'focus', |
|
| 507 | + $background_color = 'white' |
|
| 508 | 508 | ) { |
| 509 | - if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 510 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 511 | - } else { return image_passe_partout($im, $width, $height); |
|
| 512 | - } |
|
| 509 | + if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 510 | + return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 511 | + } else { return image_passe_partout($im, $width, $height); |
|
| 512 | + } |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -527,23 +527,23 @@ discard block |
||
| 527 | 527 | * Code HTML de l'image ou du texte. |
| 528 | 528 | **/ |
| 529 | 529 | function image_reduire_par($img, $val = 1, $force = false) { |
| 530 | - // PHP 7+ type hint |
|
| 531 | - $img = (string)$img; |
|
| 532 | - $val = (int)$val; |
|
| 533 | - $force = (bool)$force; |
|
| 530 | + // PHP 7+ type hint |
|
| 531 | + $img = (string)$img; |
|
| 532 | + $val = (int)$val; |
|
| 533 | + $force = (bool)$force; |
|
| 534 | 534 | |
| 535 | - [$hauteur, $largeur] = taille_image($img); |
|
| 535 | + [$hauteur, $largeur] = taille_image($img); |
|
| 536 | 536 | |
| 537 | - $l = round($largeur / $val); |
|
| 538 | - $h = round($hauteur / $val); |
|
| 537 | + $l = round($largeur / $val); |
|
| 538 | + $h = round($hauteur / $val); |
|
| 539 | 539 | |
| 540 | - if ($l > $h) { |
|
| 541 | - $h = 0; |
|
| 542 | - } else { |
|
| 543 | - $l = 0; |
|
| 544 | - } |
|
| 540 | + if ($l > $h) { |
|
| 541 | + $h = 0; |
|
| 542 | + } else { |
|
| 543 | + $l = 0; |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | - return image_reduire($img, $l, $h, $force); |
|
| 546 | + return image_reduire($img, $l, $h, $force); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -566,10 +566,10 @@ discard block |
||
| 566 | 566 | * Couleur en écriture hexadécimale. |
| 567 | 567 | **/ |
| 568 | 568 | function filtre_couleur_saturation_dist($couleur, $val, $strict = false) { |
| 569 | - if (function_exists('couleur_saturation')) { |
|
| 570 | - return couleur_saturation($couleur, $val, $strict); |
|
| 571 | - } |
|
| 572 | - return $couleur; |
|
| 569 | + if (function_exists('couleur_saturation')) { |
|
| 570 | + return couleur_saturation($couleur, $val, $strict); |
|
| 571 | + } |
|
| 572 | + return $couleur; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -590,8 +590,8 @@ discard block |
||
| 590 | 590 | * Couleur en écriture hexadécimale. |
| 591 | 591 | **/ |
| 592 | 592 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 593 | - if (function_exists('couleur_luminance')) { |
|
| 594 | - return couleur_luminance($couleur, $val); |
|
| 595 | - } |
|
| 596 | - return $couleur; |
|
| 593 | + if (function_exists('couleur_luminance')) { |
|
| 594 | + return couleur_luminance($couleur, $val); |
|
| 595 | + } |
|
| 596 | + return $couleur; |
|
| 597 | 597 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -40,15 +40,15 @@ discard block |
||
| 40 | 40 | * @return bool|null|void |
| 41 | 41 | */ |
| 42 | 42 | function inc_session_dist($auteur = false) { |
| 43 | - if (is_numeric($auteur)) { |
|
| 44 | - return supprimer_sessions($auteur, $auteur > 0); |
|
| 45 | - } else { |
|
| 46 | - if (is_array($auteur)) { |
|
| 47 | - return ajouter_session($auteur); |
|
| 48 | - } else { |
|
| 49 | - return verifier_session($auteur); |
|
| 50 | - } |
|
| 51 | - } |
|
| 43 | + if (is_numeric($auteur)) { |
|
| 44 | + return supprimer_sessions($auteur, $auteur > 0); |
|
| 45 | + } else { |
|
| 46 | + if (is_array($auteur)) { |
|
| 47 | + return ajouter_session($auteur); |
|
| 48 | + } else { |
|
| 49 | + return verifier_session($auteur); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -77,36 +77,36 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function supprimer_sessions($id_auteur, $toutes = true, $actives = true) { |
| 79 | 79 | |
| 80 | - $nb_files = 0; |
|
| 81 | - $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000); |
|
| 82 | - spip_log("supprimer sessions auteur $id_auteur", 'session'); |
|
| 83 | - if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 84 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 85 | - $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | - $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | - $t = time() - (4 * _RENOUVELLE_ALEA); |
|
| 88 | - while (($f = readdir($dir)) !== false) { |
|
| 89 | - $nb_files++; |
|
| 90 | - if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) { |
|
| 91 | - $f = _DIR_SESSIONS . $f; |
|
| 92 | - if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
|
| 93 | - spip_unlink($f); |
|
| 94 | - } |
|
| 95 | - // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
|
| 96 | - // cf http://core.spip.org/issues/3276 |
|
| 97 | - elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | - spip_unlink($f); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } else { |
|
| 104 | - verifier_session(); |
|
| 105 | - spip_unlink(fichier_session('alea_ephemere', true)); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // forcer le recalcul de la session courante |
|
| 109 | - spip_session(true); |
|
| 80 | + $nb_files = 0; |
|
| 81 | + $nb_max_files = (defined('_MAX_NB_SESSIONS_OUVERTES') ? _MAX_NB_SESSIONS_OUVERTES : 1000); |
|
| 82 | + spip_log("supprimer sessions auteur $id_auteur", 'session'); |
|
| 83 | + if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 84 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 85 | + $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | + $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | + $t = time() - (4 * _RENOUVELLE_ALEA); |
|
| 88 | + while (($f = readdir($dir)) !== false) { |
|
| 89 | + $nb_files++; |
|
| 90 | + if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) { |
|
| 91 | + $f = _DIR_SESSIONS . $f; |
|
| 92 | + if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
|
| 93 | + spip_unlink($f); |
|
| 94 | + } |
|
| 95 | + // si il y a trop de sessions ouvertes, on purge les sessions anonymes de plus de 3H |
|
| 96 | + // cf http://core.spip.org/issues/3276 |
|
| 97 | + elseif ($nb_files > $nb_max_files and !intval($regs[1]) and ($t_short > filemtime($f))) { |
|
| 98 | + spip_unlink($f); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } else { |
|
| 104 | + verifier_session(); |
|
| 105 | + spip_unlink(fichier_session('alea_ephemere', true)); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // forcer le recalcul de la session courante |
|
| 109 | + spip_session(true); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -124,125 +124,125 @@ discard block |
||
| 124 | 124 | * @return bool|string |
| 125 | 125 | */ |
| 126 | 126 | function ajouter_session($auteur) { |
| 127 | - // Si le client a deja une session valide pour son id_auteur |
|
| 128 | - // on conserve le meme fichier |
|
| 129 | - |
|
| 130 | - // Attention un visiteur peut avoir une session et un id=0, |
|
| 131 | - // => ne pas melanger les sessions des differents visiteurs |
|
| 132 | - $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 133 | - |
|
| 134 | - // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session) |
|
| 135 | - // on va vérifier s'il y a vraiment des choses à écrire |
|
| 136 | - if (!$id_auteur) { |
|
| 137 | - // On supprime les données de base pour voir le contenu réel de la session |
|
| 138 | - $auteur_verif = $auteur; |
|
| 139 | - if (isset($auteur_verif['id_auteur'])) { |
|
| 140 | - unset($auteur_verif['id_auteur']); |
|
| 141 | - } |
|
| 142 | - if (isset($auteur_verif['hash_env'])) { |
|
| 143 | - unset($auteur_verif['hash_env']); |
|
| 144 | - } |
|
| 145 | - if (isset($auteur_verif['ip_change'])) { |
|
| 146 | - unset($auteur_verif['ip_change']); |
|
| 147 | - } |
|
| 148 | - if (isset($auteur_verif['date_session'])) { |
|
| 149 | - unset($auteur_verif['date_session']); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Les variables vraiment nulle ne sont pas à prendre en compte non plus |
|
| 153 | - foreach ($auteur_verif as $variable => $valeur) { |
|
| 154 | - if ($valeur === null) { |
|
| 155 | - unset($auteur_verif[$variable]); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là |
|
| 160 | - if (!$auteur_verif) { |
|
| 161 | - if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) { |
|
| 162 | - unset($_SESSION[$_COOKIE['spip_session']]); |
|
| 163 | - } |
|
| 164 | - if (isset($_COOKIE['spip_session'])) { |
|
| 165 | - unset($_COOKIE['spip_session']); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ( |
|
| 173 | - !isset($_COOKIE['spip_session']) |
|
| 174 | - or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 175 | - ) { |
|
| 176 | - $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // Maintenant on sait qu'on a des choses à écrire |
|
| 180 | - // On s'assure d'avoir au moins ces valeurs |
|
| 181 | - $auteur['id_auteur'] = $id_auteur; |
|
| 182 | - if (!isset($auteur['hash_env'])) { |
|
| 183 | - $auteur['hash_env'] = hash_env(); |
|
| 184 | - } |
|
| 185 | - if (!isset($auteur['ip_change'])) { |
|
| 186 | - $auteur['ip_change'] = false; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if (!isset($auteur['date_session'])) { |
|
| 190 | - $auteur['date_session'] = time(); |
|
| 191 | - } |
|
| 192 | - if ( |
|
| 193 | - isset($auteur['prefs']) |
|
| 194 | - and is_string($auteur['prefs']) |
|
| 195 | - and $prefs = @unserialize($auteur['prefs']) |
|
| 196 | - ) { |
|
| 197 | - $auteur['prefs'] = $prefs; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $fichier_session = ''; |
|
| 201 | - |
|
| 202 | - // les sessions anonymes sont stockees dans $_SESSION |
|
| 203 | - if (!$id_auteur) { |
|
| 204 | - spip_php_session_start(); |
|
| 205 | - $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur); |
|
| 206 | - } else { |
|
| 207 | - $fichier_session = fichier_session('alea_ephemere'); |
|
| 208 | - if (!ecrire_fichier_session($fichier_session, $auteur)) { |
|
| 209 | - spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS); |
|
| 210 | - include_spip('inc/minipres'); |
|
| 211 | - echo minipres(); |
|
| 212 | - exit; |
|
| 213 | - } |
|
| 214 | - // verifier et limiter le nombre maxi de sessions |
|
| 215 | - // https://core.spip.net/issues/3807 |
|
| 216 | - lister_sessions_auteur($id_auteur); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // poser le cookie de session SPIP |
|
| 220 | - include_spip('inc/cookie'); |
|
| 221 | - $duree = definir_duree_cookie_session($auteur); |
|
| 222 | - spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 223 | - 'expires' => time() + $duree |
|
| 224 | - ]); |
|
| 225 | - spip_log("ajoute session $fichier_session cookie $duree", 'session'); |
|
| 226 | - |
|
| 227 | - // Si on est admin, poser le cookie de correspondance |
|
| 228 | - if (!function_exists('autoriser')) { |
|
| 229 | - include_spip('inc/autoriser'); |
|
| 230 | - } |
|
| 231 | - if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 232 | - spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 233 | - 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
|
| 234 | - ]); |
|
| 235 | - } // sinon le supprimer ... |
|
| 236 | - else { |
|
| 237 | - spip_setcookie('spip_admin', '', [ |
|
| 238 | - 'expires' => 1 |
|
| 239 | - ]); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - # on en profite pour purger les vieilles sessions anonymes abandonnees |
|
| 243 | - # supprimer_sessions(0, true, false); |
|
| 244 | - |
|
| 245 | - return $_COOKIE['spip_session']; |
|
| 127 | + // Si le client a deja une session valide pour son id_auteur |
|
| 128 | + // on conserve le meme fichier |
|
| 129 | + |
|
| 130 | + // Attention un visiteur peut avoir une session et un id=0, |
|
| 131 | + // => ne pas melanger les sessions des differents visiteurs |
|
| 132 | + $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 133 | + |
|
| 134 | + // Si ce n'est pas un inscrit (les inscrits ont toujours des choses en session) |
|
| 135 | + // on va vérifier s'il y a vraiment des choses à écrire |
|
| 136 | + if (!$id_auteur) { |
|
| 137 | + // On supprime les données de base pour voir le contenu réel de la session |
|
| 138 | + $auteur_verif = $auteur; |
|
| 139 | + if (isset($auteur_verif['id_auteur'])) { |
|
| 140 | + unset($auteur_verif['id_auteur']); |
|
| 141 | + } |
|
| 142 | + if (isset($auteur_verif['hash_env'])) { |
|
| 143 | + unset($auteur_verif['hash_env']); |
|
| 144 | + } |
|
| 145 | + if (isset($auteur_verif['ip_change'])) { |
|
| 146 | + unset($auteur_verif['ip_change']); |
|
| 147 | + } |
|
| 148 | + if (isset($auteur_verif['date_session'])) { |
|
| 149 | + unset($auteur_verif['date_session']); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Les variables vraiment nulle ne sont pas à prendre en compte non plus |
|
| 153 | + foreach ($auteur_verif as $variable => $valeur) { |
|
| 154 | + if ($valeur === null) { |
|
| 155 | + unset($auteur_verif[$variable]); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // Si après ça la session est vide alors on supprime l'éventuel fichier et on arrête là |
|
| 160 | + if (!$auteur_verif) { |
|
| 161 | + if (isset($_COOKIE['spip_session']) and isset($_SESSION[$_COOKIE['spip_session']])) { |
|
| 162 | + unset($_SESSION[$_COOKIE['spip_session']]); |
|
| 163 | + } |
|
| 164 | + if (isset($_COOKIE['spip_session'])) { |
|
| 165 | + unset($_COOKIE['spip_session']); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ( |
|
| 173 | + !isset($_COOKIE['spip_session']) |
|
| 174 | + or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 175 | + ) { |
|
| 176 | + $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // Maintenant on sait qu'on a des choses à écrire |
|
| 180 | + // On s'assure d'avoir au moins ces valeurs |
|
| 181 | + $auteur['id_auteur'] = $id_auteur; |
|
| 182 | + if (!isset($auteur['hash_env'])) { |
|
| 183 | + $auteur['hash_env'] = hash_env(); |
|
| 184 | + } |
|
| 185 | + if (!isset($auteur['ip_change'])) { |
|
| 186 | + $auteur['ip_change'] = false; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if (!isset($auteur['date_session'])) { |
|
| 190 | + $auteur['date_session'] = time(); |
|
| 191 | + } |
|
| 192 | + if ( |
|
| 193 | + isset($auteur['prefs']) |
|
| 194 | + and is_string($auteur['prefs']) |
|
| 195 | + and $prefs = @unserialize($auteur['prefs']) |
|
| 196 | + ) { |
|
| 197 | + $auteur['prefs'] = $prefs; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $fichier_session = ''; |
|
| 201 | + |
|
| 202 | + // les sessions anonymes sont stockees dans $_SESSION |
|
| 203 | + if (!$id_auteur) { |
|
| 204 | + spip_php_session_start(); |
|
| 205 | + $_SESSION[$_COOKIE['spip_session']] = preparer_ecriture_session($auteur); |
|
| 206 | + } else { |
|
| 207 | + $fichier_session = fichier_session('alea_ephemere'); |
|
| 208 | + if (!ecrire_fichier_session($fichier_session, $auteur)) { |
|
| 209 | + spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS); |
|
| 210 | + include_spip('inc/minipres'); |
|
| 211 | + echo minipres(); |
|
| 212 | + exit; |
|
| 213 | + } |
|
| 214 | + // verifier et limiter le nombre maxi de sessions |
|
| 215 | + // https://core.spip.net/issues/3807 |
|
| 216 | + lister_sessions_auteur($id_auteur); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // poser le cookie de session SPIP |
|
| 220 | + include_spip('inc/cookie'); |
|
| 221 | + $duree = definir_duree_cookie_session($auteur); |
|
| 222 | + spip_setcookie('spip_session', $_COOKIE['spip_session'], [ |
|
| 223 | + 'expires' => time() + $duree |
|
| 224 | + ]); |
|
| 225 | + spip_log("ajoute session $fichier_session cookie $duree", 'session'); |
|
| 226 | + |
|
| 227 | + // Si on est admin, poser le cookie de correspondance |
|
| 228 | + if (!function_exists('autoriser')) { |
|
| 229 | + include_spip('inc/autoriser'); |
|
| 230 | + } |
|
| 231 | + if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
|
| 232 | + spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 233 | + 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
|
| 234 | + ]); |
|
| 235 | + } // sinon le supprimer ... |
|
| 236 | + else { |
|
| 237 | + spip_setcookie('spip_admin', '', [ |
|
| 238 | + 'expires' => 1 |
|
| 239 | + ]); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + # on en profite pour purger les vieilles sessions anonymes abandonnees |
|
| 243 | + # supprimer_sessions(0, true, false); |
|
| 244 | + |
|
| 245 | + return $_COOKIE['spip_session']; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -262,15 +262,15 @@ discard block |
||
| 262 | 262 | * Durée en secondes |
| 263 | 263 | **/ |
| 264 | 264 | function definir_duree_cookie_session($auteur) { |
| 265 | - $coef = 2; |
|
| 266 | - if (isset($auteur['cookie'])) { |
|
| 267 | - if (is_numeric($auteur['cookie'])) { |
|
| 268 | - $coef = $auteur['cookie']; |
|
| 269 | - } else { |
|
| 270 | - $coef = 20; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 265 | + $coef = 2; |
|
| 266 | + if (isset($auteur['cookie'])) { |
|
| 267 | + if (is_numeric($auteur['cookie'])) { |
|
| 268 | + $coef = $auteur['cookie']; |
|
| 269 | + } else { |
|
| 270 | + $coef = 20; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -290,91 +290,91 @@ discard block |
||
| 290 | 290 | * @return bool|int|null |
| 291 | 291 | */ |
| 292 | 292 | function verifier_session($change = false) { |
| 293 | - // si pas de cookie, c'est fichu |
|
| 294 | - if (!isset($_COOKIE['spip_session'])) { |
|
| 295 | - return false; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $fichier_session = ''; |
|
| 299 | - |
|
| 300 | - // est-ce une session anonyme ? |
|
| 301 | - if (!intval($_COOKIE['spip_session'])) { |
|
| 302 | - spip_php_session_start(); |
|
| 303 | - if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) { |
|
| 304 | - return false; |
|
| 305 | - } |
|
| 306 | - $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']]; |
|
| 307 | - } else { |
|
| 308 | - // Tester avec alea courant |
|
| 309 | - $fichier_session = fichier_session('alea_ephemere', true); |
|
| 310 | - if ($fichier_session and @file_exists($fichier_session)) { |
|
| 311 | - include($fichier_session); |
|
| 312 | - } else { |
|
| 313 | - // Sinon, tester avec alea precedent |
|
| 314 | - $fichier_session = fichier_session('alea_ephemere_ancien', true); |
|
| 315 | - if (!$fichier_session or !@file_exists($fichier_session)) { |
|
| 316 | - return false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // Renouveler la session avec l'alea courant |
|
| 320 | - include($fichier_session); |
|
| 321 | - spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 322 | - spip_unlink($fichier_session); |
|
| 323 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - // Compatibilite ascendante : auteur_session est visiteur_session si |
|
| 328 | - // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut |
|
| 329 | - // n'etre qu'identifie, sans aucune authentification). |
|
| 330 | - |
|
| 331 | - if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 332 | - $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - // Si l'adresse IP change, inc/presentation mettra une balise image |
|
| 337 | - // avec un URL de rappel demandant a changer le nom de la session. |
|
| 338 | - // Seul celui qui a l'IP d'origine est rejoue |
|
| 339 | - // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter |
|
| 340 | - // sa victime, mais se ferait deconnecter par elle. |
|
| 341 | - if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) { |
|
| 342 | - if (!$GLOBALS['visiteur_session']['ip_change']) { |
|
| 343 | - define('_SESSION_REJOUER', true); |
|
| 344 | - $GLOBALS['visiteur_session']['ip_change'] = true; |
|
| 345 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 346 | - } else { |
|
| 347 | - if ($change) { |
|
| 348 | - spip_log('session non rejouee, vol de cookie ?', 'session'); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } else { |
|
| 352 | - if ($change) { |
|
| 353 | - spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session'); |
|
| 354 | - if ($fichier_session) { |
|
| 355 | - spip_unlink($fichier_session); |
|
| 356 | - } |
|
| 357 | - $GLOBALS['visiteur_session']['ip_change'] = false; |
|
| 358 | - unset($_COOKIE['spip_session']); |
|
| 359 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Si la session a ete initiee il y a trop longtemps, elle est annulee |
|
| 364 | - if ( |
|
| 365 | - isset($GLOBALS['visiteur_session']) |
|
| 366 | - and defined('_AGE_SESSION_MAX') |
|
| 367 | - and _AGE_SESSION_MAX > 0 |
|
| 368 | - and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX |
|
| 369 | - ) { |
|
| 370 | - unset($GLOBALS['visiteur_session']); |
|
| 371 | - |
|
| 372 | - return false; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 376 | - ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 377 | - : null; |
|
| 293 | + // si pas de cookie, c'est fichu |
|
| 294 | + if (!isset($_COOKIE['spip_session'])) { |
|
| 295 | + return false; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $fichier_session = ''; |
|
| 299 | + |
|
| 300 | + // est-ce une session anonyme ? |
|
| 301 | + if (!intval($_COOKIE['spip_session'])) { |
|
| 302 | + spip_php_session_start(); |
|
| 303 | + if (!isset($_SESSION[$_COOKIE['spip_session']]) or !is_array($_SESSION[$_COOKIE['spip_session']])) { |
|
| 304 | + return false; |
|
| 305 | + } |
|
| 306 | + $GLOBALS['visiteur_session'] = $_SESSION[$_COOKIE['spip_session']]; |
|
| 307 | + } else { |
|
| 308 | + // Tester avec alea courant |
|
| 309 | + $fichier_session = fichier_session('alea_ephemere', true); |
|
| 310 | + if ($fichier_session and @file_exists($fichier_session)) { |
|
| 311 | + include($fichier_session); |
|
| 312 | + } else { |
|
| 313 | + // Sinon, tester avec alea precedent |
|
| 314 | + $fichier_session = fichier_session('alea_ephemere_ancien', true); |
|
| 315 | + if (!$fichier_session or !@file_exists($fichier_session)) { |
|
| 316 | + return false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // Renouveler la session avec l'alea courant |
|
| 320 | + include($fichier_session); |
|
| 321 | + spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 322 | + spip_unlink($fichier_session); |
|
| 323 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + // Compatibilite ascendante : auteur_session est visiteur_session si |
|
| 328 | + // c'est un auteur SPIP authentifie (tandis qu'un visiteur_session peut |
|
| 329 | + // n'etre qu'identifie, sans aucune authentification). |
|
| 330 | + |
|
| 331 | + if (isset($GLOBALS['visiteur_session']['id_auteur']) and $GLOBALS['visiteur_session']['id_auteur']) { |
|
| 332 | + $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + // Si l'adresse IP change, inc/presentation mettra une balise image |
|
| 337 | + // avec un URL de rappel demandant a changer le nom de la session. |
|
| 338 | + // Seul celui qui a l'IP d'origine est rejoue |
|
| 339 | + // ainsi un eventuel voleur de cookie ne pourrait pas deconnecter |
|
| 340 | + // sa victime, mais se ferait deconnecter par elle. |
|
| 341 | + if (hash_env() != $GLOBALS['visiteur_session']['hash_env']) { |
|
| 342 | + if (!$GLOBALS['visiteur_session']['ip_change']) { |
|
| 343 | + define('_SESSION_REJOUER', true); |
|
| 344 | + $GLOBALS['visiteur_session']['ip_change'] = true; |
|
| 345 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 346 | + } else { |
|
| 347 | + if ($change) { |
|
| 348 | + spip_log('session non rejouee, vol de cookie ?', 'session'); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } else { |
|
| 352 | + if ($change) { |
|
| 353 | + spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session'); |
|
| 354 | + if ($fichier_session) { |
|
| 355 | + spip_unlink($fichier_session); |
|
| 356 | + } |
|
| 357 | + $GLOBALS['visiteur_session']['ip_change'] = false; |
|
| 358 | + unset($_COOKIE['spip_session']); |
|
| 359 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Si la session a ete initiee il y a trop longtemps, elle est annulee |
|
| 364 | + if ( |
|
| 365 | + isset($GLOBALS['visiteur_session']) |
|
| 366 | + and defined('_AGE_SESSION_MAX') |
|
| 367 | + and _AGE_SESSION_MAX > 0 |
|
| 368 | + and time() - @$GLOBALS['visiteur_session']['date_session'] > _AGE_SESSION_MAX |
|
| 369 | + ) { |
|
| 370 | + unset($GLOBALS['visiteur_session']); |
|
| 371 | + |
|
| 372 | + return false; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return is_numeric($GLOBALS['visiteur_session']['id_auteur']) |
|
| 376 | + ? $GLOBALS['visiteur_session']['id_auteur'] |
|
| 377 | + : null; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * Valeur, si trouvée, `null` sinon. |
| 390 | 390 | */ |
| 391 | 391 | function session_get($nom) { |
| 392 | - return $GLOBALS['visiteur_session'][$nom] ?? null; |
|
| 392 | + return $GLOBALS['visiteur_session'][$nom] ?? null; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -405,32 +405,32 @@ discard block |
||
| 405 | 405 | * @return void|array |
| 406 | 406 | */ |
| 407 | 407 | function session_set($nom, $val = null) { |
| 408 | - static $remove = []; |
|
| 409 | - static $actualiser_sessions = false; |
|
| 410 | - if ($nom === false) { |
|
| 411 | - return $remove; |
|
| 412 | - } |
|
| 413 | - if (is_null($val)) { |
|
| 414 | - // rien a faire |
|
| 415 | - if (!isset($GLOBALS['visiteur_session'][$nom])) { |
|
| 416 | - return; |
|
| 417 | - } |
|
| 418 | - unset($GLOBALS['visiteur_session'][$nom]); |
|
| 419 | - $remove[] = $nom; |
|
| 420 | - } else { |
|
| 421 | - // On ajoute la valeur dans la globale |
|
| 422 | - $GLOBALS['visiteur_session'][$nom] = $val; |
|
| 423 | - if ($remove) { |
|
| 424 | - $remove = array_diff($remove, [$nom]); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - if (!$actualiser_sessions) { |
|
| 428 | - // il faut creer la session si on en a pas, la premiere fois |
|
| 429 | - ajouter_session($GLOBALS['visiteur_session']); |
|
| 430 | - // in register la fonction qui mettra a jour toutes les sessions en fin de hit |
|
| 431 | - register_shutdown_function('terminer_actualiser_sessions'); |
|
| 432 | - $actualiser_sessions = true; |
|
| 433 | - } |
|
| 408 | + static $remove = []; |
|
| 409 | + static $actualiser_sessions = false; |
|
| 410 | + if ($nom === false) { |
|
| 411 | + return $remove; |
|
| 412 | + } |
|
| 413 | + if (is_null($val)) { |
|
| 414 | + // rien a faire |
|
| 415 | + if (!isset($GLOBALS['visiteur_session'][$nom])) { |
|
| 416 | + return; |
|
| 417 | + } |
|
| 418 | + unset($GLOBALS['visiteur_session'][$nom]); |
|
| 419 | + $remove[] = $nom; |
|
| 420 | + } else { |
|
| 421 | + // On ajoute la valeur dans la globale |
|
| 422 | + $GLOBALS['visiteur_session'][$nom] = $val; |
|
| 423 | + if ($remove) { |
|
| 424 | + $remove = array_diff($remove, [$nom]); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + if (!$actualiser_sessions) { |
|
| 428 | + // il faut creer la session si on en a pas, la premiere fois |
|
| 429 | + ajouter_session($GLOBALS['visiteur_session']); |
|
| 430 | + // in register la fonction qui mettra a jour toutes les sessions en fin de hit |
|
| 431 | + register_shutdown_function('terminer_actualiser_sessions'); |
|
| 432 | + $actualiser_sessions = true; |
|
| 433 | + } |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | /** |
@@ -439,12 +439,12 @@ discard block |
||
| 439 | 439 | * @uses actualiser_sessions() |
| 440 | 440 | */ |
| 441 | 441 | function terminer_actualiser_sessions() { |
| 442 | - // se remettre dans le dossier de travail au cas ou Apache a change |
|
| 443 | - chdir(_ROOT_CWD); |
|
| 444 | - // recuperer les variables a effacer |
|
| 445 | - $remove = session_set(false); |
|
| 446 | - // mettre a jour toutes les sessions |
|
| 447 | - actualiser_sessions($GLOBALS['visiteur_session'], $remove); |
|
| 442 | + // se remettre dans le dossier de travail au cas ou Apache a change |
|
| 443 | + chdir(_ROOT_CWD); |
|
| 444 | + // recuperer les variables a effacer |
|
| 445 | + $remove = session_set(false); |
|
| 446 | + // mettre a jour toutes les sessions |
|
| 447 | + actualiser_sessions($GLOBALS['visiteur_session'], $remove); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
@@ -469,83 +469,83 @@ discard block |
||
| 469 | 469 | */ |
| 470 | 470 | function actualiser_sessions($auteur, $supprimer_cles = []) { |
| 471 | 471 | |
| 472 | - $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 473 | - $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0; |
|
| 474 | - |
|
| 475 | - // si l'auteur est celui de la session courante, verifier/creer la session si besoin |
|
| 476 | - $fichier_session_courante = ''; |
|
| 477 | - if ($id_auteur == $id_auteur_courant) { |
|
| 478 | - $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 479 | - ajouter_session($auteur); |
|
| 480 | - if ($id_auteur) { |
|
| 481 | - $fichier_session_courante = fichier_session('alea_ephemere'); |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees |
|
| 486 | - if (!$id_auteur) { |
|
| 487 | - return; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - // les préférences sont désérialisées, toujours. |
|
| 491 | - // [fixme] Le champ 'prefs' sert aussi à l’inscription |
|
| 492 | - if (isset($auteur['prefs']) and is_string($auteur['prefs'])) { |
|
| 493 | - $auteur['prefs'] = @unserialize($auteur['prefs']); |
|
| 494 | - if (!is_array($auteur['prefs'])) { |
|
| 495 | - $auteur['prefs'] = []; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // memoriser l'auteur courant (celui qui modifie la fiche) |
|
| 500 | - $sauve = $GLOBALS['visiteur_session']; |
|
| 501 | - |
|
| 502 | - // .. mettre a jour les sessions de l'auteur cible |
|
| 503 | - // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire |
|
| 504 | - // cree par une ecriture concurente d'une session (fichier atomique temporaire) |
|
| 505 | - $sessions = lister_sessions_auteur($id_auteur); |
|
| 506 | - |
|
| 507 | - // 1ere passe : lire et fusionner les sessions |
|
| 508 | - foreach ($sessions as $session) { |
|
| 509 | - $GLOBALS['visiteur_session'] = []; |
|
| 510 | - // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 511 | - if ( |
|
| 512 | - $session !== $fichier_session_courante |
|
| 513 | - and @file_exists($session) |
|
| 514 | - ) { |
|
| 515 | - include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 516 | - |
|
| 517 | - $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // supprimer les eventuelles cles dont on ne veut plus |
|
| 522 | - foreach ($supprimer_cles as $cle) { |
|
| 523 | - unset($auteur[$cle]); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - $auteur_session = preparer_ecriture_session($auteur); |
|
| 527 | - |
|
| 528 | - // seconde passe : ecrire les sessions qui ne sont pas a jour |
|
| 529 | - foreach ($sessions as $session) { |
|
| 530 | - $GLOBALS['visiteur_session'] = []; |
|
| 531 | - // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 532 | - if (@file_exists($session)) { |
|
| 533 | - include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 534 | - |
|
| 535 | - // est-ce que cette session est a mettre a jour ? |
|
| 536 | - if ($auteur_session != $GLOBALS['visiteur_session']) { |
|
| 537 | - ecrire_fichier_session($session, $auteur); |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - if ($id_auteur == $id_auteur_courant) { |
|
| 543 | - $GLOBALS['visiteur_session'] = $auteur; |
|
| 544 | - $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 545 | - } else { |
|
| 546 | - // restaurer l'auteur courant |
|
| 547 | - $GLOBALS['visiteur_session'] = $sauve; |
|
| 548 | - } |
|
| 472 | + $id_auteur = isset($auteur['id_auteur']) ? intval($auteur['id_auteur']) : 0; |
|
| 473 | + $id_auteur_courant = isset($GLOBALS['visiteur_session']['id_auteur']) ? intval($GLOBALS['visiteur_session']['id_auteur']) : 0; |
|
| 474 | + |
|
| 475 | + // si l'auteur est celui de la session courante, verifier/creer la session si besoin |
|
| 476 | + $fichier_session_courante = ''; |
|
| 477 | + if ($id_auteur == $id_auteur_courant) { |
|
| 478 | + $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 479 | + ajouter_session($auteur); |
|
| 480 | + if ($id_auteur) { |
|
| 481 | + $fichier_session_courante = fichier_session('alea_ephemere'); |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // si session anonyme on ne fait rien d'autre ici : les sessions anonymes sont non partagees |
|
| 486 | + if (!$id_auteur) { |
|
| 487 | + return; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + // les préférences sont désérialisées, toujours. |
|
| 491 | + // [fixme] Le champ 'prefs' sert aussi à l’inscription |
|
| 492 | + if (isset($auteur['prefs']) and is_string($auteur['prefs'])) { |
|
| 493 | + $auteur['prefs'] = @unserialize($auteur['prefs']); |
|
| 494 | + if (!is_array($auteur['prefs'])) { |
|
| 495 | + $auteur['prefs'] = []; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // memoriser l'auteur courant (celui qui modifie la fiche) |
|
| 500 | + $sauve = $GLOBALS['visiteur_session']; |
|
| 501 | + |
|
| 502 | + // .. mettre a jour les sessions de l'auteur cible |
|
| 503 | + // attention au $ final pour ne pas risquer d'embarquer un .php.jeton temporaire |
|
| 504 | + // cree par une ecriture concurente d'une session (fichier atomique temporaire) |
|
| 505 | + $sessions = lister_sessions_auteur($id_auteur); |
|
| 506 | + |
|
| 507 | + // 1ere passe : lire et fusionner les sessions |
|
| 508 | + foreach ($sessions as $session) { |
|
| 509 | + $GLOBALS['visiteur_session'] = []; |
|
| 510 | + // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 511 | + if ( |
|
| 512 | + $session !== $fichier_session_courante |
|
| 513 | + and @file_exists($session) |
|
| 514 | + ) { |
|
| 515 | + include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 516 | + |
|
| 517 | + $auteur = array_merge($GLOBALS['visiteur_session'], $auteur); |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // supprimer les eventuelles cles dont on ne veut plus |
|
| 522 | + foreach ($supprimer_cles as $cle) { |
|
| 523 | + unset($auteur[$cle]); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + $auteur_session = preparer_ecriture_session($auteur); |
|
| 527 | + |
|
| 528 | + // seconde passe : ecrire les sessions qui ne sont pas a jour |
|
| 529 | + foreach ($sessions as $session) { |
|
| 530 | + $GLOBALS['visiteur_session'] = []; |
|
| 531 | + // a pu etre supprime entre le preg initial et le moment ou l'on arrive la (concurrence) |
|
| 532 | + if (@file_exists($session)) { |
|
| 533 | + include $session; # $GLOBALS['visiteur_session'] est alors l'auteur cible |
|
| 534 | + |
|
| 535 | + // est-ce que cette session est a mettre a jour ? |
|
| 536 | + if ($auteur_session != $GLOBALS['visiteur_session']) { |
|
| 537 | + ecrire_fichier_session($session, $auteur); |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + if ($id_auteur == $id_auteur_courant) { |
|
| 543 | + $GLOBALS['visiteur_session'] = $auteur; |
|
| 544 | + $GLOBALS['auteur_session'] = &$GLOBALS['visiteur_session']; |
|
| 545 | + } else { |
|
| 546 | + // restaurer l'auteur courant |
|
| 547 | + $GLOBALS['visiteur_session'] = $sauve; |
|
| 548 | + } |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /** |
@@ -559,48 +559,48 @@ discard block |
||
| 559 | 559 | */ |
| 560 | 560 | function lister_sessions_auteur($id_auteur, $nb_max = null) { |
| 561 | 561 | |
| 562 | - if (is_null($nb_max)) { |
|
| 563 | - if (!defined('_NB_SESSIONS_MAX')) { |
|
| 564 | - define('_NB_SESSIONS_MAX', 100); |
|
| 565 | - } |
|
| 566 | - $nb_max = _NB_SESSIONS_MAX; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - // liste des sessions |
|
| 570 | - $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 571 | - |
|
| 572 | - // si on en a plus que la limite, supprimer les plus vieilles |
|
| 573 | - // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
|
| 574 | - if ( |
|
| 575 | - $id_auteur |
|
| 576 | - and count($sessions) > $nb_max |
|
| 577 | - ) { |
|
| 578 | - // limiter le nombre de sessions ouvertes par un auteur |
|
| 579 | - // filemtime sur les sessions |
|
| 580 | - $sessions = array_flip($sessions); |
|
| 581 | - |
|
| 582 | - // 1ere passe : lire les filemtime |
|
| 583 | - foreach ($sessions as $session => $z) { |
|
| 584 | - if ( |
|
| 585 | - $d = @filemtime($session) |
|
| 586 | - ) { |
|
| 587 | - $sessions[$session] = $d; |
|
| 588 | - } else { |
|
| 589 | - $sessions[$session] = 0; |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - // les plus anciennes en premier |
|
| 594 | - asort($sessions); |
|
| 595 | - |
|
| 596 | - $sessions = array_keys($sessions); |
|
| 597 | - while (count($sessions) > $nb_max) { |
|
| 598 | - $session = array_shift($sessions); |
|
| 599 | - @unlink($session); |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - return $sessions; |
|
| 562 | + if (is_null($nb_max)) { |
|
| 563 | + if (!defined('_NB_SESSIONS_MAX')) { |
|
| 564 | + define('_NB_SESSIONS_MAX', 100); |
|
| 565 | + } |
|
| 566 | + $nb_max = _NB_SESSIONS_MAX; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + // liste des sessions |
|
| 570 | + $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 571 | + |
|
| 572 | + // si on en a plus que la limite, supprimer les plus vieilles |
|
| 573 | + // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
|
| 574 | + if ( |
|
| 575 | + $id_auteur |
|
| 576 | + and count($sessions) > $nb_max |
|
| 577 | + ) { |
|
| 578 | + // limiter le nombre de sessions ouvertes par un auteur |
|
| 579 | + // filemtime sur les sessions |
|
| 580 | + $sessions = array_flip($sessions); |
|
| 581 | + |
|
| 582 | + // 1ere passe : lire les filemtime |
|
| 583 | + foreach ($sessions as $session => $z) { |
|
| 584 | + if ( |
|
| 585 | + $d = @filemtime($session) |
|
| 586 | + ) { |
|
| 587 | + $sessions[$session] = $d; |
|
| 588 | + } else { |
|
| 589 | + $sessions[$session] = 0; |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + // les plus anciennes en premier |
|
| 594 | + asort($sessions); |
|
| 595 | + |
|
| 596 | + $sessions = array_keys($sessions); |
|
| 597 | + while (count($sessions) > $nb_max) { |
|
| 598 | + $session = array_shift($sessions); |
|
| 599 | + @unlink($session); |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + return $sessions; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | |
@@ -614,26 +614,26 @@ discard block |
||
| 614 | 614 | * @return array |
| 615 | 615 | */ |
| 616 | 616 | function preparer_ecriture_session($auteur) { |
| 617 | - $row = $auteur; |
|
| 618 | - |
|
| 619 | - // ne pas enregistrer ces elements de securite |
|
| 620 | - // dans le fichier de session |
|
| 621 | - unset($auteur['pass']); |
|
| 622 | - unset($auteur['htpass']); |
|
| 623 | - unset($auteur['low_sec']); |
|
| 624 | - unset($auteur['alea_actuel']); |
|
| 625 | - unset($auteur['alea_futur']); |
|
| 626 | - |
|
| 627 | - $auteur = pipeline('preparer_fichier_session', ['args' => ['row' => $row], 'data' => $auteur]); |
|
| 628 | - |
|
| 629 | - // ne pas enregistrer les valeurs vraiment nulle dans le fichier |
|
| 630 | - foreach ($auteur as $variable => $valeur) { |
|
| 631 | - if ($valeur === null) { |
|
| 632 | - unset($auteur[$variable]); |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - return $auteur; |
|
| 617 | + $row = $auteur; |
|
| 618 | + |
|
| 619 | + // ne pas enregistrer ces elements de securite |
|
| 620 | + // dans le fichier de session |
|
| 621 | + unset($auteur['pass']); |
|
| 622 | + unset($auteur['htpass']); |
|
| 623 | + unset($auteur['low_sec']); |
|
| 624 | + unset($auteur['alea_actuel']); |
|
| 625 | + unset($auteur['alea_futur']); |
|
| 626 | + |
|
| 627 | + $auteur = pipeline('preparer_fichier_session', ['args' => ['row' => $row], 'data' => $auteur]); |
|
| 628 | + |
|
| 629 | + // ne pas enregistrer les valeurs vraiment nulle dans le fichier |
|
| 630 | + foreach ($auteur as $variable => $valeur) { |
|
| 631 | + if ($valeur === null) { |
|
| 632 | + unset($auteur[$variable]); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + return $auteur; |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
@@ -645,17 +645,17 @@ discard block |
||
| 645 | 645 | */ |
| 646 | 646 | function ecrire_fichier_session($fichier, $auteur) { |
| 647 | 647 | |
| 648 | - $auteur = preparer_ecriture_session($auteur); |
|
| 648 | + $auteur = preparer_ecriture_session($auteur); |
|
| 649 | 649 | |
| 650 | - // enregistrer les autres donnees du visiteur |
|
| 651 | - $texte = '<' . "?php\n"; |
|
| 652 | - foreach ($auteur as $var => $val) { |
|
| 653 | - $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 654 | - . var_export($val, true) . ";\n"; |
|
| 655 | - } |
|
| 656 | - $texte .= '?' . ">\n"; |
|
| 650 | + // enregistrer les autres donnees du visiteur |
|
| 651 | + $texte = '<' . "?php\n"; |
|
| 652 | + foreach ($auteur as $var => $val) { |
|
| 653 | + $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 654 | + . var_export($val, true) . ";\n"; |
|
| 655 | + } |
|
| 656 | + $texte .= '?' . ">\n"; |
|
| 657 | 657 | |
| 658 | - return ecrire_fichier($fichier, $texte); |
|
| 658 | + return ecrire_fichier($fichier, $texte); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | |
@@ -668,23 +668,23 @@ discard block |
||
| 668 | 668 | */ |
| 669 | 669 | function fichier_session($alea, $tantpis = false) { |
| 670 | 670 | |
| 671 | - include_spip('inc/acces'); |
|
| 672 | - charger_aleas(); |
|
| 671 | + include_spip('inc/acces'); |
|
| 672 | + charger_aleas(); |
|
| 673 | 673 | |
| 674 | - if (empty($GLOBALS['meta'][$alea])) { |
|
| 675 | - if (!$tantpis) { |
|
| 676 | - spip_log("fichier session ($tantpis): $alea indisponible", 'session'); |
|
| 677 | - include_spip('inc/minipres'); |
|
| 678 | - echo minipres(); |
|
| 679 | - } |
|
| 674 | + if (empty($GLOBALS['meta'][$alea])) { |
|
| 675 | + if (!$tantpis) { |
|
| 676 | + spip_log("fichier session ($tantpis): $alea indisponible", 'session'); |
|
| 677 | + include_spip('inc/minipres'); |
|
| 678 | + echo minipres(); |
|
| 679 | + } |
|
| 680 | 680 | |
| 681 | - return ''; // echec mais $tanpis |
|
| 682 | - } else { |
|
| 683 | - $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
|
| 684 | - $c = $_COOKIE['spip_session']; |
|
| 681 | + return ''; // echec mais $tanpis |
|
| 682 | + } else { |
|
| 683 | + $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
|
| 684 | + $c = $_COOKIE['spip_session']; |
|
| 685 | 685 | |
| 686 | - return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 687 | - } |
|
| 686 | + return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 687 | + } |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | * @return string |
| 702 | 702 | */ |
| 703 | 703 | function rejouer_session() { |
| 704 | - return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 704 | + return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
@@ -711,12 +711,12 @@ discard block |
||
| 711 | 711 | * @return string |
| 712 | 712 | */ |
| 713 | 713 | function hash_env() { |
| 714 | - static $res = ''; |
|
| 715 | - if ($res) { |
|
| 716 | - return $res; |
|
| 717 | - } |
|
| 714 | + static $res = ''; |
|
| 715 | + if ($res) { |
|
| 716 | + return $res; |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | - return $res = md5($GLOBALS['ip'] . ($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 719 | + return $res = md5($GLOBALS['ip'] . ($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -728,11 +728,11 @@ discard block |
||
| 728 | 728 | * @return bool True si une session PHP est ouverte. |
| 729 | 729 | **/ |
| 730 | 730 | function spip_php_session_start() { |
| 731 | - if (!is_php_session_started()) { |
|
| 732 | - return session_start(); |
|
| 733 | - } |
|
| 731 | + if (!is_php_session_started()) { |
|
| 732 | + return session_start(); |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | - return true; |
|
| 735 | + return true; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -742,9 +742,9 @@ discard block |
||
| 742 | 742 | * @return bool true si une session PHP est active |
| 743 | 743 | **/ |
| 744 | 744 | function is_php_session_started() { |
| 745 | - if (php_sapi_name() !== 'cli') { |
|
| 746 | - return session_status() === PHP_SESSION_ACTIVE ? true : false; |
|
| 747 | - } |
|
| 745 | + if (php_sapi_name() !== 'cli') { |
|
| 746 | + return session_status() === PHP_SESSION_ACTIVE ? true : false; |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | - return false; |
|
| 749 | + return false; |
|
| 750 | 750 | } |
@@ -82,13 +82,13 @@ discard block |
||
| 82 | 82 | spip_log("supprimer sessions auteur $id_auteur", 'session'); |
| 83 | 83 | if ($toutes or $id_auteur !== $GLOBALS['visiteur_session']['id_auteur']) { |
| 84 | 84 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 85 | - $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | - $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 85 | + $t = $_SERVER['REQUEST_TIME'] - (4 * _RENOUVELLE_ALEA); // 48h par defaut |
|
| 86 | + $t_short = $_SERVER['REQUEST_TIME'] - max(_RENOUVELLE_ALEA / 4, 3 * 3600); // 3h par defaut |
|
| 87 | 87 | $t = time() - (4 * _RENOUVELLE_ALEA); |
| 88 | 88 | while (($f = readdir($dir)) !== false) { |
| 89 | 89 | $nb_files++; |
| 90 | 90 | if (preg_match(',^[^\d-]*(-?\d+)_\w{32}\.php[3]?$,', $f, $regs)) { |
| 91 | - $f = _DIR_SESSIONS . $f; |
|
| 91 | + $f = _DIR_SESSIONS.$f; |
|
| 92 | 92 | if (($actives and $regs[1] == $id_auteur) or ($t > filemtime($f))) { |
| 93 | 93 | spip_unlink($f); |
| 94 | 94 | } |
@@ -171,9 +171,9 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | if ( |
| 173 | 173 | !isset($_COOKIE['spip_session']) |
| 174 | - or !preg_match(',^' . $id_auteur . '_,', $_COOKIE['spip_session']) |
|
| 174 | + or !preg_match(',^'.$id_auteur.'_,', $_COOKIE['spip_session']) |
|
| 175 | 175 | ) { |
| 176 | - $_COOKIE['spip_session'] = $id_auteur . '_' . md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 176 | + $_COOKIE['spip_session'] = $id_auteur.'_'.md5(uniqid(random_int(0, mt_getrandmax()), true)); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // Maintenant on sait qu'on a des choses à écrire |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | } else { |
| 207 | 207 | $fichier_session = fichier_session('alea_ephemere'); |
| 208 | 208 | if (!ecrire_fichier_session($fichier_session, $auteur)) { |
| 209 | - spip_log('Echec ecriture fichier session ' . $fichier_session, 'session' . _LOG_HS); |
|
| 209 | + spip_log('Echec ecriture fichier session '.$fichier_session, 'session'._LOG_HS); |
|
| 210 | 210 | include_spip('inc/minipres'); |
| 211 | 211 | echo minipres(); |
| 212 | 212 | exit; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | include_spip('inc/autoriser'); |
| 230 | 230 | } |
| 231 | 231 | if (autoriser('ecrire', '', '', $auteur) and _DUREE_COOKIE_ADMIN) { |
| 232 | - spip_setcookie('spip_admin', '@' . ($auteur['email'] ?: $auteur['login']), [ |
|
| 232 | + spip_setcookie('spip_admin', '@'.($auteur['email'] ?: $auteur['login']), [ |
|
| 233 | 233 | 'expires' => time() + max(_DUREE_COOKIE_ADMIN, $duree) |
| 234 | 234 | ]); |
| 235 | 235 | } // sinon le supprimer ... |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $coef = 20; |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | - return (int)(_RENOUVELLE_ALEA * $coef); |
|
| 273 | + return (int) (_RENOUVELLE_ALEA * $coef); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | // Renouveler la session avec l'alea courant |
| 320 | 320 | include($fichier_session); |
| 321 | - spip_log('renouvelle session ' . $GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 321 | + spip_log('renouvelle session '.$GLOBALS['visiteur_session']['id_auteur'], 'session'); |
|
| 322 | 322 | spip_unlink($fichier_session); |
| 323 | 323 | ajouter_session($GLOBALS['visiteur_session']); |
| 324 | 324 | } |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | } |
| 351 | 351 | } else { |
| 352 | 352 | if ($change) { |
| 353 | - spip_log("rejoue session $fichier_session " . $_COOKIE['spip_session'], 'session'); |
|
| 353 | + spip_log("rejoue session $fichier_session ".$_COOKIE['spip_session'], 'session'); |
|
| 354 | 354 | if ($fichier_session) { |
| 355 | 355 | spip_unlink($fichier_session); |
| 356 | 356 | } |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | // liste des sessions |
| 570 | - $sessions = preg_files(_DIR_SESSIONS, '/' . $id_auteur . '_.*\.php$'); |
|
| 570 | + $sessions = preg_files(_DIR_SESSIONS, '/'.$id_auteur.'_.*\.php$'); |
|
| 571 | 571 | |
| 572 | 572 | // si on en a plus que la limite, supprimer les plus vieilles |
| 573 | 573 | // si ce ne sont pas des sessions anonymes car elles sont alors chacune differentes |
@@ -648,12 +648,12 @@ discard block |
||
| 648 | 648 | $auteur = preparer_ecriture_session($auteur); |
| 649 | 649 | |
| 650 | 650 | // enregistrer les autres donnees du visiteur |
| 651 | - $texte = '<' . "?php\n"; |
|
| 651 | + $texte = '<'."?php\n"; |
|
| 652 | 652 | foreach ($auteur as $var => $val) { |
| 653 | - $texte .= '$GLOBALS[\'visiteur_session\'][' . var_export($var, true) . '] = ' |
|
| 654 | - . var_export($val, true) . ";\n"; |
|
| 653 | + $texte .= '$GLOBALS[\'visiteur_session\']['.var_export($var, true).'] = ' |
|
| 654 | + . var_export($val, true).";\n"; |
|
| 655 | 655 | } |
| 656 | - $texte .= '?' . ">\n"; |
|
| 656 | + $texte .= '?'.">\n"; |
|
| 657 | 657 | |
| 658 | 658 | return ecrire_fichier($fichier, $texte); |
| 659 | 659 | } |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | $repertoire = sous_repertoire(_DIR_SESSIONS, '', false, $tantpis); |
| 684 | 684 | $c = $_COOKIE['spip_session']; |
| 685 | 685 | |
| 686 | - return $repertoire . intval($c) . '_' . md5($c . ' ' . $GLOBALS['meta'][$alea]) . '.php'; |
|
| 686 | + return $repertoire.intval($c).'_'.md5($c.' '.$GLOBALS['meta'][$alea]).'.php'; |
|
| 687 | 687 | } |
| 688 | 688 | } |
| 689 | 689 | |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | * @return string |
| 702 | 702 | */ |
| 703 | 703 | function rejouer_session() { |
| 704 | - return '<img src="' . generer_url_action('cookie', 'change_session=oui', true) . '" width="0" height="0" alt="" />'; |
|
| 704 | + return '<img src="'.generer_url_action('cookie', 'change_session=oui', true).'" width="0" height="0" alt="" />'; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | return $res; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - return $res = md5($GLOBALS['ip'] . ($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 719 | + return $res = md5($GLOBALS['ip'].($_SERVER['HTTP_USER_AGENT'] ?? '')); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -553,16 +553,14 @@ |
||
| 553 | 553 | if (stripos($suite, 'SELECT') !== false) { |
| 554 | 554 | if ($echappe_textes) { |
| 555 | 555 | [$suite_echap, $textes] = query_echappe_textes($suite); |
| 556 | - } |
|
| 557 | - else { |
|
| 556 | + } else { |
|
| 558 | 557 | $suite_echap = $suite; |
| 559 | 558 | } |
| 560 | 559 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
| 561 | 560 | $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
| 562 | 561 | if ($echappe_textes) { |
| 563 | 562 | $suite = query_reinjecte_textes($suite_echap, $textes); |
| 564 | - } |
|
| 565 | - else { |
|
| 563 | + } else { |
|
| 566 | 564 | $suite = $suite_echap; |
| 567 | 565 | } |
| 568 | 566 | } |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | $link = @mysqli_connect($host, $login, $pass); |
| 59 | 59 | } |
| 60 | 60 | } catch (\mysqli_sql_exception $e) { |
| 61 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 61 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 62 | 62 | $link = false; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!$link) { |
| 66 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 66 | + spip_log('Echec mysqli_connect. Erreur : '.mysqli_connect_error(), 'mysql.'._LOG_HS); |
|
| 67 | 67 | |
| 68 | 68 | return false; |
| 69 | 69 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | spip_log( |
| 85 | - "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 85 | + "Connexion MySQLi vers $host, base $db, prefixe $prefixe ".($ok ? 'operationnelle' : 'impossible'), |
|
| 86 | 86 | _LOG_DEBUG |
| 87 | 87 | ); |
| 88 | 88 | |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 175 | 175 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 176 | - spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 176 | + spip_log('changement de charset sql : '.'SET NAMES '._q($charset), _LOG_DEBUG); |
|
| 177 | 177 | |
| 178 | - return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 178 | + return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES '._q($charset)); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | function spip_mysql_get_charset($charset = [], $serveur = '', $requeter = true) { |
| 191 | 191 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 192 | 192 | $connexion['last'] = $c = 'SHOW CHARACTER SET' |
| 193 | - . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 193 | + . (!$charset ? '' : (' LIKE '._q($charset['charset']))); |
|
| 194 | 194 | |
| 195 | 195 | return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
| 196 | 196 | } |
@@ -234,21 +234,21 @@ discard block |
||
| 234 | 234 | $debug = ''; |
| 235 | 235 | if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
| 236 | 236 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 237 | - [, $id, , $infos] = $GLOBALS['debug']['aucasou']; |
|
| 238 | - $debug .= "BOUCLE$id @ " . ($infos[0] ?? '') . ' | '; |
|
| 237 | + [, $id,, $infos] = $GLOBALS['debug']['aucasou']; |
|
| 238 | + $debug .= "BOUCLE$id @ ".($infos[0] ?? '').' | '; |
|
| 239 | 239 | } |
| 240 | 240 | if (isset($_SERVER['REQUEST_URI'])) { |
| 241 | 241 | $debug .= $_SERVER['REQUEST_URI']; |
| 242 | 242 | } |
| 243 | 243 | if (!empty($GLOBALS['ip'])) { |
| 244 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 244 | + $debug .= ' + '.$GLOBALS['ip']; |
|
| 245 | 245 | } |
| 246 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 246 | + $debug = ' /* '.mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)).' */'; |
|
| 247 | 247 | } |
| 248 | 248 | try { |
| 249 | - $r = mysqli_query($link, $query . $debug); |
|
| 249 | + $r = mysqli_query($link, $query.$debug); |
|
| 250 | 250 | } catch (\mysqli_sql_exception $e) { |
| 251 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 251 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 252 | 252 | $r = false; |
| 253 | 253 | // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
| 254 | 254 | // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | $link = $connexion['link']; |
| 267 | 267 | //On retente au cas où |
| 268 | 268 | try { |
| 269 | - $r = mysqli_query($link, $query . $debug); |
|
| 269 | + $r = mysqli_query($link, $query.$debug); |
|
| 270 | 270 | } catch (\mysqli_sql_exception $e) { |
| 271 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 271 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 272 | 272 | $r = false; |
| 273 | 273 | // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
| 274 | 274 | // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | // d'utiliser ceux-ci, copie-colle de phpmyadmin |
| 302 | 302 | $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
| 303 | 303 | |
| 304 | - return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 304 | + return spip_mysql_query('ALTER '.$query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @return bool Toujours true |
| 315 | 315 | */ |
| 316 | 316 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 317 | - spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 317 | + spip_mysql_query('OPTIMIZE TABLE '.$table); |
|
| 318 | 318 | |
| 319 | 319 | return true; |
| 320 | 320 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | $link = $connexion['link']; |
| 338 | 338 | $db = $connexion['db']; |
| 339 | 339 | |
| 340 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 340 | + $query = 'EXPLAIN '._mysql_traite_query($query, $db, $prefixe); |
|
| 341 | 341 | $r = mysqli_query($link, $query); |
| 342 | 342 | |
| 343 | 343 | return spip_mysql_fetch($r, null, $serveur); |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | . calculer_mysql_expression('WHERE', $where) |
| 389 | 389 | . calculer_mysql_expression('GROUP BY', $groupby, ',') |
| 390 | 390 | . calculer_mysql_expression('HAVING', $having) |
| 391 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 391 | + . ($orderby ? ("\nORDER BY ".spip_mysql_order($orderby)) : '') |
|
| 392 | 392 | . ($limit ? "\nLIMIT $limit" : ''); |
| 393 | 393 | |
| 394 | 394 | // renvoyer la requete inerte si demandee |
@@ -478,12 +478,12 @@ discard block |
||
| 478 | 478 | $exp = "\n$expression "; |
| 479 | 479 | |
| 480 | 480 | if (!is_array($v)) { |
| 481 | - return $exp . $v; |
|
| 481 | + return $exp.$v; |
|
| 482 | 482 | } else { |
| 483 | 483 | if (strtoupper($join) === 'AND') { |
| 484 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 484 | + return $exp.join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 485 | 485 | } else { |
| 486 | - return $exp . join($join, $v); |
|
| 486 | + return $exp.join($join, $v); |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | } |
@@ -501,17 +501,17 @@ discard block |
||
| 501 | 501 | if (substr($k, -1) == '@') { |
| 502 | 502 | // c'est une jointure qui se refere au from precedent |
| 503 | 503 | // pas de virgule |
| 504 | - $res .= ' ' . $v; |
|
| 504 | + $res .= ' '.$v; |
|
| 505 | 505 | } else { |
| 506 | 506 | if (!is_numeric($k)) { |
| 507 | 507 | $p = strpos($v, ' '); |
| 508 | 508 | if ($p) { |
| 509 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 509 | + $v = substr($v, 0, $p)." AS `$k`".substr($v, $p); |
|
| 510 | 510 | } else { |
| 511 | 511 | $v .= " AS `$k`"; |
| 512 | 512 | } |
| 513 | 513 | } |
| 514 | - $res .= ', ' . $v; |
|
| 514 | + $res .= ', '.$v; |
|
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | |
@@ -541,13 +541,13 @@ discard block |
||
| 541 | 541 | function _mysql_traite_query($query, $db = '', $prefixe = '', $echappe_textes = true) { |
| 542 | 542 | |
| 543 | 543 | if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
| 544 | - $pref = '`' . $db . '`.'; |
|
| 544 | + $pref = '`'.$db.'`.'; |
|
| 545 | 545 | } else { |
| 546 | 546 | $pref = ''; |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | if ($prefixe) { |
| 550 | - $pref .= $prefixe . '_'; |
|
| 550 | + $pref .= $prefixe.'_'; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | $suite_echap = $suite; |
| 567 | 567 | } |
| 568 | 568 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
| 569 | - $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 569 | + $suite_echap = $r[1]._mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 570 | 570 | if ($echappe_textes) { |
| 571 | 571 | $suite = query_reinjecte_textes($suite_echap, $textes); |
| 572 | 572 | } |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 579 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1'.$pref, $query).$suite; |
|
| 580 | 580 | |
| 581 | 581 | // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
| 582 | 582 | // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | $ok = false; |
| 617 | 617 | } |
| 618 | 618 | if (!$ok) { |
| 619 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 619 | + spip_log('Echec mysqli_selectdb. Erreur : '.mysqli_error($link), 'mysql.'._LOG_CRITIQUE); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | return $ok; |
@@ -706,10 +706,10 @@ discard block |
||
| 706 | 706 | |
| 707 | 707 | $character_set = ''; |
| 708 | 708 | if (@$GLOBALS['meta']['charset_sql_base']) { |
| 709 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 709 | + $character_set .= ' CHARACTER SET '.$GLOBALS['meta']['charset_sql_base']; |
|
| 710 | 710 | } |
| 711 | 711 | if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
| 712 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 712 | + $character_set .= ' COLLATE '.$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | foreach ($champs as $k => $v) { |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | preg_match(',(char|text),i', $defs[1]) |
| 720 | 720 | and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
| 721 | 721 | ) { |
| 722 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 722 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 723 | 723 | } |
| 724 | 724 | } |
| 725 | 725 | |
@@ -731,8 +731,8 @@ discard block |
||
| 731 | 731 | $s = ','; |
| 732 | 732 | } |
| 733 | 733 | $temporary = $temporary ? 'TEMPORARY' : ''; |
| 734 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 735 | - . (defined('_MYSQL_ENGINE') ? ' ENGINE=' . _MYSQL_ENGINE : '') |
|
| 734 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query".($keys ? ",$keys" : '').')' |
|
| 735 | + . (defined('_MYSQL_ENGINE') ? ' ENGINE='._MYSQL_ENGINE : '') |
|
| 736 | 736 | . ($character_set ? " DEFAULT $character_set" : '') |
| 737 | 737 | . "\n"; |
| 738 | 738 | |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | return false; |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 814 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 815 | 815 | |
| 816 | 816 | return spip_mysql_query($query, $serveur, $requeter); |
| 817 | 817 | } |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | * Ressource à utiliser avec sql_fetch() |
| 870 | 870 | **/ |
| 871 | 871 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 872 | - return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 872 | + return spip_mysql_query('SHOW TABLES LIKE '._q($match), $serveur, $requeter); |
|
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | /** |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | * - true si la requête a réussie, false sinon |
| 886 | 886 | */ |
| 887 | 887 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 888 | - $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = ' . _q($table), $serveur, true)); |
|
| 888 | + $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = '._q($table), $serveur, true)); |
|
| 889 | 889 | $engine = $table_status['Engine']; |
| 890 | 890 | if ($engine == 'InnoDB') { |
| 891 | 891 | if (spip_mysql_alter("TABLE $table ENGINE = InnoDB", $serveur, $requeter)) { |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | } elseif ($engine == 'MyISAM') { |
| 895 | 895 | return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
| 896 | 896 | } else { |
| 897 | - spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.' . _LOG_DEBUG); |
|
| 897 | + spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.'._LOG_DEBUG); |
|
| 898 | 898 | } |
| 899 | 899 | return false; |
| 900 | 900 | } |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | * - string : requete sql, si $requeter = true |
| 915 | 915 | **/ |
| 916 | 916 | function spip_mysql_table_exists(string $table, $serveur = '', $requeter = true) { |
| 917 | - $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 917 | + $r = spip_mysql_query('SHOW TABLES LIKE '._q($table), $serveur, $requeter); |
|
| 918 | 918 | if (!$requeter) { |
| 919 | 919 | return $r; |
| 920 | 920 | } |
@@ -996,22 +996,22 @@ discard block |
||
| 996 | 996 | } |
| 997 | 997 | if ($val['Default'] === '0' || $val['Default']) { |
| 998 | 998 | if (preg_match('/[A-Z_]/', $val['Default'])) { |
| 999 | - $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 999 | + $nfields[$val['Field']] .= ' DEFAULT '.$val['Default']; |
|
| 1000 | 1000 | } else { |
| 1001 | - $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 1001 | + $nfields[$val['Field']] .= " DEFAULT '".$val['Default']."'"; |
|
| 1002 | 1002 | } |
| 1003 | 1003 | } |
| 1004 | 1004 | if ($val['Extra']) { |
| 1005 | - $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 1005 | + $nfields[$val['Field']] .= ' '.$val['Extra']; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | if ($val['Key'] == 'PRI') { |
| 1008 | 1008 | $nkeys['PRIMARY KEY'] = $val['Field']; |
| 1009 | 1009 | } else { |
| 1010 | 1010 | if ($val['Key'] == 'MUL') { |
| 1011 | - $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 1011 | + $nkeys['KEY '.$val['Field']] = $val['Field']; |
|
| 1012 | 1012 | } else { |
| 1013 | 1013 | if ($val['Key'] == 'UNI') { |
| 1014 | - $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1014 | + $nkeys['UNIQUE KEY '.$val['Field']] = $val['Field']; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | } |
| 1017 | 1017 | } |
@@ -1087,7 +1087,7 @@ discard block |
||
| 1087 | 1087 | $serveur = '', |
| 1088 | 1088 | $requeter = true |
| 1089 | 1089 | ) { |
| 1090 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1090 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1091 | 1091 | |
| 1092 | 1092 | $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
| 1093 | 1093 | if (!$requeter) { |
@@ -1127,7 +1127,7 @@ discard block |
||
| 1127 | 1127 | if ($s) { |
| 1128 | 1128 | $trace = debug_backtrace(); |
| 1129 | 1129 | if ($trace[0]['function'] != 'spip_mysql_error') { |
| 1130 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1130 | + spip_log("$s - $query - ".sql_error_backtrace(), 'mysql.'._LOG_ERREUR); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | } |
| 1133 | 1133 | |
@@ -1257,7 +1257,7 @@ discard block |
||
| 1257 | 1257 | try { |
| 1258 | 1258 | $insert = mysqli_query($link, $query); |
| 1259 | 1259 | } catch (\mysqli_sql_exception $e) { |
| 1260 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1260 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 1261 | 1261 | // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
| 1262 | 1262 | // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
| 1263 | 1263 | } |
@@ -1312,8 +1312,8 @@ discard block |
||
| 1312 | 1312 | |
| 1313 | 1313 | return spip_mysql_insert( |
| 1314 | 1314 | $table, |
| 1315 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 1316 | - '(' . join(',', $couples) . ')', |
|
| 1315 | + '('.join(',', array_keys($couples)).')', |
|
| 1316 | + '('.join(',', $couples).')', |
|
| 1317 | 1317 | $desc, |
| 1318 | 1318 | $serveur, |
| 1319 | 1319 | $requeter |
@@ -1350,7 +1350,7 @@ discard block |
||
| 1350 | 1350 | } |
| 1351 | 1351 | $fields = $desc['field'] ?? []; |
| 1352 | 1352 | |
| 1353 | - $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1353 | + $cles = '('.join(',', array_keys(reset($tab_couples))).')'; |
|
| 1354 | 1354 | $valeurs = []; |
| 1355 | 1355 | $r = false; |
| 1356 | 1356 | |
@@ -1359,7 +1359,7 @@ discard block |
||
| 1359 | 1359 | foreach ($couples as $champ => $val) { |
| 1360 | 1360 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1361 | 1361 | } |
| 1362 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1362 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 1363 | 1363 | if (count($valeurs) >= 100) { |
| 1364 | 1364 | $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
| 1365 | 1365 | $valeurs = []; |
@@ -1396,7 +1396,7 @@ discard block |
||
| 1396 | 1396 | function spip_mysql_update($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1397 | 1397 | $set = []; |
| 1398 | 1398 | foreach ($champs as $champ => $val) { |
| 1399 | - $set[] = $champ . "=$val"; |
|
| 1399 | + $set[] = $champ."=$val"; |
|
| 1400 | 1400 | } |
| 1401 | 1401 | if (!empty($set)) { |
| 1402 | 1402 | return spip_mysql_query( |
@@ -1453,7 +1453,7 @@ discard block |
||
| 1453 | 1453 | } |
| 1454 | 1454 | $set = []; |
| 1455 | 1455 | foreach ($champs as $champ => $val) { |
| 1456 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1456 | + $set[] = $champ.'='.spip_mysql_cite($val, @$fields[$champ]); |
|
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | return spip_mysql_query( |
@@ -1522,10 +1522,10 @@ discard block |
||
| 1522 | 1522 | * - false en cas d'erreur. |
| 1523 | 1523 | **/ |
| 1524 | 1524 | function spip_mysql_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1525 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1525 | + return spip_mysql_query("REPLACE $table (".join(',', array_keys($couples)).') VALUES ('.join( |
|
| 1526 | 1526 | ',', |
| 1527 | 1527 | array_map('_q', $couples) |
| 1528 | - ) . ')', $serveur, $requeter); |
|
| 1528 | + ).')', $serveur, $requeter); |
|
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | |
@@ -1554,10 +1554,10 @@ discard block |
||
| 1554 | 1554 | * - false en cas d'erreur. |
| 1555 | 1555 | **/ |
| 1556 | 1556 | function spip_mysql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1557 | - $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1557 | + $cles = '('.join(',', array_keys($tab_couples[0])).')'; |
|
| 1558 | 1558 | $valeurs = []; |
| 1559 | 1559 | foreach ($tab_couples as $couples) { |
| 1560 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1560 | + $valeurs[] = '('.join(',', array_map('_q', $couples)).')'; |
|
| 1561 | 1561 | } |
| 1562 | 1562 | $valeurs = implode(', ', $valeurs); |
| 1563 | 1563 | |
@@ -1577,28 +1577,28 @@ discard block |
||
| 1577 | 1577 | */ |
| 1578 | 1578 | function spip_mysql_multi($objet, $lang) { |
| 1579 | 1579 | $lengthlang = strlen("[$lang]"); |
| 1580 | - $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1581 | - $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1582 | - $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1583 | - $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1584 | - $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1585 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1580 | + $posmulti = 'INSTR('.$objet.", '<multi>')"; |
|
| 1581 | + $posfinmulti = 'INSTR('.$objet.", '</multi>')"; |
|
| 1582 | + $debutchaine = 'LEFT('.$objet.", $posmulti-1)"; |
|
| 1583 | + $finchaine = 'RIGHT('.$objet.', CHAR_LENGTH('.$objet.") -(7+$posfinmulti))"; |
|
| 1584 | + $chainemulti = 'TRIM(SUBSTRING('.$objet.", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1585 | + $poslang = "INSTR($chainemulti,'[".$lang."]')"; |
|
| 1586 | 1586 | $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
| 1587 | - $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1588 | - $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1587 | + $chainelang = 'TRIM(SUBSTRING('.$objet.", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1588 | + $posfinlang = 'INSTR('.$chainelang.", '[')"; |
|
| 1589 | 1589 | $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
| 1590 | 1590 | //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
| 1591 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1592 | - ' TRIM(' . $objet . '), ' . |
|
| 1593 | - ' CONCAT( ' . |
|
| 1594 | - " $debutchaine, " . |
|
| 1595 | - ' IF( ' . |
|
| 1596 | - " $poslang = 0, " . |
|
| 1597 | - " $chainemulti, " . |
|
| 1598 | - " $chainelang" . |
|
| 1599 | - ' ), ' . |
|
| 1600 | - " $finchaine" . |
|
| 1601 | - ' ) ' . |
|
| 1591 | + $retour = "(TRIM(IF($posmulti = 0 , ". |
|
| 1592 | + ' TRIM('.$objet.'), '. |
|
| 1593 | + ' CONCAT( '. |
|
| 1594 | + " $debutchaine, ". |
|
| 1595 | + ' IF( '. |
|
| 1596 | + " $poslang = 0, ". |
|
| 1597 | + " $chainemulti, ". |
|
| 1598 | + " $chainelang". |
|
| 1599 | + ' ), '. |
|
| 1600 | + " $finchaine". |
|
| 1601 | + ' ) '. |
|
| 1602 | 1602 | '))) AS multi'; |
| 1603 | 1603 | |
| 1604 | 1604 | return $retour; |
@@ -1615,7 +1615,7 @@ discard block |
||
| 1615 | 1615 | * Valeur hexadécimale pour MySQL |
| 1616 | 1616 | **/ |
| 1617 | 1617 | function spip_mysql_hex($v) { |
| 1618 | - return '0x' . $v; |
|
| 1618 | + return '0x'.$v; |
|
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | /** |
@@ -1655,7 +1655,7 @@ discard block |
||
| 1655 | 1655 | * Expression SQL |
| 1656 | 1656 | **/ |
| 1657 | 1657 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1658 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1658 | + $use_now = (($champ === 'maj' or strpos($champ, '.maj')) ? true : false); |
|
| 1659 | 1659 | return '(' |
| 1660 | 1660 | . $champ |
| 1661 | 1661 | . (($interval <= 0) ? '>' : '<') |
@@ -1710,7 +1710,7 @@ discard block |
||
| 1710 | 1710 | } elseif ($v === null) { |
| 1711 | 1711 | return "''"; |
| 1712 | 1712 | } |
| 1713 | - return "'" . addslashes($v) . "'"; |
|
| 1713 | + return "'".addslashes($v)."'"; |
|
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | 1716 | if ($v === null) { |
@@ -1734,7 +1734,7 @@ discard block |
||
| 1734 | 1734 | } |
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | - return ("'" . addslashes($v) . "'"); |
|
| 1737 | + return ("'".addslashes($v)."'"); |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | 1740 | /** |
@@ -1768,7 +1768,7 @@ discard block |
||
| 1768 | 1768 | } else { |
| 1769 | 1769 | $GLOBALS['mysql_rappel_nom_base'] = false; |
| 1770 | 1770 | |
| 1771 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1771 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; ". |
|
| 1772 | 1772 | "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
| 1773 | 1773 | } |
| 1774 | 1774 | } |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (!defined('_MYSQL_NOPLANES')) { |
| 26 | - define('_MYSQL_NOPLANES', true); |
|
| 26 | + define('_MYSQL_NOPLANES', true); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -40,112 +40,112 @@ discard block |
||
| 40 | 40 | * - tableau décrivant la connexion sinon |
| 41 | 41 | */ |
| 42 | 42 | function req_mysql_dist($host, $port, $login, #[\SensitiveParameter] $pass, $db = '', $prefixe = '') { |
| 43 | - if (!extension_loaded(\mysqli::class)) { |
|
| 44 | - return false; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 48 | - try { |
|
| 49 | - if ( |
|
| 50 | - $port and !is_numeric($socket = $port) |
|
| 51 | - and (!$host or $host === 'localhost') |
|
| 52 | - ) { |
|
| 53 | - $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 54 | - } elseif ($port) { |
|
| 55 | - $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | - } else { |
|
| 57 | - $link = @mysqli_connect($host, $login, $pass); |
|
| 58 | - } |
|
| 59 | - } catch (\mysqli_sql_exception $e) { |
|
| 60 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 61 | - $link = false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (!$link) { |
|
| 65 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 66 | - |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 69 | - $last = ''; |
|
| 70 | - if (!$db) { |
|
| 71 | - $ok = $link; |
|
| 72 | - $db = 'spip'; |
|
| 73 | - } else { |
|
| 74 | - $ok = mysqli_select_db($link, $db); |
|
| 75 | - if ( |
|
| 76 | - defined('_MYSQL_SET_SQL_MODE') |
|
| 77 | - or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 78 | - ) { |
|
| 79 | - mysqli_query($link, $last = "set sql_mode=''"); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - spip_log( |
|
| 84 | - "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 85 | - _LOG_DEBUG |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - return !$ok ? false : [ |
|
| 89 | - 'db' => $db, |
|
| 90 | - 'last' => $last, |
|
| 91 | - 'prefixe' => $prefixe ?: $db, |
|
| 92 | - 'link' => $link, |
|
| 93 | - 'total_requetes' => 0, |
|
| 94 | - ]; |
|
| 43 | + if (!extension_loaded(\mysqli::class)) { |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 48 | + try { |
|
| 49 | + if ( |
|
| 50 | + $port and !is_numeric($socket = $port) |
|
| 51 | + and (!$host or $host === 'localhost') |
|
| 52 | + ) { |
|
| 53 | + $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 54 | + } elseif ($port) { |
|
| 55 | + $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | + } else { |
|
| 57 | + $link = @mysqli_connect($host, $login, $pass); |
|
| 58 | + } |
|
| 59 | + } catch (\mysqli_sql_exception $e) { |
|
| 60 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 61 | + $link = false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (!$link) { |
|
| 65 | + spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 66 | + |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | + $last = ''; |
|
| 70 | + if (!$db) { |
|
| 71 | + $ok = $link; |
|
| 72 | + $db = 'spip'; |
|
| 73 | + } else { |
|
| 74 | + $ok = mysqli_select_db($link, $db); |
|
| 75 | + if ( |
|
| 76 | + defined('_MYSQL_SET_SQL_MODE') |
|
| 77 | + or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 78 | + ) { |
|
| 79 | + mysqli_query($link, $last = "set sql_mode=''"); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + spip_log( |
|
| 84 | + "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 85 | + _LOG_DEBUG |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + return !$ok ? false : [ |
|
| 89 | + 'db' => $db, |
|
| 90 | + 'last' => $last, |
|
| 91 | + 'prefixe' => $prefixe ?: $db, |
|
| 92 | + 'link' => $link, |
|
| 93 | + 'total_requetes' => 0, |
|
| 94 | + ]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | $GLOBALS['spip_mysql_functions_1'] = [ |
| 99 | - 'alter' => 'spip_mysql_alter', |
|
| 100 | - 'count' => 'spip_mysql_count', |
|
| 101 | - 'countsel' => 'spip_mysql_countsel', |
|
| 102 | - 'create' => 'spip_mysql_create', |
|
| 103 | - 'create_base' => 'spip_mysql_create_base', |
|
| 104 | - 'create_view' => 'spip_mysql_create_view', |
|
| 105 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 106 | - 'delete' => 'spip_mysql_delete', |
|
| 107 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 108 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 109 | - 'errno' => 'spip_mysql_errno', |
|
| 110 | - 'error' => 'spip_mysql_error', |
|
| 111 | - 'explain' => 'spip_mysql_explain', |
|
| 112 | - 'fetch' => 'spip_mysql_fetch', |
|
| 113 | - 'seek' => 'spip_mysql_seek', |
|
| 114 | - 'free' => 'spip_mysql_free', |
|
| 115 | - 'hex' => 'spip_mysql_hex', |
|
| 116 | - 'in' => 'spip_mysql_in', |
|
| 117 | - 'insert' => 'spip_mysql_insert', |
|
| 118 | - 'insertq' => 'spip_mysql_insertq', |
|
| 119 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 120 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 121 | - 'multi' => 'spip_mysql_multi', |
|
| 122 | - 'optimize' => 'spip_mysql_optimize', |
|
| 123 | - 'query' => 'spip_mysql_query', |
|
| 124 | - 'quote' => 'spip_mysql_quote', |
|
| 125 | - 'replace' => 'spip_mysql_replace', |
|
| 126 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 127 | - 'repair' => 'spip_mysql_repair', |
|
| 128 | - 'select' => 'spip_mysql_select', |
|
| 129 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 130 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 131 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 132 | - 'showbase' => 'spip_mysql_showbase', |
|
| 133 | - 'showtable' => 'spip_mysql_showtable', |
|
| 134 | - 'table_exists' => 'spip_mysql_table_exists', |
|
| 135 | - 'update' => 'spip_mysql_update', |
|
| 136 | - 'updateq' => 'spip_mysql_updateq', |
|
| 137 | - |
|
| 138 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 139 | - 'charsets' => [ |
|
| 140 | - 'cp1250' => ['charset' => 'cp1250', 'collation' => 'cp1250_general_ci'], |
|
| 141 | - 'cp1251' => ['charset' => 'cp1251', 'collation' => 'cp1251_general_ci'], |
|
| 142 | - 'cp1256' => ['charset' => 'cp1256', 'collation' => 'cp1256_general_ci'], |
|
| 143 | - 'iso-8859-1' => ['charset' => 'latin1', 'collation' => 'latin1_swedish_ci'], |
|
| 99 | + 'alter' => 'spip_mysql_alter', |
|
| 100 | + 'count' => 'spip_mysql_count', |
|
| 101 | + 'countsel' => 'spip_mysql_countsel', |
|
| 102 | + 'create' => 'spip_mysql_create', |
|
| 103 | + 'create_base' => 'spip_mysql_create_base', |
|
| 104 | + 'create_view' => 'spip_mysql_create_view', |
|
| 105 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 106 | + 'delete' => 'spip_mysql_delete', |
|
| 107 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 108 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 109 | + 'errno' => 'spip_mysql_errno', |
|
| 110 | + 'error' => 'spip_mysql_error', |
|
| 111 | + 'explain' => 'spip_mysql_explain', |
|
| 112 | + 'fetch' => 'spip_mysql_fetch', |
|
| 113 | + 'seek' => 'spip_mysql_seek', |
|
| 114 | + 'free' => 'spip_mysql_free', |
|
| 115 | + 'hex' => 'spip_mysql_hex', |
|
| 116 | + 'in' => 'spip_mysql_in', |
|
| 117 | + 'insert' => 'spip_mysql_insert', |
|
| 118 | + 'insertq' => 'spip_mysql_insertq', |
|
| 119 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 120 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 121 | + 'multi' => 'spip_mysql_multi', |
|
| 122 | + 'optimize' => 'spip_mysql_optimize', |
|
| 123 | + 'query' => 'spip_mysql_query', |
|
| 124 | + 'quote' => 'spip_mysql_quote', |
|
| 125 | + 'replace' => 'spip_mysql_replace', |
|
| 126 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 127 | + 'repair' => 'spip_mysql_repair', |
|
| 128 | + 'select' => 'spip_mysql_select', |
|
| 129 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 130 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 131 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 132 | + 'showbase' => 'spip_mysql_showbase', |
|
| 133 | + 'showtable' => 'spip_mysql_showtable', |
|
| 134 | + 'table_exists' => 'spip_mysql_table_exists', |
|
| 135 | + 'update' => 'spip_mysql_update', |
|
| 136 | + 'updateq' => 'spip_mysql_updateq', |
|
| 137 | + |
|
| 138 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 139 | + 'charsets' => [ |
|
| 140 | + 'cp1250' => ['charset' => 'cp1250', 'collation' => 'cp1250_general_ci'], |
|
| 141 | + 'cp1251' => ['charset' => 'cp1251', 'collation' => 'cp1251_general_ci'], |
|
| 142 | + 'cp1256' => ['charset' => 'cp1256', 'collation' => 'cp1256_general_ci'], |
|
| 143 | + 'iso-8859-1' => ['charset' => 'latin1', 'collation' => 'latin1_swedish_ci'], |
|
| 144 | 144 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 145 | - 'iso-8859-9' => ['charset' => 'latin5', 'collation' => 'latin5_turkish_ci'], |
|
| 145 | + 'iso-8859-9' => ['charset' => 'latin5', 'collation' => 'latin5_turkish_ci'], |
|
| 146 | 146 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 147 | - 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'] |
|
| 148 | - ] |
|
| 147 | + 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'] |
|
| 148 | + ] |
|
| 149 | 149 | ]; |
| 150 | 150 | |
| 151 | 151 | |
@@ -156,9 +156,9 @@ discard block |
||
| 156 | 156 | * @return Object Information de connexion pour mysqli |
| 157 | 157 | */ |
| 158 | 158 | function _mysql_link($serveur = '') { |
| 159 | - $link = &$GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 159 | + $link = &$GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 160 | 160 | |
| 161 | - return $link; |
|
| 161 | + return $link; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | * @return mysqli_result|bool Jeu de résultats pour fetch() |
| 172 | 172 | */ |
| 173 | 173 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 174 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 175 | - spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 174 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 175 | + spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 176 | 176 | |
| 177 | - return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 177 | + return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | * @return array Description du charset (son nom est dans 'charset') |
| 188 | 188 | */ |
| 189 | 189 | function spip_mysql_get_charset($charset = [], $serveur = '', $requeter = true) { |
| 190 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 191 | - $connexion['last'] = $c = 'SHOW CHARACTER SET' |
|
| 192 | - . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 190 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 191 | + $connexion['last'] = $c = 'SHOW CHARACTER SET' |
|
| 192 | + . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 193 | 193 | |
| 194 | - return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 194 | + return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -207,80 +207,80 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | function spip_mysql_query($query, $serveur = '', $requeter = true) { |
| 209 | 209 | |
| 210 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 211 | - $prefixe = $connexion['prefixe']; |
|
| 212 | - $link = $connexion['link']; |
|
| 213 | - $db = $connexion['db']; |
|
| 214 | - |
|
| 215 | - $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 216 | - |
|
| 217 | - // renvoyer la requete inerte si demandee |
|
| 218 | - if (!$requeter) { |
|
| 219 | - return $query; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (isset($_GET['var_profile']) or (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES)) { |
|
| 223 | - include_spip('public/tracer'); |
|
| 224 | - $t = trace_query_start(); |
|
| 225 | - } else { |
|
| 226 | - $t = 0; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $connexion['last'] = $query; |
|
| 230 | - $connexion['total_requetes']++; |
|
| 231 | - |
|
| 232 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 233 | - $debug = ''; |
|
| 234 | - if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 235 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 236 | - [, $id, , $infos] = $GLOBALS['debug']['aucasou']; |
|
| 237 | - $debug .= "BOUCLE$id @ " . ($infos[0] ?? '') . ' | '; |
|
| 238 | - } |
|
| 239 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 240 | - $debug .= $_SERVER['REQUEST_URI']; |
|
| 241 | - } |
|
| 242 | - if (!empty($GLOBALS['ip'])) { |
|
| 243 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 244 | - } |
|
| 245 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 246 | - } |
|
| 247 | - try { |
|
| 248 | - $r = mysqli_query($link, $query . $debug); |
|
| 249 | - } catch (\mysqli_sql_exception $e) { |
|
| 250 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 251 | - $r = false; |
|
| 252 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 253 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 257 | - if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 258 | - if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 259 | - //Fermer la connexion defaillante |
|
| 260 | - mysqli_close($connexion['link']); |
|
| 261 | - unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 262 | - //Relancer une connexion vierge |
|
| 263 | - spip_connect($serveur); |
|
| 264 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 265 | - $link = $connexion['link']; |
|
| 266 | - //On retente au cas où |
|
| 267 | - try { |
|
| 268 | - $r = mysqli_query($link, $query . $debug); |
|
| 269 | - } catch (\mysqli_sql_exception $e) { |
|
| 270 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 271 | - $r = false; |
|
| 272 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 273 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // Log de l'erreur eventuelle |
|
| 279 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 280 | - // et du fautif |
|
| 281 | - $e .= spip_mysql_error($query, $serveur); |
|
| 282 | - } |
|
| 283 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 210 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 211 | + $prefixe = $connexion['prefixe']; |
|
| 212 | + $link = $connexion['link']; |
|
| 213 | + $db = $connexion['db']; |
|
| 214 | + |
|
| 215 | + $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 216 | + |
|
| 217 | + // renvoyer la requete inerte si demandee |
|
| 218 | + if (!$requeter) { |
|
| 219 | + return $query; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (isset($_GET['var_profile']) or (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES)) { |
|
| 223 | + include_spip('public/tracer'); |
|
| 224 | + $t = trace_query_start(); |
|
| 225 | + } else { |
|
| 226 | + $t = 0; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $connexion['last'] = $query; |
|
| 230 | + $connexion['total_requetes']++; |
|
| 231 | + |
|
| 232 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 233 | + $debug = ''; |
|
| 234 | + if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 235 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 236 | + [, $id, , $infos] = $GLOBALS['debug']['aucasou']; |
|
| 237 | + $debug .= "BOUCLE$id @ " . ($infos[0] ?? '') . ' | '; |
|
| 238 | + } |
|
| 239 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 240 | + $debug .= $_SERVER['REQUEST_URI']; |
|
| 241 | + } |
|
| 242 | + if (!empty($GLOBALS['ip'])) { |
|
| 243 | + $debug .= ' + ' . $GLOBALS['ip']; |
|
| 244 | + } |
|
| 245 | + $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 246 | + } |
|
| 247 | + try { |
|
| 248 | + $r = mysqli_query($link, $query . $debug); |
|
| 249 | + } catch (\mysqli_sql_exception $e) { |
|
| 250 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 251 | + $r = false; |
|
| 252 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 253 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 257 | + if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 258 | + if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 259 | + //Fermer la connexion defaillante |
|
| 260 | + mysqli_close($connexion['link']); |
|
| 261 | + unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 262 | + //Relancer une connexion vierge |
|
| 263 | + spip_connect($serveur); |
|
| 264 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 265 | + $link = $connexion['link']; |
|
| 266 | + //On retente au cas où |
|
| 267 | + try { |
|
| 268 | + $r = mysqli_query($link, $query . $debug); |
|
| 269 | + } catch (\mysqli_sql_exception $e) { |
|
| 270 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 271 | + $r = false; |
|
| 272 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 273 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // Log de l'erreur eventuelle |
|
| 279 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 280 | + // et du fautif |
|
| 281 | + $e .= spip_mysql_error($query, $serveur); |
|
| 282 | + } |
|
| 283 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -295,12 +295,12 @@ discard block |
||
| 295 | 295 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 296 | 296 | */ |
| 297 | 297 | function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
| 298 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 299 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 300 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 301 | - $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
|
| 298 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 299 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 300 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 301 | + $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
|
| 302 | 302 | |
| 303 | - return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 303 | + return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | * @return bool Toujours true |
| 314 | 314 | */ |
| 315 | 315 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 316 | - spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 316 | + spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 317 | 317 | |
| 318 | - return true; |
|
| 318 | + return true; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | |
@@ -328,18 +328,18 @@ discard block |
||
| 328 | 328 | * @return array Tableau de l'explication |
| 329 | 329 | */ |
| 330 | 330 | function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
| 331 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 332 | - return []; |
|
| 333 | - } |
|
| 334 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 335 | - $prefixe = $connexion['prefixe']; |
|
| 336 | - $link = $connexion['link']; |
|
| 337 | - $db = $connexion['db']; |
|
| 338 | - |
|
| 339 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 340 | - $r = mysqli_query($link, $query); |
|
| 341 | - |
|
| 342 | - return spip_mysql_fetch($r, null, $serveur); |
|
| 331 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 332 | + return []; |
|
| 333 | + } |
|
| 334 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 335 | + $prefixe = $connexion['prefixe']; |
|
| 336 | + $link = $connexion['link']; |
|
| 337 | + $db = $connexion['db']; |
|
| 338 | + |
|
| 339 | + $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 340 | + $r = mysqli_query($link, $query); |
|
| 341 | + |
|
| 342 | + return spip_mysql_fetch($r, null, $serveur); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -368,35 +368,35 @@ discard block |
||
| 368 | 368 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 369 | 369 | */ |
| 370 | 370 | function spip_mysql_select( |
| 371 | - $select, |
|
| 372 | - $from, |
|
| 373 | - $where = '', |
|
| 374 | - $groupby = '', |
|
| 375 | - $orderby = '', |
|
| 376 | - $limit = '', |
|
| 377 | - $having = '', |
|
| 378 | - $serveur = '', |
|
| 379 | - $requeter = true |
|
| 371 | + $select, |
|
| 372 | + $from, |
|
| 373 | + $where = '', |
|
| 374 | + $groupby = '', |
|
| 375 | + $orderby = '', |
|
| 376 | + $limit = '', |
|
| 377 | + $having = '', |
|
| 378 | + $serveur = '', |
|
| 379 | + $requeter = true |
|
| 380 | 380 | ) { |
| 381 | 381 | |
| 382 | 382 | |
| 383 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 384 | - $query = |
|
| 385 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 386 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 387 | - . calculer_mysql_expression('WHERE', $where) |
|
| 388 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 389 | - . calculer_mysql_expression('HAVING', $having) |
|
| 390 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 391 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 383 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 384 | + $query = |
|
| 385 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 386 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 387 | + . calculer_mysql_expression('WHERE', $where) |
|
| 388 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 389 | + . calculer_mysql_expression('HAVING', $having) |
|
| 390 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 391 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 392 | 392 | |
| 393 | - // renvoyer la requete inerte si demandee |
|
| 394 | - if ($requeter === false) { |
|
| 395 | - return $query; |
|
| 396 | - } |
|
| 397 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 393 | + // renvoyer la requete inerte si demandee |
|
| 394 | + if ($requeter === false) { |
|
| 395 | + return $query; |
|
| 396 | + } |
|
| 397 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 398 | 398 | |
| 399 | - return $r ?: $query; |
|
| 399 | + return $r ?: $query; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | * @return string texte du orderby préparé |
| 414 | 414 | */ |
| 415 | 415 | function spip_mysql_order($orderby) { |
| 416 | - return (is_array($orderby)) ? join(', ', $orderby) : $orderby; |
|
| 416 | + return (is_array($orderby)) ? join(', ', $orderby) : $orderby; |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | |
@@ -436,26 +436,26 @@ discard block |
||
| 436 | 436 | * Contrainte pour clause WHERE |
| 437 | 437 | */ |
| 438 | 438 | function calculer_mysql_where($v) { |
| 439 | - if (!is_array($v)) { |
|
| 440 | - return $v; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - $op = array_shift($v); |
|
| 444 | - if (!($n = count($v))) { |
|
| 445 | - return $op; |
|
| 446 | - } else { |
|
| 447 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 448 | - if ($n == 1) { |
|
| 449 | - return "$op($arg)"; |
|
| 450 | - } else { |
|
| 451 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 452 | - if ($n == 2) { |
|
| 453 | - return "($arg $op $arg2)"; |
|
| 454 | - } else { |
|
| 455 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - } |
|
| 439 | + if (!is_array($v)) { |
|
| 440 | + return $v; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + $op = array_shift($v); |
|
| 444 | + if (!($n = count($v))) { |
|
| 445 | + return $op; |
|
| 446 | + } else { |
|
| 447 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 448 | + if ($n == 1) { |
|
| 449 | + return "$op($arg)"; |
|
| 450 | + } else { |
|
| 451 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 452 | + if ($n == 2) { |
|
| 453 | + return "($arg $op $arg2)"; |
|
| 454 | + } else { |
|
| 455 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -470,21 +470,21 @@ discard block |
||
| 470 | 470 | * @return string texte de l'expression, une partie donc, du texte la requête. |
| 471 | 471 | */ |
| 472 | 472 | function calculer_mysql_expression($expression, $v, $join = 'AND') { |
| 473 | - if (empty($v)) { |
|
| 474 | - return ''; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - $exp = "\n$expression "; |
|
| 478 | - |
|
| 479 | - if (!is_array($v)) { |
|
| 480 | - return $exp . $v; |
|
| 481 | - } else { |
|
| 482 | - if (strtoupper($join) === 'AND') { |
|
| 483 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 484 | - } else { |
|
| 485 | - return $exp . join($join, $v); |
|
| 486 | - } |
|
| 487 | - } |
|
| 473 | + if (empty($v)) { |
|
| 474 | + return ''; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + $exp = "\n$expression "; |
|
| 478 | + |
|
| 479 | + if (!is_array($v)) { |
|
| 480 | + return $exp . $v; |
|
| 481 | + } else { |
|
| 482 | + if (strtoupper($join) === 'AND') { |
|
| 483 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 484 | + } else { |
|
| 485 | + return $exp . join($join, $v); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
@@ -495,26 +495,26 @@ discard block |
||
| 495 | 495 | * @return string Sélection de colonnes pour une clause SELECT |
| 496 | 496 | */ |
| 497 | 497 | function spip_mysql_select_as($args) { |
| 498 | - $res = ''; |
|
| 499 | - foreach ($args as $k => $v) { |
|
| 500 | - if (substr($k, -1) == '@') { |
|
| 501 | - // c'est une jointure qui se refere au from precedent |
|
| 502 | - // pas de virgule |
|
| 503 | - $res .= ' ' . $v; |
|
| 504 | - } else { |
|
| 505 | - if (!is_numeric($k)) { |
|
| 506 | - $p = strpos($v, ' '); |
|
| 507 | - if ($p) { |
|
| 508 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 509 | - } else { |
|
| 510 | - $v .= " AS `$k`"; |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - $res .= ', ' . $v; |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - return substr($res, 2); |
|
| 498 | + $res = ''; |
|
| 499 | + foreach ($args as $k => $v) { |
|
| 500 | + if (substr($k, -1) == '@') { |
|
| 501 | + // c'est une jointure qui se refere au from precedent |
|
| 502 | + // pas de virgule |
|
| 503 | + $res .= ' ' . $v; |
|
| 504 | + } else { |
|
| 505 | + if (!is_numeric($k)) { |
|
| 506 | + $p = strpos($v, ' '); |
|
| 507 | + if ($p) { |
|
| 508 | + $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 509 | + } else { |
|
| 510 | + $v .= " AS `$k`"; |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + $res .= ', ' . $v; |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + return substr($res, 2); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | |
@@ -539,58 +539,58 @@ discard block |
||
| 539 | 539 | */ |
| 540 | 540 | function _mysql_traite_query($query, $db = '', $prefixe = '', $echappe_textes = true) { |
| 541 | 541 | |
| 542 | - if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 543 | - $pref = '`' . $db . '`.'; |
|
| 544 | - } else { |
|
| 545 | - $pref = ''; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if ($prefixe) { |
|
| 549 | - $pref .= $prefixe . '_'; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 553 | - $suite = ''; |
|
| 554 | - } else { |
|
| 555 | - $suite = strstr($query, (string) $regs[0]); |
|
| 556 | - $query = substr($query, 0, -strlen($suite)); |
|
| 557 | - // propager le prefixe en cas de requete imbriquee |
|
| 558 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 559 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 560 | - if (stripos($suite, 'SELECT') !== false) { |
|
| 561 | - if ($echappe_textes) { |
|
| 562 | - [$suite_echap, $textes] = query_echappe_textes($suite); |
|
| 563 | - } |
|
| 564 | - else { |
|
| 565 | - $suite_echap = $suite; |
|
| 566 | - } |
|
| 567 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
|
| 568 | - $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 569 | - if ($echappe_textes) { |
|
| 570 | - $suite = query_reinjecte_textes($suite_echap, $textes); |
|
| 571 | - } |
|
| 572 | - else { |
|
| 573 | - $suite = $suite_echap; |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 579 | - |
|
| 580 | - // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 581 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 582 | - if ( |
|
| 583 | - defined('_MYSQL_NOPLANES') |
|
| 584 | - and _MYSQL_NOPLANES |
|
| 585 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 586 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 587 | - ) { |
|
| 588 | - include_spip('inc/charsets'); |
|
| 589 | - $r = utf8_noplanes($r); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 593 | - return $r; |
|
| 542 | + if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 543 | + $pref = '`' . $db . '`.'; |
|
| 544 | + } else { |
|
| 545 | + $pref = ''; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + if ($prefixe) { |
|
| 549 | + $pref .= $prefixe . '_'; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 553 | + $suite = ''; |
|
| 554 | + } else { |
|
| 555 | + $suite = strstr($query, (string) $regs[0]); |
|
| 556 | + $query = substr($query, 0, -strlen($suite)); |
|
| 557 | + // propager le prefixe en cas de requete imbriquee |
|
| 558 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 559 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 560 | + if (stripos($suite, 'SELECT') !== false) { |
|
| 561 | + if ($echappe_textes) { |
|
| 562 | + [$suite_echap, $textes] = query_echappe_textes($suite); |
|
| 563 | + } |
|
| 564 | + else { |
|
| 565 | + $suite_echap = $suite; |
|
| 566 | + } |
|
| 567 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
|
| 568 | + $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 569 | + if ($echappe_textes) { |
|
| 570 | + $suite = query_reinjecte_textes($suite_echap, $textes); |
|
| 571 | + } |
|
| 572 | + else { |
|
| 573 | + $suite = $suite_echap; |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 579 | + |
|
| 580 | + // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 581 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 582 | + if ( |
|
| 583 | + defined('_MYSQL_NOPLANES') |
|
| 584 | + and _MYSQL_NOPLANES |
|
| 585 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 586 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 587 | + ) { |
|
| 588 | + include_spip('inc/charsets'); |
|
| 589 | + $r = utf8_noplanes($r); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 593 | + return $r; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -608,17 +608,17 @@ discard block |
||
| 608 | 608 | * - False en cas d'erreur. |
| 609 | 609 | **/ |
| 610 | 610 | function spip_mysql_selectdb($db, $serveur = '', $requeter = true) { |
| 611 | - $link = _mysql_link($serveur); |
|
| 612 | - try { |
|
| 613 | - $ok = mysqli_select_db($link, $db); |
|
| 614 | - } catch (\mysqli_sql_exception $e) { |
|
| 615 | - $ok = false; |
|
| 616 | - } |
|
| 617 | - if (!$ok) { |
|
| 618 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - return $ok; |
|
| 611 | + $link = _mysql_link($serveur); |
|
| 612 | + try { |
|
| 613 | + $ok = mysqli_select_db($link, $db); |
|
| 614 | + } catch (\mysqli_sql_exception $e) { |
|
| 615 | + $ok = false; |
|
| 616 | + } |
|
| 617 | + if (!$ok) { |
|
| 618 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + return $ok; |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | |
@@ -639,14 +639,14 @@ discard block |
||
| 639 | 639 | * Liste de noms de bases de données |
| 640 | 640 | **/ |
| 641 | 641 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 642 | - $dbs = []; |
|
| 643 | - if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 644 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 645 | - $dbs[] = $row['Database']; |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - return $dbs; |
|
| 642 | + $dbs = []; |
|
| 643 | + if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 644 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 645 | + $dbs[] = $row['Database']; |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + return $dbs; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | |
@@ -669,73 +669,73 @@ discard block |
||
| 669 | 669 | * - true si la requête réussie, false sinon. |
| 670 | 670 | */ |
| 671 | 671 | function spip_mysql_create( |
| 672 | - $nom, |
|
| 673 | - $champs, |
|
| 674 | - $cles, |
|
| 675 | - $autoinc = false, |
|
| 676 | - $temporary = false, |
|
| 677 | - $serveur = '', |
|
| 678 | - $requeter = true |
|
| 672 | + $nom, |
|
| 673 | + $champs, |
|
| 674 | + $cles, |
|
| 675 | + $autoinc = false, |
|
| 676 | + $temporary = false, |
|
| 677 | + $serveur = '', |
|
| 678 | + $requeter = true |
|
| 679 | 679 | ) { |
| 680 | 680 | |
| 681 | - $query = ''; |
|
| 682 | - $keys = ''; |
|
| 683 | - $s = ''; |
|
| 684 | - $p = ''; |
|
| 685 | - |
|
| 686 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 687 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 688 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 689 | - return; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 693 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 694 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - foreach ($cles as $k => $v) { |
|
| 698 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 699 | - if ($k == 'PRIMARY KEY') { |
|
| 700 | - $p = $v; |
|
| 701 | - } |
|
| 702 | - $s = ','; |
|
| 703 | - } |
|
| 704 | - $s = ''; |
|
| 705 | - |
|
| 706 | - $character_set = ''; |
|
| 707 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 708 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 709 | - } |
|
| 710 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 711 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - foreach ($champs as $k => $v) { |
|
| 715 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 716 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 717 | - if ( |
|
| 718 | - preg_match(',(char|text),i', $defs[1]) |
|
| 719 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 720 | - ) { |
|
| 721 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - $query .= "$s\n\t\t$k $v" |
|
| 726 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 727 | - ? ' auto_increment' |
|
| 728 | - : '' |
|
| 729 | - ); |
|
| 730 | - $s = ','; |
|
| 731 | - } |
|
| 732 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 733 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 734 | - . (defined('_MYSQL_ENGINE') ? ' ENGINE=' . _MYSQL_ENGINE : '') |
|
| 735 | - . ($character_set ? " DEFAULT $character_set" : '') |
|
| 736 | - . "\n"; |
|
| 737 | - |
|
| 738 | - return spip_mysql_query($q, $serveur); |
|
| 681 | + $query = ''; |
|
| 682 | + $keys = ''; |
|
| 683 | + $s = ''; |
|
| 684 | + $p = ''; |
|
| 685 | + |
|
| 686 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 687 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 688 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 689 | + return; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 693 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 694 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + foreach ($cles as $k => $v) { |
|
| 698 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 699 | + if ($k == 'PRIMARY KEY') { |
|
| 700 | + $p = $v; |
|
| 701 | + } |
|
| 702 | + $s = ','; |
|
| 703 | + } |
|
| 704 | + $s = ''; |
|
| 705 | + |
|
| 706 | + $character_set = ''; |
|
| 707 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 708 | + $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 709 | + } |
|
| 710 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 711 | + $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + foreach ($champs as $k => $v) { |
|
| 715 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 716 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 717 | + if ( |
|
| 718 | + preg_match(',(char|text),i', $defs[1]) |
|
| 719 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 720 | + ) { |
|
| 721 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + $query .= "$s\n\t\t$k $v" |
|
| 726 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 727 | + ? ' auto_increment' |
|
| 728 | + : '' |
|
| 729 | + ); |
|
| 730 | + $s = ','; |
|
| 731 | + } |
|
| 732 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 733 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 734 | + . (defined('_MYSQL_ENGINE') ? ' ENGINE=' . _MYSQL_ENGINE : '') |
|
| 735 | + . ($character_set ? " DEFAULT $character_set" : '') |
|
| 736 | + . "\n"; |
|
| 737 | + |
|
| 738 | + return spip_mysql_query($q, $serveur); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | |
@@ -748,25 +748,25 @@ discard block |
||
| 748 | 748 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 749 | 749 | */ |
| 750 | 750 | function _mysql_remplacements_definitions_table($query) { |
| 751 | - // quelques remplacements |
|
| 752 | - $num = '(\s*\([0-9]*\))?'; |
|
| 753 | - $enum = '(\s*\([^\)]*\))?'; |
|
| 754 | - |
|
| 755 | - $remplace = [ |
|
| 756 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 757 | - '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 758 | - ]; |
|
| 759 | - |
|
| 760 | - if (is_string($query)) { |
|
| 761 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 762 | - } elseif (is_array($query)) { |
|
| 763 | - $keys = array_keys($remplace); |
|
| 764 | - foreach ($query as $k => $q) { |
|
| 765 | - $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - return $query; |
|
| 751 | + // quelques remplacements |
|
| 752 | + $num = '(\s*\([0-9]*\))?'; |
|
| 753 | + $enum = '(\s*\([^\)]*\))?'; |
|
| 754 | + |
|
| 755 | + $remplace = [ |
|
| 756 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 757 | + '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 758 | + ]; |
|
| 759 | + |
|
| 760 | + if (is_string($query)) { |
|
| 761 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 762 | + } elseif (is_array($query)) { |
|
| 763 | + $keys = array_keys($remplace); |
|
| 764 | + foreach ($query as $k => $q) { |
|
| 765 | + $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + return $query; |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | * @return bool true si la base est créee. |
| 780 | 780 | **/ |
| 781 | 781 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 782 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 782 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | |
@@ -800,19 +800,19 @@ discard block |
||
| 800 | 800 | * - string texte de la requête si $requeter vaut false |
| 801 | 801 | */ |
| 802 | 802 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 803 | - if (!$query_select) { |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - // vue deja presente |
|
| 807 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 808 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 803 | + if (!$query_select) { |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + // vue deja presente |
|
| 807 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 808 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 809 | 809 | |
| 810 | - return false; |
|
| 811 | - } |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | 812 | |
| 813 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 813 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 814 | 814 | |
| 815 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 815 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | |
@@ -828,11 +828,11 @@ discard block |
||
| 828 | 828 | * - true si la requête a réussie, false sinon |
| 829 | 829 | */ |
| 830 | 830 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 831 | - if ($exist) { |
|
| 832 | - $exist = ' IF EXISTS'; |
|
| 833 | - } |
|
| 831 | + if ($exist) { |
|
| 832 | + $exist = ' IF EXISTS'; |
|
| 833 | + } |
|
| 834 | 834 | |
| 835 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 835 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | /** |
@@ -847,11 +847,11 @@ discard block |
||
| 847 | 847 | * - true si la requête a réussie, false sinon |
| 848 | 848 | */ |
| 849 | 849 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 850 | - if ($exist) { |
|
| 851 | - $exist = ' IF EXISTS'; |
|
| 852 | - } |
|
| 850 | + if ($exist) { |
|
| 851 | + $exist = ' IF EXISTS'; |
|
| 852 | + } |
|
| 853 | 853 | |
| 854 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 854 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | * Ressource à utiliser avec sql_fetch() |
| 869 | 869 | **/ |
| 870 | 870 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 871 | - return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 871 | + return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | /** |
@@ -884,18 +884,18 @@ discard block |
||
| 884 | 884 | * - true si la requête a réussie, false sinon |
| 885 | 885 | */ |
| 886 | 886 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 887 | - $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = ' . _q($table), $serveur, true)); |
|
| 888 | - $engine = $table_status['Engine']; |
|
| 889 | - if ($engine == 'InnoDB') { |
|
| 890 | - if (spip_mysql_alter("TABLE $table ENGINE = InnoDB", $serveur, $requeter)) { |
|
| 891 | - return [' OK ']; |
|
| 892 | - } |
|
| 893 | - } elseif ($engine == 'MyISAM') { |
|
| 894 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 895 | - } else { |
|
| 896 | - spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.' . _LOG_DEBUG); |
|
| 897 | - } |
|
| 898 | - return false; |
|
| 887 | + $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = ' . _q($table), $serveur, true)); |
|
| 888 | + $engine = $table_status['Engine']; |
|
| 889 | + if ($engine == 'InnoDB') { |
|
| 890 | + if (spip_mysql_alter("TABLE $table ENGINE = InnoDB", $serveur, $requeter)) { |
|
| 891 | + return [' OK ']; |
|
| 892 | + } |
|
| 893 | + } elseif ($engine == 'MyISAM') { |
|
| 894 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 895 | + } else { |
|
| 896 | + spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.' . _LOG_DEBUG); |
|
| 897 | + } |
|
| 898 | + return false; |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | /** |
@@ -913,12 +913,12 @@ discard block |
||
| 913 | 913 | * - string : requete sql, si $requeter = true |
| 914 | 914 | **/ |
| 915 | 915 | function spip_mysql_table_exists(string $table, $serveur = '', $requeter = true) { |
| 916 | - $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 917 | - if (!$requeter) { |
|
| 918 | - return $r; |
|
| 919 | - } |
|
| 920 | - $res = spip_mysql_fetch($r); |
|
| 921 | - return (bool) $res; |
|
| 916 | + $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 917 | + if (!$requeter) { |
|
| 918 | + return $r; |
|
| 919 | + } |
|
| 920 | + $res = spip_mysql_fetch($r); |
|
| 921 | + return (bool) $res; |
|
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | define('_MYSQL_RE_SHOW_TABLE', '/^[^(),]*\(((?:[^()]*\((?:[^()]*\([^()]*\))?[^()]*\)[^()]*)*[^()]*)\)[^()]*$/'); |
@@ -941,86 +941,86 @@ discard block |
||
| 941 | 941 | * - array description de la table sinon |
| 942 | 942 | */ |
| 943 | 943 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 944 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 945 | - if (!$s) { |
|
| 946 | - return ''; |
|
| 947 | - } |
|
| 948 | - if (!$requeter) { |
|
| 949 | - return $s; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - [, $a] = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 953 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 954 | - $desc = $r[1]; |
|
| 955 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 956 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 957 | - if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 958 | - $namedkeys = $r[2]; |
|
| 959 | - $desc = $r[1]; |
|
| 960 | - } else { |
|
| 961 | - $namedkeys = ''; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - $fields = []; |
|
| 965 | - foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 966 | - preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 967 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 968 | - } |
|
| 969 | - $keys = []; |
|
| 970 | - |
|
| 971 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 972 | - if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 973 | - $k = str_replace('`', '', trim($r[1])); |
|
| 974 | - $t = strtolower(str_replace('`', '', $r[2])); |
|
| 975 | - if ($k && !isset($keys[$k])) { |
|
| 976 | - $keys[$k] = $t; |
|
| 977 | - } else { |
|
| 978 | - $keys[] = $t; |
|
| 979 | - } |
|
| 980 | - } |
|
| 981 | - } |
|
| 982 | - spip_mysql_free($s); |
|
| 983 | - |
|
| 984 | - return ['field' => $fields, 'key' => $keys]; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 988 | - if ($res) { |
|
| 989 | - $nfields = []; |
|
| 990 | - $nkeys = []; |
|
| 991 | - while ($val = spip_mysql_fetch($res)) { |
|
| 992 | - $nfields[$val['Field']] = $val['Type']; |
|
| 993 | - if ($val['Null'] == 'NO') { |
|
| 994 | - $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 995 | - } |
|
| 996 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 997 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 998 | - $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 999 | - } else { |
|
| 1000 | - $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - if ($val['Extra']) { |
|
| 1004 | - $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 1005 | - } |
|
| 1006 | - if ($val['Key'] == 'PRI') { |
|
| 1007 | - $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 1008 | - } else { |
|
| 1009 | - if ($val['Key'] == 'MUL') { |
|
| 1010 | - $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 1011 | - } else { |
|
| 1012 | - if ($val['Key'] == 'UNI') { |
|
| 1013 | - $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1014 | - } |
|
| 1015 | - } |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - spip_mysql_free($res); |
|
| 1019 | - |
|
| 1020 | - return ['field' => $nfields, 'key' => $nkeys]; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - return ''; |
|
| 944 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 945 | + if (!$s) { |
|
| 946 | + return ''; |
|
| 947 | + } |
|
| 948 | + if (!$requeter) { |
|
| 949 | + return $s; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + [, $a] = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 953 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 954 | + $desc = $r[1]; |
|
| 955 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 956 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 957 | + if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 958 | + $namedkeys = $r[2]; |
|
| 959 | + $desc = $r[1]; |
|
| 960 | + } else { |
|
| 961 | + $namedkeys = ''; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + $fields = []; |
|
| 965 | + foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 966 | + preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 967 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 968 | + } |
|
| 969 | + $keys = []; |
|
| 970 | + |
|
| 971 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 972 | + if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 973 | + $k = str_replace('`', '', trim($r[1])); |
|
| 974 | + $t = strtolower(str_replace('`', '', $r[2])); |
|
| 975 | + if ($k && !isset($keys[$k])) { |
|
| 976 | + $keys[$k] = $t; |
|
| 977 | + } else { |
|
| 978 | + $keys[] = $t; |
|
| 979 | + } |
|
| 980 | + } |
|
| 981 | + } |
|
| 982 | + spip_mysql_free($s); |
|
| 983 | + |
|
| 984 | + return ['field' => $fields, 'key' => $keys]; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 988 | + if ($res) { |
|
| 989 | + $nfields = []; |
|
| 990 | + $nkeys = []; |
|
| 991 | + while ($val = spip_mysql_fetch($res)) { |
|
| 992 | + $nfields[$val['Field']] = $val['Type']; |
|
| 993 | + if ($val['Null'] == 'NO') { |
|
| 994 | + $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 995 | + } |
|
| 996 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 997 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 998 | + $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 999 | + } else { |
|
| 1000 | + $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + if ($val['Extra']) { |
|
| 1004 | + $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 1005 | + } |
|
| 1006 | + if ($val['Key'] == 'PRI') { |
|
| 1007 | + $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 1008 | + } else { |
|
| 1009 | + if ($val['Key'] == 'MUL') { |
|
| 1010 | + $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 1011 | + } else { |
|
| 1012 | + if ($val['Key'] == 'UNI') { |
|
| 1013 | + $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1014 | + } |
|
| 1015 | + } |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + spip_mysql_free($res); |
|
| 1019 | + |
|
| 1020 | + return ['field' => $nfields, 'key' => $nkeys]; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + return ''; |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | |
@@ -1039,13 +1039,13 @@ discard block |
||
| 1039 | 1039 | * - false Erreur |
| 1040 | 1040 | */ |
| 1041 | 1041 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 1042 | - if (!$t) { |
|
| 1043 | - $t = \MYSQLI_ASSOC; |
|
| 1044 | - } |
|
| 1045 | - if ($r) { |
|
| 1046 | - return mysqli_fetch_array($r, $t); |
|
| 1047 | - } |
|
| 1048 | - return false; |
|
| 1042 | + if (!$t) { |
|
| 1043 | + $t = \MYSQLI_ASSOC; |
|
| 1044 | + } |
|
| 1045 | + if ($r) { |
|
| 1046 | + return mysqli_fetch_array($r, $t); |
|
| 1047 | + } |
|
| 1048 | + return false; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | /** |
@@ -1058,10 +1058,10 @@ discard block |
||
| 1058 | 1058 | * @return bool True si déplacement réussi, false sinon. |
| 1059 | 1059 | **/ |
| 1060 | 1060 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 1061 | - if ($r and mysqli_num_rows($r)) { |
|
| 1062 | - return mysqli_data_seek($r, $row_number); |
|
| 1063 | - } |
|
| 1064 | - return false; |
|
| 1061 | + if ($r and mysqli_num_rows($r)) { |
|
| 1062 | + return mysqli_data_seek($r, $row_number); |
|
| 1063 | + } |
|
| 1064 | + return false; |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | |
@@ -1079,26 +1079,26 @@ discard block |
||
| 1079 | 1079 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1080 | 1080 | **/ |
| 1081 | 1081 | function spip_mysql_countsel( |
| 1082 | - $from = [], |
|
| 1083 | - $where = [], |
|
| 1084 | - $groupby = '', |
|
| 1085 | - $having = [], |
|
| 1086 | - $serveur = '', |
|
| 1087 | - $requeter = true |
|
| 1082 | + $from = [], |
|
| 1083 | + $where = [], |
|
| 1084 | + $groupby = '', |
|
| 1085 | + $having = [], |
|
| 1086 | + $serveur = '', |
|
| 1087 | + $requeter = true |
|
| 1088 | 1088 | ) { |
| 1089 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1090 | - |
|
| 1091 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1092 | - if (!$requeter) { |
|
| 1093 | - return $r; |
|
| 1094 | - } |
|
| 1095 | - if (!$r instanceof mysqli_result) { |
|
| 1096 | - return 0; |
|
| 1097 | - } |
|
| 1098 | - [$c] = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1099 | - mysqli_free_result($r); |
|
| 1100 | - |
|
| 1101 | - return intval($c); |
|
| 1089 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1090 | + |
|
| 1091 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1092 | + if (!$requeter) { |
|
| 1093 | + return $r; |
|
| 1094 | + } |
|
| 1095 | + if (!$r instanceof mysqli_result) { |
|
| 1096 | + return 0; |
|
| 1097 | + } |
|
| 1098 | + [$c] = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1099 | + mysqli_free_result($r); |
|
| 1100 | + |
|
| 1101 | + return intval($c); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1121,16 +1121,16 @@ discard block |
||
| 1121 | 1121 | * Erreur eventuelle |
| 1122 | 1122 | **/ |
| 1123 | 1123 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1124 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1125 | - $s = mysqli_error($link); |
|
| 1126 | - if ($s) { |
|
| 1127 | - $trace = debug_backtrace(); |
|
| 1128 | - if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1129 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - return $s; |
|
| 1124 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1125 | + $s = mysqli_error($link); |
|
| 1126 | + if ($s) { |
|
| 1127 | + $trace = debug_backtrace(); |
|
| 1128 | + if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1129 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + return $s; |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | |
@@ -1145,18 +1145,18 @@ discard block |
||
| 1145 | 1145 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1146 | 1146 | **/ |
| 1147 | 1147 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1148 | - $link = $GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 1149 | - $s = mysqli_errno($link); |
|
| 1150 | - // 2006 MySQL server has gone away |
|
| 1151 | - // 2013 Lost connection to MySQL server during query |
|
| 1152 | - if (in_array($s, [2006, 2013])) { |
|
| 1153 | - define('spip_interdire_cache', true); |
|
| 1154 | - } |
|
| 1155 | - if ($s) { |
|
| 1156 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - return $s; |
|
| 1148 | + $link = $GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 1149 | + $s = mysqli_errno($link); |
|
| 1150 | + // 2006 MySQL server has gone away |
|
| 1151 | + // 2013 Lost connection to MySQL server during query |
|
| 1152 | + if (in_array($s, [2006, 2013])) { |
|
| 1153 | + define('spip_interdire_cache', true); |
|
| 1154 | + } |
|
| 1155 | + if ($s) { |
|
| 1156 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + return $s; |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | |
@@ -1170,9 +1170,9 @@ discard block |
||
| 1170 | 1170 | * @return int Nombre de lignes |
| 1171 | 1171 | */ |
| 1172 | 1172 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1173 | - if ($r) { |
|
| 1174 | - return mysqli_num_rows($r); |
|
| 1175 | - } |
|
| 1173 | + if ($r) { |
|
| 1174 | + return mysqli_num_rows($r); |
|
| 1175 | + } |
|
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | |
@@ -1188,11 +1188,11 @@ discard block |
||
| 1188 | 1188 | * @return bool True si réussi |
| 1189 | 1189 | */ |
| 1190 | 1190 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1191 | - if ($r instanceof mysqli_result) { |
|
| 1192 | - mysqli_free_result($r); |
|
| 1193 | - return true; |
|
| 1194 | - } |
|
| 1195 | - return false; |
|
| 1191 | + if ($r instanceof mysqli_result) { |
|
| 1192 | + mysqli_free_result($r); |
|
| 1193 | + return true; |
|
| 1194 | + } |
|
| 1195 | + return false; |
|
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | 1198 | |
@@ -1220,59 +1220,59 @@ discard block |
||
| 1220 | 1220 | **/ |
| 1221 | 1221 | function spip_mysql_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 1222 | 1222 | |
| 1223 | - $e = null; |
|
| 1224 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1225 | - $link = $connexion['link']; |
|
| 1226 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1227 | - |
|
| 1228 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1229 | - if ( |
|
| 1230 | - defined('_MYSQL_NOPLANES') |
|
| 1231 | - and _MYSQL_NOPLANES |
|
| 1232 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1233 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1234 | - ) { |
|
| 1235 | - include_spip('inc/charsets'); |
|
| 1236 | - $valeurs = utf8_noplanes($valeurs); |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1240 | - if (!$requeter) { |
|
| 1241 | - return $query; |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - if (isset($_GET['var_profile'])) { |
|
| 1245 | - include_spip('public/tracer'); |
|
| 1246 | - $t = trace_query_start(); |
|
| 1247 | - $e = ''; |
|
| 1248 | - } else { |
|
| 1249 | - $t = 0; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - $connexion['last'] = $query; |
|
| 1253 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1254 | - $r = false; |
|
| 1255 | - $insert = false; |
|
| 1256 | - try { |
|
| 1257 | - $insert = mysqli_query($link, $query); |
|
| 1258 | - } catch (\mysqli_sql_exception $e) { |
|
| 1259 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1260 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 1261 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 1262 | - } |
|
| 1263 | - if ($insert) { |
|
| 1264 | - $r = mysqli_insert_id($link); |
|
| 1265 | - } else { |
|
| 1266 | - // Log de l'erreur eventuelle |
|
| 1267 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1268 | - // et du fautif |
|
| 1269 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1274 | - |
|
| 1275 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1223 | + $e = null; |
|
| 1224 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1225 | + $link = $connexion['link']; |
|
| 1226 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1227 | + |
|
| 1228 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1229 | + if ( |
|
| 1230 | + defined('_MYSQL_NOPLANES') |
|
| 1231 | + and _MYSQL_NOPLANES |
|
| 1232 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1233 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1234 | + ) { |
|
| 1235 | + include_spip('inc/charsets'); |
|
| 1236 | + $valeurs = utf8_noplanes($valeurs); |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1240 | + if (!$requeter) { |
|
| 1241 | + return $query; |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + if (isset($_GET['var_profile'])) { |
|
| 1245 | + include_spip('public/tracer'); |
|
| 1246 | + $t = trace_query_start(); |
|
| 1247 | + $e = ''; |
|
| 1248 | + } else { |
|
| 1249 | + $t = 0; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + $connexion['last'] = $query; |
|
| 1253 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1254 | + $r = false; |
|
| 1255 | + $insert = false; |
|
| 1256 | + try { |
|
| 1257 | + $insert = mysqli_query($link, $query); |
|
| 1258 | + } catch (\mysqli_sql_exception $e) { |
|
| 1259 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1260 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 1261 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 1262 | + } |
|
| 1263 | + if ($insert) { |
|
| 1264 | + $r = mysqli_insert_id($link); |
|
| 1265 | + } else { |
|
| 1266 | + // Log de l'erreur eventuelle |
|
| 1267 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1268 | + // et du fautif |
|
| 1269 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1274 | + |
|
| 1275 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1276 | 1276 | } |
| 1277 | 1277 | |
| 1278 | 1278 | /** |
@@ -1297,26 +1297,26 @@ discard block |
||
| 1297 | 1297 | **/ |
| 1298 | 1298 | function spip_mysql_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1299 | 1299 | |
| 1300 | - if (!$desc) { |
|
| 1301 | - $desc = description_table($table, $serveur); |
|
| 1302 | - } |
|
| 1303 | - if (!$desc) { |
|
| 1304 | - $couples = []; |
|
| 1305 | - } |
|
| 1306 | - $fields = $desc['field'] ?? []; |
|
| 1307 | - |
|
| 1308 | - foreach ($couples as $champ => $val) { |
|
| 1309 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - return spip_mysql_insert( |
|
| 1313 | - $table, |
|
| 1314 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 1315 | - '(' . join(',', $couples) . ')', |
|
| 1316 | - $desc, |
|
| 1317 | - $serveur, |
|
| 1318 | - $requeter |
|
| 1319 | - ); |
|
| 1300 | + if (!$desc) { |
|
| 1301 | + $desc = description_table($table, $serveur); |
|
| 1302 | + } |
|
| 1303 | + if (!$desc) { |
|
| 1304 | + $couples = []; |
|
| 1305 | + } |
|
| 1306 | + $fields = $desc['field'] ?? []; |
|
| 1307 | + |
|
| 1308 | + foreach ($couples as $champ => $val) { |
|
| 1309 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + return spip_mysql_insert( |
|
| 1313 | + $table, |
|
| 1314 | + '(' . join(',', array_keys($couples)) . ')', |
|
| 1315 | + '(' . join(',', $couples) . ')', |
|
| 1316 | + $desc, |
|
| 1317 | + $serveur, |
|
| 1318 | + $requeter |
|
| 1319 | + ); |
|
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | |
@@ -1341,34 +1341,34 @@ discard block |
||
| 1341 | 1341 | **/ |
| 1342 | 1342 | function spip_mysql_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1343 | 1343 | |
| 1344 | - if (!$desc) { |
|
| 1345 | - $desc = description_table($table, $serveur); |
|
| 1346 | - } |
|
| 1347 | - if (!$desc) { |
|
| 1348 | - $tab_couples = []; |
|
| 1349 | - } |
|
| 1350 | - $fields = $desc['field'] ?? []; |
|
| 1351 | - |
|
| 1352 | - $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1353 | - $valeurs = []; |
|
| 1354 | - $r = false; |
|
| 1355 | - |
|
| 1356 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1357 | - foreach ($tab_couples as $couples) { |
|
| 1358 | - foreach ($couples as $champ => $val) { |
|
| 1359 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1360 | - } |
|
| 1361 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1362 | - if (count($valeurs) >= 100) { |
|
| 1363 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1364 | - $valeurs = []; |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - if (count($valeurs)) { |
|
| 1368 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1344 | + if (!$desc) { |
|
| 1345 | + $desc = description_table($table, $serveur); |
|
| 1346 | + } |
|
| 1347 | + if (!$desc) { |
|
| 1348 | + $tab_couples = []; |
|
| 1349 | + } |
|
| 1350 | + $fields = $desc['field'] ?? []; |
|
| 1351 | + |
|
| 1352 | + $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1353 | + $valeurs = []; |
|
| 1354 | + $r = false; |
|
| 1355 | + |
|
| 1356 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1357 | + foreach ($tab_couples as $couples) { |
|
| 1358 | + foreach ($couples as $champ => $val) { |
|
| 1359 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1360 | + } |
|
| 1361 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1362 | + if (count($valeurs) >= 100) { |
|
| 1363 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1364 | + $valeurs = []; |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + if (count($valeurs)) { |
|
| 1368 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | /** |
@@ -1393,20 +1393,20 @@ discard block |
||
| 1393 | 1393 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1394 | 1394 | */ |
| 1395 | 1395 | function spip_mysql_update($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1396 | - $set = []; |
|
| 1397 | - foreach ($champs as $champ => $val) { |
|
| 1398 | - $set[] = $champ . "=$val"; |
|
| 1399 | - } |
|
| 1400 | - if (!empty($set)) { |
|
| 1401 | - return spip_mysql_query( |
|
| 1402 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1403 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1404 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1405 | - $serveur, |
|
| 1406 | - $requeter |
|
| 1407 | - ); |
|
| 1408 | - } |
|
| 1409 | - return false; |
|
| 1396 | + $set = []; |
|
| 1397 | + foreach ($champs as $champ => $val) { |
|
| 1398 | + $set[] = $champ . "=$val"; |
|
| 1399 | + } |
|
| 1400 | + if (!empty($set)) { |
|
| 1401 | + return spip_mysql_query( |
|
| 1402 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1403 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1404 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1405 | + $serveur, |
|
| 1406 | + $requeter |
|
| 1407 | + ); |
|
| 1408 | + } |
|
| 1409 | + return false; |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | /** |
@@ -1439,29 +1439,29 @@ discard block |
||
| 1439 | 1439 | */ |
| 1440 | 1440 | function spip_mysql_updateq($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1441 | 1441 | |
| 1442 | - if (!$champs) { |
|
| 1443 | - return; |
|
| 1444 | - } |
|
| 1445 | - if (!$desc) { |
|
| 1446 | - $desc = description_table($table, $serveur); |
|
| 1447 | - } |
|
| 1448 | - if (!$desc) { |
|
| 1449 | - $champs = []; |
|
| 1450 | - } else { |
|
| 1451 | - $fields = $desc['field']; |
|
| 1452 | - } |
|
| 1453 | - $set = []; |
|
| 1454 | - foreach ($champs as $champ => $val) { |
|
| 1455 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - return spip_mysql_query( |
|
| 1459 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1460 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1461 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1462 | - $serveur, |
|
| 1463 | - $requeter |
|
| 1464 | - ); |
|
| 1442 | + if (!$champs) { |
|
| 1443 | + return; |
|
| 1444 | + } |
|
| 1445 | + if (!$desc) { |
|
| 1446 | + $desc = description_table($table, $serveur); |
|
| 1447 | + } |
|
| 1448 | + if (!$desc) { |
|
| 1449 | + $champs = []; |
|
| 1450 | + } else { |
|
| 1451 | + $fields = $desc['field']; |
|
| 1452 | + } |
|
| 1453 | + $set = []; |
|
| 1454 | + foreach ($champs as $champ => $val) { |
|
| 1455 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + return spip_mysql_query( |
|
| 1459 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1460 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1461 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1462 | + $serveur, |
|
| 1463 | + $requeter |
|
| 1464 | + ); |
|
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | /** |
@@ -1477,22 +1477,22 @@ discard block |
||
| 1477 | 1477 | * - false en cas d'erreur. |
| 1478 | 1478 | **/ |
| 1479 | 1479 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1480 | - $res = spip_mysql_query( |
|
| 1481 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1482 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1483 | - $serveur, |
|
| 1484 | - $requeter |
|
| 1485 | - ); |
|
| 1486 | - if (!$requeter) { |
|
| 1487 | - return $res; |
|
| 1488 | - } |
|
| 1489 | - if ($res) { |
|
| 1490 | - $link = _mysql_link($serveur); |
|
| 1491 | - |
|
| 1492 | - return mysqli_affected_rows($link); |
|
| 1493 | - } else { |
|
| 1494 | - return false; |
|
| 1495 | - } |
|
| 1480 | + $res = spip_mysql_query( |
|
| 1481 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1482 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1483 | + $serveur, |
|
| 1484 | + $requeter |
|
| 1485 | + ); |
|
| 1486 | + if (!$requeter) { |
|
| 1487 | + return $res; |
|
| 1488 | + } |
|
| 1489 | + if ($res) { |
|
| 1490 | + $link = _mysql_link($serveur); |
|
| 1491 | + |
|
| 1492 | + return mysqli_affected_rows($link); |
|
| 1493 | + } else { |
|
| 1494 | + return false; |
|
| 1495 | + } |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | |
@@ -1521,10 +1521,10 @@ discard block |
||
| 1521 | 1521 | * - false en cas d'erreur. |
| 1522 | 1522 | **/ |
| 1523 | 1523 | function spip_mysql_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1524 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1525 | - ',', |
|
| 1526 | - array_map('_q', $couples) |
|
| 1527 | - ) . ')', $serveur, $requeter); |
|
| 1524 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1525 | + ',', |
|
| 1526 | + array_map('_q', $couples) |
|
| 1527 | + ) . ')', $serveur, $requeter); |
|
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | 1530 | |
@@ -1553,14 +1553,14 @@ discard block |
||
| 1553 | 1553 | * - false en cas d'erreur. |
| 1554 | 1554 | **/ |
| 1555 | 1555 | function spip_mysql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1556 | - $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1557 | - $valeurs = []; |
|
| 1558 | - foreach ($tab_couples as $couples) { |
|
| 1559 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1560 | - } |
|
| 1561 | - $valeurs = implode(', ', $valeurs); |
|
| 1562 | - |
|
| 1563 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1556 | + $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1557 | + $valeurs = []; |
|
| 1558 | + foreach ($tab_couples as $couples) { |
|
| 1559 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1560 | + } |
|
| 1561 | + $valeurs = implode(', ', $valeurs); |
|
| 1562 | + |
|
| 1563 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | 1566 | |
@@ -1575,32 +1575,32 @@ discard block |
||
| 1575 | 1575 | * @return string texte de sélection pour la requête |
| 1576 | 1576 | */ |
| 1577 | 1577 | function spip_mysql_multi($objet, $lang) { |
| 1578 | - $lengthlang = strlen("[$lang]"); |
|
| 1579 | - $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1580 | - $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1581 | - $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1582 | - $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1583 | - $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1584 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1585 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1586 | - $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1587 | - $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1588 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1589 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1590 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1591 | - ' TRIM(' . $objet . '), ' . |
|
| 1592 | - ' CONCAT( ' . |
|
| 1593 | - " $debutchaine, " . |
|
| 1594 | - ' IF( ' . |
|
| 1595 | - " $poslang = 0, " . |
|
| 1596 | - " $chainemulti, " . |
|
| 1597 | - " $chainelang" . |
|
| 1598 | - ' ), ' . |
|
| 1599 | - " $finchaine" . |
|
| 1600 | - ' ) ' . |
|
| 1601 | - '))) AS multi'; |
|
| 1602 | - |
|
| 1603 | - return $retour; |
|
| 1578 | + $lengthlang = strlen("[$lang]"); |
|
| 1579 | + $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1580 | + $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1581 | + $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1582 | + $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1583 | + $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1584 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1585 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1586 | + $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1587 | + $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1588 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1589 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1590 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1591 | + ' TRIM(' . $objet . '), ' . |
|
| 1592 | + ' CONCAT( ' . |
|
| 1593 | + " $debutchaine, " . |
|
| 1594 | + ' IF( ' . |
|
| 1595 | + " $poslang = 0, " . |
|
| 1596 | + " $chainemulti, " . |
|
| 1597 | + " $chainelang" . |
|
| 1598 | + ' ), ' . |
|
| 1599 | + " $finchaine" . |
|
| 1600 | + ' ) ' . |
|
| 1601 | + '))) AS multi'; |
|
| 1602 | + |
|
| 1603 | + return $retour; |
|
| 1604 | 1604 | } |
| 1605 | 1605 | |
| 1606 | 1606 | /** |
@@ -1614,7 +1614,7 @@ discard block |
||
| 1614 | 1614 | * Valeur hexadécimale pour MySQL |
| 1615 | 1615 | **/ |
| 1616 | 1616 | function spip_mysql_hex($v) { |
| 1617 | - return '0x' . $v; |
|
| 1617 | + return '0x' . $v; |
|
| 1618 | 1618 | } |
| 1619 | 1619 | |
| 1620 | 1620 | /** |
@@ -1630,15 +1630,15 @@ discard block |
||
| 1630 | 1630 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1631 | 1631 | */ |
| 1632 | 1632 | function spip_mysql_quote($v, $type = '') { |
| 1633 | - if (!is_array($v)) { |
|
| 1634 | - return spip_mysql_cite($v, $type); |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1638 | - foreach ($v as $k => $r) { |
|
| 1639 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1640 | - } |
|
| 1641 | - return implode(',', $v); |
|
| 1633 | + if (!is_array($v)) { |
|
| 1634 | + return spip_mysql_cite($v, $type); |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1638 | + foreach ($v as $k => $r) { |
|
| 1639 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1640 | + } |
|
| 1641 | + return implode(',', $v); |
|
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | 1644 | /** |
@@ -1654,18 +1654,18 @@ discard block |
||
| 1654 | 1654 | * Expression SQL |
| 1655 | 1655 | **/ |
| 1656 | 1656 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1657 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1658 | - return '(' |
|
| 1659 | - . $champ |
|
| 1660 | - . (($interval <= 0) ? '>' : '<') |
|
| 1661 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1662 | - . '(' |
|
| 1663 | - . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1664 | - . ', INTERVAL ' |
|
| 1665 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1666 | - . ' ' |
|
| 1667 | - . $unite |
|
| 1668 | - . '))'; |
|
| 1657 | + $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1658 | + return '(' |
|
| 1659 | + . $champ |
|
| 1660 | + . (($interval <= 0) ? '>' : '<') |
|
| 1661 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1662 | + . '(' |
|
| 1663 | + . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1664 | + . ', INTERVAL ' |
|
| 1665 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1666 | + . ' ' |
|
| 1667 | + . $unite |
|
| 1668 | + . '))'; |
|
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | |
@@ -1689,7 +1689,7 @@ discard block |
||
| 1689 | 1689 | * Expression de requête SQL |
| 1690 | 1690 | **/ |
| 1691 | 1691 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1692 | - return "($val $not IN ($valeurs))"; |
|
| 1692 | + return "($val $not IN ($valeurs))"; |
|
| 1693 | 1693 | } |
| 1694 | 1694 | |
| 1695 | 1695 | |
@@ -1701,39 +1701,39 @@ discard block |
||
| 1701 | 1701 | * @return string|number texte ou nombre échappé |
| 1702 | 1702 | */ |
| 1703 | 1703 | function spip_mysql_cite($v, $type) { |
| 1704 | - if (!$type) { |
|
| 1705 | - if (is_bool($v)) { |
|
| 1706 | - return strval(intval($v)); |
|
| 1707 | - } elseif (is_numeric($v)) { |
|
| 1708 | - return strval($v); |
|
| 1709 | - } elseif ($v === null) { |
|
| 1710 | - return "''"; |
|
| 1711 | - } |
|
| 1712 | - return "'" . addslashes($v) . "'"; |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - if ($v === null) { |
|
| 1716 | - if (stripos($type, 'NOT NULL') === false) { |
|
| 1717 | - // null php se traduit en NULL SQL |
|
| 1718 | - return 'NULL'; |
|
| 1719 | - } else { |
|
| 1720 | - return "''"; |
|
| 1721 | - } |
|
| 1722 | - } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1723 | - return $v; |
|
| 1724 | - } elseif (sql_test_int($type)) { |
|
| 1725 | - if ( |
|
| 1726 | - is_numeric($v) |
|
| 1727 | - or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1728 | - ) { |
|
| 1729 | - return $v; |
|
| 1730 | - } else { |
|
| 1731 | - // si pas numerique, forcer le intval |
|
| 1732 | - return intval($v); |
|
| 1733 | - } |
|
| 1734 | - } |
|
| 1735 | - |
|
| 1736 | - return ("'" . addslashes($v) . "'"); |
|
| 1704 | + if (!$type) { |
|
| 1705 | + if (is_bool($v)) { |
|
| 1706 | + return strval(intval($v)); |
|
| 1707 | + } elseif (is_numeric($v)) { |
|
| 1708 | + return strval($v); |
|
| 1709 | + } elseif ($v === null) { |
|
| 1710 | + return "''"; |
|
| 1711 | + } |
|
| 1712 | + return "'" . addslashes($v) . "'"; |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + if ($v === null) { |
|
| 1716 | + if (stripos($type, 'NOT NULL') === false) { |
|
| 1717 | + // null php se traduit en NULL SQL |
|
| 1718 | + return 'NULL'; |
|
| 1719 | + } else { |
|
| 1720 | + return "''"; |
|
| 1721 | + } |
|
| 1722 | + } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1723 | + return $v; |
|
| 1724 | + } elseif (sql_test_int($type)) { |
|
| 1725 | + if ( |
|
| 1726 | + is_numeric($v) |
|
| 1727 | + or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1728 | + ) { |
|
| 1729 | + return $v; |
|
| 1730 | + } else { |
|
| 1731 | + // si pas numerique, forcer le intval |
|
| 1732 | + return intval($v); |
|
| 1733 | + } |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + return ("'" . addslashes($v) . "'"); |
|
| 1737 | 1737 | } |
| 1738 | 1738 | |
| 1739 | 1739 | /** |
@@ -1743,7 +1743,7 @@ discard block |
||
| 1743 | 1743 | * True si on a les fonctions, false sinon |
| 1744 | 1744 | */ |
| 1745 | 1745 | function spip_versions_mysql() { |
| 1746 | - return function_exists('mysqli_query'); |
|
| 1746 | + return function_exists('mysqli_query'); |
|
| 1747 | 1747 | } |
| 1748 | 1748 | |
| 1749 | 1749 | |
@@ -1756,20 +1756,20 @@ discard block |
||
| 1756 | 1756 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1757 | 1757 | */ |
| 1758 | 1758 | function test_rappel_nom_base_mysql($server_db) { |
| 1759 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1760 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1761 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1759 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1760 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1761 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1762 | 1762 | |
| 1763 | - if ($ok) { |
|
| 1764 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1763 | + if ($ok) { |
|
| 1764 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1765 | 1765 | |
| 1766 | - return ''; |
|
| 1767 | - } else { |
|
| 1768 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1766 | + return ''; |
|
| 1767 | + } else { |
|
| 1768 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1769 | 1769 | |
| 1770 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1771 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1772 | - } |
|
| 1770 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1771 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1772 | + } |
|
| 1773 | 1773 | } |
| 1774 | 1774 | |
| 1775 | 1775 | /** |
@@ -1783,13 +1783,13 @@ discard block |
||
| 1783 | 1783 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1784 | 1784 | */ |
| 1785 | 1785 | function test_sql_mode_mysql($server_db) { |
| 1786 | - $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1787 | - $row = sql_fetch($res, $server_db); |
|
| 1788 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1789 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1786 | + $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1787 | + $row = sql_fetch($res, $server_db); |
|
| 1788 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1789 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1790 | 1790 | |
| 1791 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1792 | - } |
|
| 1791 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1792 | + } |
|
| 1793 | 1793 | |
| 1794 | - return ''; |
|
| 1794 | + return ''; |
|
| 1795 | 1795 | } |
@@ -63,9 +63,9 @@ |
||
| 63 | 63 | $f = new IndenteurXML(); |
| 64 | 64 | $sax($page, $apply, $f); |
| 65 | 65 | if (!$f->err) { |
| 66 | - return $f->entete . $f->res; |
|
| 66 | + return $f->entete.$f->res; |
|
| 67 | 67 | } |
| 68 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 68 | + spip_log('indentation impossible '.(is_countable($f->err) ? count($f->err) : 0).' erreurs de validation'); |
|
| 69 | 69 | |
| 70 | - return $f->entete . $f->page; |
|
| 70 | + return $f->entete.$f->page; |
|
| 71 | 71 | } |
@@ -10,54 +10,54 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | class IndenteurXML { |
| 17 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 18 | - xml_debutElement($this, $name, $attrs); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function finElement($phraseur, $name) { |
|
| 22 | - xml_finElement($this, $name); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function textElement($phraseur, $data) { |
|
| 26 | - xml_textElement($this, $data); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function piElement($phraseur, $target, $data) { |
|
| 30 | - xml_PiElement($this, $target, $data); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function defaultElement($phraseur, $data) { |
|
| 34 | - xml_defaultElement($this, $data); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function phraserTout($phraseur, $data) { |
|
| 38 | - xml_parsestring($this, $data); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public $depth = ''; |
|
| 42 | - public $res = ''; |
|
| 43 | - public $err = []; |
|
| 44 | - public $contenu = []; |
|
| 45 | - public $ouvrant = []; |
|
| 46 | - public $reperes = []; |
|
| 47 | - public $entete = ''; |
|
| 48 | - public $page = ''; |
|
| 49 | - public $dtc = null; |
|
| 50 | - public $sax = null; |
|
| 17 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 18 | + xml_debutElement($this, $name, $attrs); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function finElement($phraseur, $name) { |
|
| 22 | + xml_finElement($this, $name); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function textElement($phraseur, $data) { |
|
| 26 | + xml_textElement($this, $data); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function piElement($phraseur, $target, $data) { |
|
| 30 | + xml_PiElement($this, $target, $data); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function defaultElement($phraseur, $data) { |
|
| 34 | + xml_defaultElement($this, $data); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function phraserTout($phraseur, $data) { |
|
| 38 | + xml_parsestring($this, $data); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public $depth = ''; |
|
| 42 | + public $res = ''; |
|
| 43 | + public $err = []; |
|
| 44 | + public $contenu = []; |
|
| 45 | + public $ouvrant = []; |
|
| 46 | + public $reperes = []; |
|
| 47 | + public $entete = ''; |
|
| 48 | + public $page = ''; |
|
| 49 | + public $dtc = null; |
|
| 50 | + public $sax = null; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | function xml_indenter_dist($page, $apply = false) { |
| 54 | - $sax = charger_fonction('sax', 'xml'); |
|
| 55 | - $f = new IndenteurXML(); |
|
| 56 | - $sax($page, $apply, $f); |
|
| 57 | - if (!$f->err) { |
|
| 58 | - return $f->entete . $f->res; |
|
| 59 | - } |
|
| 60 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 61 | - |
|
| 62 | - return $f->entete . $f->page; |
|
| 54 | + $sax = charger_fonction('sax', 'xml'); |
|
| 55 | + $f = new IndenteurXML(); |
|
| 56 | + $sax($page, $apply, $f); |
|
| 57 | + if (!$f->err) { |
|
| 58 | + return $f->entete . $f->res; |
|
| 59 | + } |
|
| 60 | + spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 61 | + |
|
| 62 | + return $f->entete . $f->page; |
|
| 63 | 63 | } |