premier jet pour la fonction inc/envoyer_gamumail qui envoie un mail à partir d'un slug. Ajout du champ id_docs aux slugs. Ajout d'un header et d'un footer standard pour les (inutiles) mails HTML
This commit is contained in:
parent
7a78d7b4d5
commit
728d5dcf6d
9 changed files with 225 additions and 9 deletions
|
@ -52,6 +52,7 @@ function gamumail_declarer_tables_objets_sql($tables) {
|
|||
'titre' => 'varchar(255) NOT NULL DEFAULT ""',
|
||||
'sujet' => 'varchar(255) NOT NULL DEFAULT ""',
|
||||
'texte' => 'text NOT NULL DEFAULT ""',
|
||||
'id_docs' => 'text NOT NULL DEFAULT ""',
|
||||
'statut' => 'varchar(20) DEFAULT "0" NOT NULL',
|
||||
'maj' => 'TIMESTAMP'
|
||||
),
|
||||
|
|
3
gamumail/html_footer.html
Normal file
3
gamumail/html_footer.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
</div>
|
||||
</body>
|
||||
</html>
|
12
gamumail/html_header.html
Normal file
12
gamumail/html_header.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<title>#NOM_SITE_SPIP</title>
|
||||
</head>
|
||||
<body style="background-color:rgb(255, 255, 255)">
|
||||
<div class="mail">
|
||||
[(#LOGO_SITE_SPIP|image_reduire{200})]
|
||||
<br>
|
||||
<br>
|
|
@ -29,6 +29,7 @@ function gamumail_upgrade($nom_meta_base_version, $version_cible) {
|
|||
$maj['create'] = array(array('maj_tables', array('spip_gamumails')));
|
||||
$maj['1.0.2'] = array(array('maj_tables', array('spip_gamumails')));
|
||||
$maj['1.0.5'] = array(array('creer_compte_curl'));
|
||||
$maj['1.0.6'] = array(array('maj_tables', array('spip_gamumails')));
|
||||
|
||||
function creer_compte_curl(){
|
||||
$mdp = uniqid(uniqid(),1);
|
||||
|
|
|
@ -25,7 +25,7 @@ function gamumail_TabClient($objet, $id_objet, $champ){
|
|||
**/
|
||||
|
||||
/**
|
||||
* fonction appelée en fin de gamumail_charger()
|
||||
* fonction appelée en fin de gamumail_charger_dist()
|
||||
*
|
||||
* $valeurs = array(
|
||||
* "slug" => $slug,
|
||||
|
@ -69,13 +69,20 @@ function gamumail_verifier_dist($erreurs, $options, $slug, $auteur, $Tclient, $T
|
|||
* @param string $redirect
|
||||
* @param array $options
|
||||
*
|
||||
* @return array $corps du message => $corps['html'] et $corps['texte']
|
||||
* @return array $corps
|
||||
* $corps = [
|
||||
* 'html' => $html,
|
||||
* 'texte' => $texte,
|
||||
* 'cc' => $cc,
|
||||
* 'cci' => $cci
|
||||
* ];
|
||||
*
|
||||
**/
|
||||
function gamumail_traiter_dist($corps, $options, $slug, $auteur, $Tclient, $Tpdf, $redirect) {
|
||||
|
||||
$html = $corps['html'];
|
||||
$html = str_replace('@@truc_a_remplacer@@', 'le machin qui remplace', $html);
|
||||
include_spip('classes/facteur');
|
||||
$texte = facteur_mail_html2text($html);
|
||||
$corps['html'] = $html;
|
||||
$corps['texte'] = $texte;
|
||||
|
|
170
inc/envoyer_gamumail.php
Normal file
170
inc/envoyer_gamumail.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
if (!defined('_ECRIRE_INC_VERSION')){
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* fonction pour préparer et envoyer un mail basé sur un slug gamumail
|
||||
*
|
||||
* @param string $slug
|
||||
* @param string $destinataires (éventuellement plusieurs adresses séparées par ,)
|
||||
* @param array $options (au cas où...)
|
||||
*
|
||||
**/
|
||||
function envoyer_gamumail($slug, $destinataires, $options = []) {
|
||||
include_spip('inc/texte');
|
||||
include_spip('classes/facteur');
|
||||
|
||||
$retour = array();
|
||||
|
||||
// sécu
|
||||
if (preg_match('/[^a-zA-Z0-9_\-]/', $slug)) {
|
||||
$retour['message_erreur'] = _T("gamumail:erreur_format_slug");
|
||||
return $retour;
|
||||
}
|
||||
|
||||
// contenu
|
||||
$res = sql_fetsel('*', 'spip_gamumails', 'slug = "'.$slug.'"');
|
||||
if ($res) {
|
||||
$sujet = $res('sujet');
|
||||
$html = propre($res('texte'));
|
||||
$texte = facteur_mail_html2text($html);
|
||||
$id_docs = $res['id_docs'];
|
||||
}
|
||||
else {
|
||||
$retour['message_erreur'] = _T("gamumail:pas_de_slug");
|
||||
return $retour;
|
||||
}
|
||||
|
||||
// destinataires
|
||||
$pour = explode(',', $destinataires);
|
||||
$cc = explode(',', lire_config('gamumail/mail_cc'));
|
||||
$cci = explode(',', lire_config('gamumail/mail_cci'));
|
||||
// si on a plusieurs destinataires, les passer en cci et mettre le compte expéditeur du site en to
|
||||
if (count($pour) > 1) {
|
||||
$cci = array_unique(array_merge($cci, $pour));
|
||||
$pour = [lire_config('facteur/adresse_envoi_email',lire_config('email_webmaster'))];
|
||||
}
|
||||
|
||||
// docs attachés
|
||||
function entier($val) {
|
||||
return is_integer($val);
|
||||
}
|
||||
$Tid_doc = array_filter(explode(',', $id_docs), 'entier');
|
||||
//$Tpdfs_ok = _request('Tpdfs_ok');
|
||||
|
||||
$pieces_jointes = [];
|
||||
/*
|
||||
if ($f = charger_fonction('traiter_av_pdf', 'gamumail', true)) {
|
||||
$options = $f($options, $auteur, $Tclient, $Tpdf);
|
||||
}
|
||||
if ($f = charger_fonction($slug . '_traiter_av_pdf', 'gamumail', true)) {
|
||||
$options = $f($options, $auteur, $Tclient, $Tpdf);
|
||||
}
|
||||
*/
|
||||
// les documents joints
|
||||
if (!empty($Tid_doc)) {
|
||||
foreach ($Tid_doc as $id_document) {
|
||||
$Tdocument = sql_fetsel('titre,fichier,extension','spip_documents','id_document='.intval($id_document));
|
||||
$destination = _DIR_IMG.$Tdocument['fichier'];
|
||||
$extension = $Tdocument['extension'];
|
||||
if ($Tdocument['titre']) {
|
||||
$nom_fichier = $Tdocument['titre'] .".".$extension;
|
||||
} else {
|
||||
$nom_fichier = basename($Tdocument['fichier']);
|
||||
}
|
||||
$type_mime = bigup_get_mime_type_extension($extension);
|
||||
$pieces_jointes[] = [
|
||||
'chemin' => $destination,
|
||||
'nom' => $nom_fichier,
|
||||
'encodage' => 'base64',
|
||||
'mime' => $type_mime
|
||||
];
|
||||
}
|
||||
}
|
||||
/*
|
||||
// les pdfs
|
||||
$Tpdf_dell = [];
|
||||
if (!empty($Tpdfs_ok) and is_array($Tpdfs_ok)) {
|
||||
if (array_key_exists('fichier', $Tpdf)) {
|
||||
$Tpdf = [$Tpdf];
|
||||
}
|
||||
|
||||
$recup_pdf = charger_fonction('charger_pdf','inc');
|
||||
foreach ($Tpdfs_ok as $pdf) {
|
||||
foreach ($Tpdf as $p) {
|
||||
if ($p['fichier'] === $pdf) {
|
||||
$c = $p['contexte'];
|
||||
$nom = $p['nom'];
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = $recup_pdf($pdf, $c);
|
||||
$nom_fichier = $nom.'.pdf';
|
||||
$destination = _DIR_TMP.basename($nom_fichier);
|
||||
$Tpdf_dell[] = $destination;
|
||||
file_put_contents($destination,$pdf);
|
||||
$pieces_jointes[] = [
|
||||
'chemin' => $destination,
|
||||
'nom' => $nom_fichier,
|
||||
'encodage' => 'base64',
|
||||
'mime' => 'application/pdf'
|
||||
];
|
||||
}
|
||||
}
|
||||
*/
|
||||
$html_header = '';
|
||||
if (find_in_path('gamumail/'.$slug .'_html_header.html')) {
|
||||
$html_header = recuperer_fond('gamumail/'.$slug . '_html_header', $options);
|
||||
}
|
||||
elseif(find_in_path('gamumail/html_header.html')) {
|
||||
$html_header = recuperer_fond('gamumail/html_header', $options);
|
||||
}
|
||||
$html_footer = '';
|
||||
if (find_in_path('gamumail/'.$slug . '_html_footer.html')) {
|
||||
$html_footer = recuperer_fond('gamumail/'.$slug . '_html_footer', $options);
|
||||
}
|
||||
elseif (find_in_path('gamumail/html_footer.html')) {
|
||||
$html_footer = recuperer_fond('gamumail/html_footer', $options);
|
||||
}
|
||||
$html = $html_header . $html . $html_footer;
|
||||
|
||||
$corps = [
|
||||
'html' => $html,
|
||||
'texte' => $texte,
|
||||
'cc' => $cc,
|
||||
'cci' => $cci,
|
||||
'pieces_jointes' => $pieces_jointes
|
||||
];
|
||||
|
||||
if ($f = charger_fonction('traiter', 'gamumail', true)) {
|
||||
$corps = $f($corps, $options, $slug, $auteur, $Tclient, $Tpdf, $redirect);
|
||||
}
|
||||
if ($f = charger_fonction($slug . '_traiter', 'gamumail', true)) {
|
||||
$corps = $f($corps, $options, $slug, $auteur, $Tclient, $Tpdf, $redirect);
|
||||
}
|
||||
|
||||
$envoyer_mail = charger_fonction('envoyer_mail', 'inc/');
|
||||
$ok = $envoyer_mail($pour, $sujet, $corps);
|
||||
if (!$ok) {
|
||||
spip_log("Erreur d'envoi du mail : ","gamumail");
|
||||
spip_log($corps,"roc");
|
||||
$retour['message_erreur'] = _T("gamumail:erreur_envoi_mail");
|
||||
} else {
|
||||
$retour['message_ok'] = _T('gamumail:mail_envoye');
|
||||
}
|
||||
/*
|
||||
// on supprime les pdfs temporaires
|
||||
if (count($Tpdf_dell)) {
|
||||
foreach ($Tpdf_dell as $pdf) {
|
||||
unlink($pdf);
|
||||
}
|
||||
}
|
||||
|
||||
if ($redirect) {
|
||||
$retour['redirect'] = $redirect;
|
||||
}
|
||||
*/
|
||||
|
||||
return $retour;
|
||||
}
|
|
@ -3,6 +3,9 @@
|
|||
display: inline-block;
|
||||
width: 100%;
|
||||
}
|
||||
.objet--mail {
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
.well {
|
||||
background-color: #cecece;
|
||||
margin: 10px auto;
|
||||
|
@ -53,6 +56,9 @@
|
|||
width: 2rem;
|
||||
height: 2rem;
|
||||
}
|
||||
span > em {
|
||||
font-size: 85%;
|
||||
}
|
||||
</style>
|
||||
<div class="inner configuration_mails">
|
||||
<div class="configuration_generale">
|
||||
|
@ -84,17 +90,28 @@
|
|||
|
||||
<div id="#SLUG" class="js-hidden">
|
||||
[(#AUTORISER{webmestre}|oui)
|
||||
<div class="objet--slyg">
|
||||
<div class="objet--slug">
|
||||
<strong>Slug : </strong>
|
||||
<span class="#EDIT{slug}">[(#SLUG|sinon{cliquez})]</span>
|
||||
<span class="#EDIT{slug}">[(#SLUG|sinon{Double clic pour éditer})]</span>
|
||||
</div>
|
||||
]
|
||||
<div class="objet--mail">
|
||||
<strong>Objet : </strong>
|
||||
<span class="#EDIT{sujet}">[(#SUJET|sinon{cliquez})]</span>
|
||||
<span class="#EDIT{sujet}">[(#SUJET|sinon{Double clic pour éditer})]</span>
|
||||
</div>
|
||||
<div class="objet--mail">
|
||||
<strong>Message : </strong>
|
||||
<div class="texte #EDIT{texte}">
|
||||
[(#TEXTE|sinon{Double clic pour éditer})]
|
||||
</div>
|
||||
</div>
|
||||
<div class="objet--mail">
|
||||
<span>Documents attachés : <em class="explication">liste d'id_document séparés par une virgule , </em></span>
|
||||
<div class="texte #EDIT{id_docs}">
|
||||
[(#ID_DOCS|sinon{Double clic pour éditer})]
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<strong>Message : </strong>
|
||||
<div class="texte #EDIT{texte}">[(#TEXTE|sinon{cliquez})]</div>
|
||||
[(#REM)
|
||||
Pour l'instant, inutile
|
||||
<div class="pdfs">
|
||||
|
|
|
@ -20,6 +20,8 @@ $GLOBALS[$GLOBALS['idx_lang']] = array(
|
|||
//EE
|
||||
'envoyer' => 'Envoyer',
|
||||
"erreur_envoi_mail" => "Erreur dans l'envoi de votre mail",
|
||||
'erreur_format_slug' => 'Le slug est un identifiant qui ne peut contenir que des chiffres, lettres et _ ou -',
|
||||
|
||||
|
||||
// I
|
||||
'icone_creer_gamumail' => 'Créer un gamumail',
|
||||
|
@ -32,6 +34,9 @@ $GLOBALS[$GLOBALS['idx_lang']] = array(
|
|||
//MM
|
||||
"mail_envoye" => "Votre message a bien été envoyé",
|
||||
|
||||
// P
|
||||
'pas_de_slug' => 'Pas de slug avec cet identifiant',
|
||||
|
||||
// R
|
||||
'retirer_lien_gamumail' => 'Retirer ce gamumail',
|
||||
'retirer_tous_liens_gamumails' => 'Retirer tous les gamumails',
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<paquet
|
||||
prefix="gamumail"
|
||||
categorie="communication"
|
||||
version="1.0.6"
|
||||
version="1.0.7"
|
||||
etat="dev"
|
||||
compatibilite="[3.2.0;3.3.*]"
|
||||
logo="prive/themes/spip/images/gamumail-64.png"
|
||||
documentation=""
|
||||
schema="1.0.5"
|
||||
schema="1.0.6"
|
||||
>
|
||||
|
||||
<nom>GamuMail</nom>
|
||||
|
|
Loading…
Add table
Reference in a new issue