From adc3b60322c90c819f28c97b600d9ca48e29e3a1 Mon Sep 17 00:00:00 2001 From: Matthieu Marcillaud <marcimat@rezo.net> Date: Wed, 5 Sep 2018 11:09:26 +0000 Subject: [PATCH] Tickets #4059 et #4138 : meilleure compat PHP 7.2 - create_function en moins, - each() en moins, - preg /e en moins --- ecrire/base/connect_sql.php | 1 + ecrire/base/upgrade.php | 5 ++--- ecrire/inc/charsets.php | 7 +++++-- ecrire/inc/config.php | 4 ++-- ecrire/inc/plonger.php | 2 +- ecrire/install/etape_chmod.php | 2 +- ecrire/req/sqlite_generique.php | 6 ++---- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ecrire/base/connect_sql.php b/ecrire/base/connect_sql.php index a0a969faf7..85e1ecb41a 100644 --- a/ecrire/base/connect_sql.php +++ b/ecrire/base/connect_sql.php @@ -526,6 +526,7 @@ function query_reinjecte_textes($query, $textes) { * - indéfini sinon. **/ function spip_query($query, $serveur = '') { + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); return function_exists($f) ? $f($query, $serveur) : false; diff --git a/ecrire/base/upgrade.php b/ecrire/base/upgrade.php index d72e7e932c..728e4773c5 100644 --- a/ecrire/base/upgrade.php +++ b/ecrire/base/upgrade.php @@ -382,8 +382,7 @@ function maj_while($installee, $cible, $maj, $meta = '', $table = 'meta', $redir define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); } - reset($maj); - while (list($v, ) = each($maj)) { + foreach ($maj as $v => $operations) { // si une maj pour cette version if ($v == 'init' or (spip_version_compare($v, $installee, '>') @@ -393,7 +392,7 @@ function maj_while($installee, $cible, $maj, $meta = '', $table = 'meta', $redir maj_debut_page($v, $meta, $table); } echo "MAJ $v"; - $etape = serie_alter($v, $maj[$v], $meta, $table, $redirect); + $etape = serie_alter($v, $operations, $meta, $table, $redirect); $trouver_table(''); // vider le cache des descriptions de table # echec sur une etape en cours ? # on sort diff --git a/ecrire/inc/charsets.php b/ecrire/inc/charsets.php index 7ea38a64f0..b32011d1ae 100644 --- a/ecrire/inc/charsets.php +++ b/ecrire/inc/charsets.php @@ -897,8 +897,11 @@ function translitteration_complexe($texte, $chiffres = false) { $texte = translitteration($texte, 'AUTO', 'complexe'); if ($chiffres) { - $texte = preg_replace("/[aeiuoyd]['`?~.^+(-]{1,2}/eS", - "translitteration_chiffree('\\0')", $texte); + $texte = preg_replace_callback( + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", + function($m) { return translitteration_chiffree($m[0]); }, + $texte + ); } return $texte; diff --git a/ecrire/inc/config.php b/ecrire/inc/config.php index 73097f4134..a06d5d8082 100644 --- a/ecrire/inc/config.php +++ b/ecrire/inc/config.php @@ -544,8 +544,8 @@ function actualise_metas($liste_meta) { // verifier le impt=non sql_updateq('spip_meta', array('impt' => 'non'), sql_in('nom', $meta_serveur)); - while (list($nom, $valeur) = each($liste_meta)) { - if (!isset($GLOBALS['meta'][$nom]) or !$GLOBALS['meta'][$nom]) { + foreach ($liste_meta as $nom => $valeur) { + if (empty($GLOBALS['meta'][$nom])) { ecrire_meta($nom, $valeur); } } diff --git a/ecrire/inc/plonger.php b/ecrire/inc/plonger.php index 2ee9e97d68..18891adca6 100644 --- a/ecrire/inc/plonger.php +++ b/ecrire/inc/plonger.php @@ -57,8 +57,8 @@ function inc_plonger_dist($id_rubrique, $idom = "", $list = array(), $col = 1, $ $rec = generer_url_ecrire('plonger', "rac=$idom&exclus=$exclu&do=$do&col=" . ($col + 1)); $info = generer_url_ecrire('informer', "type=rubrique&rac=$idom&do=$do&id="); $args = "'$idom',this,$col,'" . $GLOBALS['spip_lang_left'] . "','$info',event"; - while (list($id, $titrebrut) = each($ordre)) { + foreach ($ordre as $id => $titrebrut) { $titre = supprimer_numero($titrebrut); $classe1 = $id_rubrique ? 'petite-rubrique' : "petit-secteur"; diff --git a/ecrire/install/etape_chmod.php b/ecrire/install/etape_chmod.php index cbbbe21a9e..870a24fc59 100644 --- a/ecrire/install/etape_chmod.php +++ b/ecrire/install/etape_chmod.php @@ -93,7 +93,7 @@ function install_etape_chmod_dist() { $bad_dirs = array(); $absent_dirs = array(); - while (list(, $my_dir) = each($GLOBALS['test_dirs'])) { + foreach ($GLOBALS['test_dirs'] as $i => $my_dir) { $test = test_ecrire($my_dir); if (!$test) { $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir); diff --git a/ecrire/req/sqlite_generique.php b/ecrire/req/sqlite_generique.php index 2cd3bab685..06c7176eef 100644 --- a/ecrire/req/sqlite_generique.php +++ b/ecrire/req/sqlite_generique.php @@ -2296,16 +2296,14 @@ function _sqlite_charger_version($version = '') { function _sqlite_modifier_table($table, $colonne, $opt = array(), $serveur = '') { if (is_array($table)) { - reset($table); - list($table_origine, $table_destination) = each($table); + list($table_origine, $table_destination) = reset($table); } else { $table_origine = $table_destination = $table; } // ne prend actuellement qu'un changement // mais pourra etre adapte pour changer plus qu'une colonne a la fois if (is_array($colonne)) { - reset($colonne); - list($colonne_origine, $colonne_destination) = each($colonne); + list($colonne_origine, $colonne_destination) = reset($colonne); } else { $colonne_origine = $colonne_destination = $colonne; } -- GitLab