I wanted to release a new version with:
- the add of new ’emailTitle’ parameter and placeholder
- the add of new ’defaultEmailTitle’ variable
- the update of defaultFormText : modify /n to
- the add of ann <a> tag for a clickable referer link
BUt I have a problem with the insertion of the <a> tag !!
When I put :
// form first vue [+idpage+]
if(!isset($_POST['ok'])) {
$myForm = str_replace("[+alarme+]", "", $myForm);
$myForm = str_replace("[+message+]", $defaultFormText.' <a href="'.$_SERVER['HTTP_REFERER'].'" >'.$_SERVER['HTTP_REFERER'].'</a>', $myForm);
The a tag is filtered and in the mail body I have : <a rel="nofollow">
http://www.mysite.com</a>
I have only tested it with a 0.9.2.1 and with a yahoo box.
If someone can test it with the 0.9.5 it will be nice.
Here the new snippet code :
/*
* Name: Sendtoafriend
* Version: 0.3
* Author: Laurent Carbonnel
* Form check system based on a Moon idea
* Updated: September 24, 2006
*
* Description:
* Add a "Send to a friend" link and form
*
* Instruction:
* Create a new snippet named "Sendtoafriend"
* Copy/Paste the code of the Sendtoafriend_0.2.txt file in it
* Create a new snippet named "AddpopupLink"
* Copy/Paste the code of the AddpopupLink_1.0.txt file in it
* Create a new template name "pop" and copy/paste the code of the poptpl.txt file
* Create a new chunk name "STFform" and copy/paste the code of the STFform_chunk.txt file
* Create a new chunk name "STFemail" and copy/paste the code of the STFemail_chunk.txt file (use a erreurForm style for test errors)
* Create a new chunk name "STFemailOK" and copy/paste the code of the STFemailOK_chunk.txt file
* Create a new page and insert the Sendtoafriend snippet inside (uncheck the "in menu" option) //It's the form page
* Insert the AddpopupLink snippet in the pages you want with the id of the page who content the Sendtoafriend snippet for parameter &destpageidAPL
* AddpopupLink exemple use : [[AddpopupLink? &destpageidAPL=`5` &widthpopAPL=`400` &heightpopAPL=`270` &textlabelAPLlink=`Send to a friend`]]
*
* Parameters :
* &tpl : form chunk name (required)
* &gab : email html template name (see STFemail.txt) (required)
* &object : email object (optional)
* &emailTitle : email title to use with the [+emailTitle+] placeholder tag in STFemail chunk (optional)
* use one of this 2 parameters :
* &emailok : aftersend chunk name (use this parameter
* &pagenext : aftersend page id redirection
* Exemples of use :
* [!Sendtoafriend? &tpl=`MyChunkForm` &gab=`MyChunkEmail` &emailok=`MyChunkEmailOK` &object=`My object` &pagenext=`redirection page id` !]
*
* [!Sendtoafriend? &tpl=`STFform` &gab=`STFemail` &pagenext=`4` &object=`a friend send you this message`!]
* [!Sendtoafriend? &tpl=`STFform` &gab=`STFemail` &emailok=`STFemailOK` &object=`a friend send you this message`!]
ADD :
- add $emailTitle parameter and placeholder ok
- Modify $defaultFormText OK
- add a <a> tag to $_SERVER['HTTP_REFERER'] not working
*/
/* CORE DEFAULT PARAMETERS */
$defaultFormText = 'Hello, I think this page would interest you : <br/>';
$defaultObject = 'An email from'.$_POST['nom'];
$defaultEmailTitle = 'MESSAGE from '.$_POST['nom'];
/* CORE DEFAULT PARAMETERS */
// Form and email getting chunk
if ($tpl) $tpl = ($chunk = $modx->getChunk($tpl)) ? $chunk:"Chunk '$tpl' not found.";
if ($gab) $gab = ($chunk = $modx->getChunk($gab)) ? $chunk:"Chunk '$gab' not found.";
if(!isset($emailok) && !isset($pagenext)){
return "!! NO REDIRECTION !! Snippet need one of these parameters : &emailok or &pagenext";
}
else {
$objet = (isset($object))? $object : $defaultObject;
$titreEmail = (isset($emailTitle))? $emailTitle : $defaultEmailTitle;
if(trim($emailok) != ""){
$pagenext = $emailok;
}
// Construction du formulaire
$output = doForm($tpl,$gab,$objet,$pagenext,$defaultFormText,$titreEmail);
// Output
return $output;
}
// **** functions definitions **** //
function erreurForm(){
global $erreur;
$erreur['NOM'] = empty($_POST['nom']);
$erreur['NOMAMI'] = empty($_POST['nomami']);
$erreur['EMAILAMI'] = !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $_POST['emailami']) ;
$erreur['EMAIL'] = !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $_POST['email']) ;
$erreur['MESSAGE'] = empty($_POST['message']);
return $erreur['NOM'] || $erreur['NOMAMI'] || $erreur['EMAIL'] || $erreur['EMAILAMI'] || $erreur['MESSAGE'];
}
// Form
function doForm($myForm,$GabMail,$Object,$pageredirect,$defaultFormText,$titreEmail) {
global $modx, $erreur ;
// form first vue [+idpage+]
if(!isset($_POST['ok'])) {
$myForm = str_replace("[+alarme+]", "", $myForm);
$myForm = str_replace("[+message+]", $defaultFormText.' <a href="'.$_SERVER['HTTP_REFERER'].'" >'.$_SERVER['HTTP_REFERER'].'</a>', $myForm);
return $myForm;
// Form validation
}
else {
// errors
if (erreurForm()){
$myForm = str_replace("[+alarme+]", "Modify fields in red", $myForm);
$myForm = str_replace("[+nom+]", $_POST['nom'],$myForm);
$myForm = str_replace("[+nomami+]", $_POST['nomami'],$myForm);
$myForm = str_replace("[+email+]", $_POST['email'],$myForm);
$myForm = str_replace("[+emailami+]", $_POST['emailami'],$myForm);
$myForm = str_replace("[+message+]", stripslashes($_POST['message']),$myForm);
$myForm= str_replace("[+classe_nom+]", ($erreur['NOM'] ? 'erreurForm' : 'normal'), $myForm);
$myForm= str_replace("[+classe_nomami+]", ($erreur['NOMAMI'] ? 'erreurForm' : 'normal'), $myForm);
$myForm= str_replace("[+classe_email+]", ($erreur['EMAIL'] ? 'erreurForm' : 'normal'), $myForm);
$myForm= str_replace("[+classe_emailami+]", ($erreur['EMAILAMI'] ? 'erreurForm' : 'normal'), $myForm);
$myForm= str_replace("[+classe_message+]", ($erreur['MESSAGE'] ? 'erreurForm' : 'normal'), $myForm);
$myForm = str_replace("[+idpage+]", $_GET['linkid'], $myForm);
return $myForm;
}
else {// all ok
$corpsmessage = $GabMail;
$corpsmessage = str_replace("[+emailTitle+]", $titreEmail,$corpsmessage);
$corpsmessage = str_replace("[+nom+]", $_POST['nom'],$corpsmessage);
$corpsmessage = str_replace("[+nomami+]", $_POST['nomami'],$corpsmessage);
$corpsmessage = str_replace("[+message+]", stripslashes(str_replace ( "\n", "<br>", $_POST['message'])),$corpsmessage);
$email_exp = $_POST['email'];
$entetedate = date("D, j M Y H:i:s -0600");
$entetemail = "From: $email_exp \n";
$entetemail .= "Cc: ";
$entetemail .= " \n";
$entetemail .= "Bcc: \n";
$entetemail .= "Reply-To: $email_exp \n";
$entetemail .= "X-Mailer: PHP/" . phpversion() . "\n" ;
$entetemail .= "Content-Type: text/html;charset=iso-8859-1"."\n" ;
$entetemail .= "Date: $entetedate";
$destMail = $_POST['emailami'];
mail($destMail,$Object,$corpsmessage,$entetemail);
if(is_numeric($pageredirect)){
$modx->sendRedirect($modx->makeUrl($pageredirect)); // page redirection
}
else { // emailOK chunk
$output = $modx->getChunk($pageredirect);
return $output;
}
}
}
}