Browse Source

Rector jusqu’à PHP 7.3 (SPIP 4.0+)

pull/13/head
Matthieu Marcillaud 1 year ago committed by Cerdic
parent
commit
ebe106332d
  1. 2
      facteur_fonctions.php
  2. 2
      formulaires/tester_facteur.php
  3. 29
      inc/envoyer_mail.php
  4. 6
      inc/facteur_envoyer_alerte_fail.php

2
facteur_fonctions.php

@ -118,7 +118,7 @@ function facteur_formulaire_fond($flux) {
$url = generer_url_ecrire('configurer_facteur');
$ajout = '<p class="notice" style="margin-top:0">'._T('facteur:message_identite_email', array('url' => $url, 'email' => $email)).'</p>';
if (preg_match(",<(div|li) [^>]*class=[\"']editer editer_email_webmaster.*>,Uims", $flux['data'], $match)) {
$p = strpos($flux['data'], $match[0]);
$p = strpos($flux['data'], (string) $match[0]);
$p = strpos($flux['data'], "<input", $p);
$p = strpos($flux['data'], "</".$match[1], $p);
$flux['data'] = substr_replace($flux['data'], $ajout, $p, 0);

2
formulaires/tester_facteur.php

@ -123,7 +123,7 @@ function facteur_envoyer_mail_test($destinataire, $titre, &$message_html, $optio
$mime = sql_getfetsel('mime_type', 'spip_types_documents', 'extension=' . sql_quote($doc['extension']));
$piece_jointe = [
'chemin' => $file,
'nom' => $doc['titre'] ? $doc['titre'] : basename($doc['fichier']),
'nom' => $doc['titre'] ?: basename($doc['fichier']),
'mime' => $mime,
];
break 2;

29
inc/envoyer_mail.php

@ -92,6 +92,7 @@ function facteur_extraire_sujet($message_html, $message_texte = '') {
* @throws Exception
*/
function inc_envoyer_mail($destinataire, $sujet, $message, $from = '', $headers = '') {
$nom_repondre_a = null;
$message_html = '';
$message_texte = '';
$nom_envoyeur = $cc = $bcc = $repondre_a = '';
@ -102,17 +103,17 @@ function inc_envoyer_mail($destinataire, $sujet, $message, $from = '', $headers
// avec entrees possible : html, texte, pieces_jointes, nom_envoyeur, ...
if (is_array($message)) {
// si on fournit un $message['html'] deliberemment vide, c'est qu'on n'en veut pas, et donc on restera au format texte
$message_html = isset($message['html']) ? ($message['html'] ? $message['html'] : ' ') : '';
$message_html = isset($message['html']) ? ($message['html'] ?: ' ') : '';
$message_texte = isset($message['texte']) ? nettoyer_caracteres_mail($message['texte']) : '';
$pieces_jointes = isset($message['pieces_jointes']) ? $message['pieces_jointes'] : [];
$nom_envoyeur = isset($message['nom_envoyeur']) ? $message['nom_envoyeur'] : '';
$from = isset($message['from']) ? $message['from'] : $from;
$cc = isset($message['cc']) ? $message['cc'] : '';
$bcc = isset($message['bcc']) ? $message['bcc'] : '';
$repondre_a = isset($message['repondre_a']) ? $message['repondre_a'] : '';
$nom_repondre_a = isset($message['nom_repondre_a']) ? $message['nom_repondre_a'] : '';
$adresse_erreur = isset($message['adresse_erreur']) ? $message['adresse_erreur'] : '';
$headers = isset($message['headers']) ? $message['headers'] : $headers;
$pieces_jointes = $message['pieces_jointes'] ?? [];
$nom_envoyeur = $message['nom_envoyeur'] ?? '';
$from = $message['from'] ?? $from;
$cc = $message['cc'] ?? '';
$bcc = $message['bcc'] ?? '';
$repondre_a = $message['repondre_a'] ?? '';
$nom_repondre_a = $message['nom_repondre_a'] ?? '';
$adresse_erreur = $message['adresse_erreur'] ?? '';
$headers = $message['headers'] ?? $headers;
if (is_string($headers)) {
$headers = array_map('trim', explode("\n", $headers));
$headers = array_filter($headers);
@ -303,18 +304,18 @@ function inc_envoyer_mail($destinataire, $sujet, $message, $from = '', $headers
}
// S'il y a des pièces jointes on les ajoute proprement
if (count($pieces_jointes)) {
if (is_countable($pieces_jointes) ? count($pieces_jointes) : 0) {
foreach ($pieces_jointes as $piece) {
if (!empty($piece['chemin']) and file_exists($piece['chemin'])) {
$facteur->AddAttachment(
$piece['chemin'],
isset($piece['nom']) ? $piece['nom'] : '',
$piece['nom'] ?? '',
(isset($piece['encodage']) and in_array($piece['encodage'], ['base64', '7bit', '8bit', 'binary', 'quoted-printable'])) ? $piece['encodage'] : 'base64',
isset($piece['mime']) ? $piece['mime'] : Facteur::_mime_types(pathinfo($piece['chemin'], PATHINFO_EXTENSION))
$piece['mime'] ?? Facteur::_mime_types(pathinfo($piece['chemin'], PATHINFO_EXTENSION))
);
}
else {
spip_log('Piece jointe manquante ignoree : ' . json_encode($piece), 'facteur' . _LOG_ERREUR);
spip_log('Piece jointe manquante ignoree : ' . json_encode($piece, JSON_THROW_ON_ERROR), 'facteur' . _LOG_ERREUR);
}
}
}

6
inc/facteur_envoyer_alerte_fail.php

@ -22,7 +22,7 @@ function inc_facteur_envoyer_alerte_fail_dist($function, $args, $include = null)
if (is_string($args)) {
$args = unserialize($args);
if ($args === false) {
spip_log('sendFailAlert: arguments errones ' . json_encode([$function, $args, $include]), 'facteur' . _LOG_ERREUR);
spip_log('sendFailAlert: arguments errones ' . json_encode([$function, $args, $include], JSON_THROW_ON_ERROR), 'facteur' . _LOG_ERREUR);
$args = [];
}
}
@ -39,11 +39,11 @@ function inc_facteur_envoyer_alerte_fail_dist($function, $args, $include = null)
}
if (!function_exists($function)) {
spip_log("sendFailAlert: fonction $function ($include) inexistante " . json_encode([$function, $args, $include]), 'facteur' . _LOG_ERREUR);
spip_log("sendFailAlert: fonction $function ($include) inexistante " . json_encode([$function, $args, $include], JSON_THROW_ON_ERROR), 'facteur' . _LOG_ERREUR);
return false;
}
$traceargs = md5(json_encode($args));
$traceargs = md5(json_encode($args, JSON_THROW_ON_ERROR));
spip_log("sendFailAlert: $function([$traceargs]) start", 'facteur');
$res = call_user_func_array($function, $args);
spip_log("sendFailAlert: $function([$traceargs]) end", 'facteur');

Loading…
Cancel
Save