Maian Friend is a simple ‘Tell a Friend’ script. This is a simple script for the people who believe they have some value. Easy to use ‘Tell a Friend’ script for your website. -Lets your visitors send up to 6 recommendations by default. More can be added by editing the template file. -Removes duplicate e-mail addresses. -Default message gets sent if no comments are entered.-Optional ‘Thank You’ message to visitor. -Optional report sent to webmaster. -Captcha code for spam prevention (Optional). -E-mail templates. -Uses savant template engine.
<?php
/*
Maian Friend v3.0
Written by David Ian Bennett
http://www.maianscriptworld.co.uk
*/
// Set error reporting level..
// Comment out for debugging..
error_reporting(0);
// Set paths..
define ('FOLDER_PATH', dirname(__FILE__).'/');
define ('INC',1);
// Load captcha..
if (isset($_GET['captcha'])) {
include (FOLDER_PATH.'captcha/securimage.php');
$img = new securimage();
$img->show();
exit;
}
// Include files...
include(FOLDER_PATH.'control/config.inc.php');
include(FOLDER_PATH.'lang/'.LANGFILE);
include(FOLDER_PATH.'control/functions.inc.php');
include(FOLDER_PATH.'classes/class_mail.inc.php');
include(FOLDER_PATH.'control/Savant2.php');
// Firstly, check for banned IP address..
if (ENABLE_IP_BANNING) {
if (file_exists(FOLDER_PATH.'control/ip_addresses.txt')) {
$file = array_map('trim',file(FOLDER_PATH.'control/ip_addresses.txt'));
if (!empty($file) && in_array(ipAddress(),$file)) {
$tpl = new Savant2();
$tpl->assign('CHARSET', $msg_charset);
$tpl->assign('TITLE', str_replace('{website}',WEBSITE_NAME,$msg_header));
$tpl->assign('MSG', $msg_other2);
$tpl->assign('FOOTER', $msg_footer);
$tpl->display('templates/ip_banned.tpl.php');
exit;
}
}
}
// Initiate settings class and load vars..
$MAIL = new mailClass();
$MAIL->smtp = ENABLE_SMTP;
$MAIL->smtp_host = SMTP_HOST;
$MAIL->smtp_user = SMTP_USER;
$MAIL->smtp_pass = SMTP_PASS;
$MAIL->smtp_port = SMTP_PORT;
$MAIL->html = ENABLE_HTML;
$formMessage = array();
$goodFriends = array();
// Process form..
if (isset($_POST['process'])) {
// Clean post vars..removes harmful tags..
// Applies callback element to all post values..
$_POST = multiDimensionalArrayMap('cleanEvilTags',$_POST);
// If enabled, check flood time...
// If this returns error, no other processing is necessary..
if (FLOOD_CONTROL>0 && checkFlood()) {
$formMessage[] = $msg_index23;
$flood = true;
}
if (!isset($flood)) {
// Clear flood coookie..
if (isset($_COOKIE[md5(FLOOD_COOKIE_NAME)])) {
setcookie(md5(FLOOD_COOKIE_NAME), '');
}
// Check name..
if ($_POST['name']=='') {
$formMessage[] = $msg_index15;
}
// Check e-mail..
if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['email'])) {
$formMessage[] = $msg_index16;
}
// Check friend fields for some input..
for ($i=0; $i<$_POST['num']; $i++) {
if ($_POST['f_name'][$i]!='' || $_POST['f_email'][$i]!='') {
$dataEntry = true;
}
}
// Display error is no friend input..
if (!isset($dataEntry)) {
$formMessage[] = $msg_index22;
} else {
// Now check name/valid e-mail combo`s..
for ($i=0; $i<$_POST['num']; $i++) {
if ($_POST['f_name'][$i]!='' || $_POST['f_email'][$i]!='') {
if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['f_email'][$i])) {
$dataInvalid = true;
}
}
// Load good data into array..
if ($_POST['f_email'][$i]!='' && preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['f_email'][$i])) {
$goodFriends[] = ($_POST['f_name'][$i] ? $_POST['f_name'][$i] : $_POST['f_email'][$i]).'##'.$_POST['f_email'][$i];
}
}
}
// Display error for invalid data..
if (isset($dataInvalid)) {
$formMessage[] = $msg_index21;
}
// Check comments..
if ($_POST['comments']=='') {
$formMessage[] = $msg_index20;
}
// Check captcha code..
if (ENABLE_CAPTCHA) {
include(FOLDER_PATH.'captcha/securimage.php');
$img = new Securimage();
$valid = $img->check($_POST['code']);
if($valid == false) {
$formMessage[] = $msg_index17;
}
}
// Are we ok so far?
if (empty($formMessage)) {
// E-mail tags..
$MAIL->addTag('{WEBSITE_NAME}', WEBSITE_NAME);
$MAIL->addTag('{HOMEPAGE}', HOMEPAGE);
$MAIL->addTag('{IP}', ipAddress());
$MAIL->addTag('{DATE}', date("j F Y"));
$MAIL->addTag('{NAME}', $_POST['name']);
$MAIL->addTag('{EMAIL}', $_POST['email']);
$MAIL->addTag('{COMMENTS}', (ENABLE_HTML ? nl2br($_POST['comments']) : $_POST['comments']));
$MAIL->addTag('{RECIPIENTS}', loadRecipients());
// If enabled, send e-mail to webmaster...
if (EMAIL_WEBMASTER) {
$MAIL->sendMail(WEBSITE_NAME,
EMAIL_ADDRESS,
WEBSITE_NAME,
EMAIL_ADDRESS,
str_replace('{website}',WEBSITE_NAME,$msg_subject),
$MAIL->template(FOLDER_PATH.'templates/email/webmaster.txt')
);
}
// Send to recipients...
$goodFriends = array_unique($goodFriends);
$MAIL->sendMail('', // Not used..
$goodFriends,
$_POST['name'],
$_POST['email'],
str_replace(array('{website}','{sender}'),array(WEBSITE_NAME,$_POST['name']),$msg_subject3),
$MAIL->template(FOLDER_PATH.'templates/email/friend.txt')
);
// If enabled, send thank you message..
if (EMAIL_VISITOR) {
$MAIL->sendMail($_POST['name'],
$_POST['email'],
WEBSITE_NAME,
EMAIL_ADDRESS,
str_replace('{website}',WEBSITE_NAME,$msg_subject2),
$MAIL->template(FOLDER_PATH.'templates/email/thanks.txt')
);
}
// Set flood coookie..
if (FLOOD_CONTROL>0) {
setcookie(md5(FLOOD_COOKIE_NAME), time(), time()+60*60*24*30);
}
// Clear form fields..
$_POST = multiDimensionalArrayMap('trim',$_POST,true);
// Add thanks message to array..
$formMessage[] = $msg_index25;
// Set var..
$formSent = true;
}
}
}
// Render HTML boxes..
$renderHTML = '';
$loadCaptcha = '';
for ($i=1; $i<=MAX_FIELDS; $i++) {
$find = array('{id}','{display}','{friend_name}','{friend_value}','{friend_email}','{email_value}');
$replace = array($i,($i<=MIN_FIELDS ? '' : ' style="display:none"'),
$msg_index13,(isset($_POST['f_name'][$i-1]) ? cleanData($_POST['f_name'][$i-1]) : ''),
$msg_index14,(isset($_POST['f_email'][$i-1]) ? cleanData($_POST['f_email'][$i-1]) : '')
);
$renderHTML .= str_replace($find,$replace,file_get_contents(FOLDER_PATH.'templates/html/friend_boxes.tpl'));
}
// Is captcha enabled?
if (ENABLE_CAPTCHA) {
$find = array('{text}','{enter_code}');
$replace = array($msg_index9,$msg_index10);
$loadCaptcha .= str_replace($find,$replace,file_get_contents(FOLDER_PATH.'templates/html/captcha.tpl'));
}
// Load templates..
include(FOLDER_PATH.'control/header.inc.php');
$tpl = new Savant2();
$tpl->assign('DISPLAY_MSG', (!empty($formMessage) ? showDisplayMessage($formMessage,(isset($formSent) ? true : false)) : ''));
$tpl->assign('CAPTCHA', $loadCaptcha);
$tpl->assign('MSG', $msg_index);
$tpl->assign('MAX', MAX_FIELDS);
$tpl->assign('MIN', MIN_FIELDS);
$tpl->assign('ENTER_YOUR_DETAILS', $msg_index2);
$tpl->assign('NAME', $msg_index3);
$tpl->assign('NAME_VALUE', (isset($_POST['name']) ? htmlentities(cleanData($_POST['name'])) : ''));
$tpl->assign('EMAIL_ADDRESS', $msg_index4);
$tpl->assign('EMAIL_ADDRESS_VALUE', (isset($_POST['email']) ? htmlentities(cleanData($_POST['email'])) : ''));
$tpl->assign('ENTER_COMMENTS', $msg_index18);
$tpl->assign('COMMENTS', $msg_index19);
$tpl->assign('COMMENTS_VALUE', (isset($_POST['comments']) ? htmlentities(cleanData($_POST['comments'])) : loadDefaultMessage()));
$tpl->assign('ADD_FIELD', $msg_index5);
$tpl->assign('REMOVE_FIELD', $msg_index6);
$tpl->assign('ENTER_FRIENDS_DETAILS', str_replace('{max}',MAX_FIELDS,$msg_index7));
$tpl->assign('FRIEND_FIELDS', $renderHTML);
$tpl->assign('SEND_MESSAGE', $msg_index8);
$tpl->display('templates/index.tpl.php');
include(FOLDER_PATH.'control/footer.inc.php');
?>
&nbsp;
/*
Maian Friend v3.0
Written by David Ian Bennett
http://www.maianscriptworld.co.uk
*/
// Set error reporting level..
// Comment out for debugging..
error_reporting(0);
// Set paths..
define ('FOLDER_PATH', dirname(__FILE__).'/');
define ('INC',1);
// Load captcha..
if (isset($_GET['captcha'])) {
include (FOLDER_PATH.'captcha/securimage.php');
$img = new securimage();
$img->show();
exit;
}
// Include files...
include(FOLDER_PATH.'control/config.inc.php');
include(FOLDER_PATH.'lang/'.LANGFILE);
include(FOLDER_PATH.'control/functions.inc.php');
include(FOLDER_PATH.'classes/class_mail.inc.php');
include(FOLDER_PATH.'control/Savant2.php');
// Firstly, check for banned IP address..
if (ENABLE_IP_BANNING) {
if (file_exists(FOLDER_PATH.'control/ip_addresses.txt')) {
$file = array_map('trim',file(FOLDER_PATH.'control/ip_addresses.txt'));
if (!empty($file) && in_array(ipAddress(),$file)) {
$tpl = new Savant2();
$tpl->assign('CHARSET', $msg_charset);
$tpl->assign('TITLE', str_replace('{website}',WEBSITE_NAME,$msg_header));
$tpl->assign('MSG', $msg_other2);
$tpl->assign('FOOTER', $msg_footer);
$tpl->display('templates/ip_banned.tpl.php');
exit;
}
}
}
// Initiate settings class and load vars..
$MAIL = new mailClass();
$MAIL->smtp = ENABLE_SMTP;
$MAIL->smtp_host = SMTP_HOST;
$MAIL->smtp_user = SMTP_USER;
$MAIL->smtp_pass = SMTP_PASS;
$MAIL->smtp_port = SMTP_PORT;
$MAIL->html = ENABLE_HTML;
$formMessage = array();
$goodFriends = array();
// Process form..
if (isset($_POST['process'])) {
// Clean post vars..removes harmful tags..
// Applies callback element to all post values..
$_POST = multiDimensionalArrayMap('cleanEvilTags',$_POST);
// If enabled, check flood time...
// If this returns error, no other processing is necessary..
if (FLOOD_CONTROL>0 && checkFlood()) {
$formMessage[] = $msg_index23;
$flood = true;
}
if (!isset($flood)) {
// Clear flood coookie..
if (isset($_COOKIE[md5(FLOOD_COOKIE_NAME)])) {
setcookie(md5(FLOOD_COOKIE_NAME), '');
}
// Check name..
if ($_POST['name']=='') {
$formMessage[] = $msg_index15;
}
// Check e-mail..
if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['email'])) {
$formMessage[] = $msg_index16;
}
// Check friend fields for some input..
for ($i=0; $i<$_POST['num']; $i++) {
if ($_POST['f_name'][$i]!='' || $_POST['f_email'][$i]!='') {
$dataEntry = true;
}
}
// Display error is no friend input..
if (!isset($dataEntry)) {
$formMessage[] = $msg_index22;
} else {
// Now check name/valid e-mail combo`s..
for ($i=0; $i<$_POST['num']; $i++) {
if ($_POST['f_name'][$i]!='' || $_POST['f_email'][$i]!='') {
if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['f_email'][$i])) {
$dataInvalid = true;
}
}
// Load good data into array..
if ($_POST['f_email'][$i]!='' && preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST['f_email'][$i])) {
$goodFriends[] = ($_POST['f_name'][$i] ? $_POST['f_name'][$i] : $_POST['f_email'][$i]).'##'.$_POST['f_email'][$i];
}
}
}
// Display error for invalid data..
if (isset($dataInvalid)) {
$formMessage[] = $msg_index21;
}
// Check comments..
if ($_POST['comments']=='') {
$formMessage[] = $msg_index20;
}
// Check captcha code..
if (ENABLE_CAPTCHA) {
include(FOLDER_PATH.'captcha/securimage.php');
$img = new Securimage();
$valid = $img->check($_POST['code']);
if($valid == false) {
$formMessage[] = $msg_index17;
}
}
// Are we ok so far?
if (empty($formMessage)) {
// E-mail tags..
$MAIL->addTag('{WEBSITE_NAME}', WEBSITE_NAME);
$MAIL->addTag('{HOMEPAGE}', HOMEPAGE);
$MAIL->addTag('{IP}', ipAddress());
$MAIL->addTag('{DATE}', date("j F Y"));
$MAIL->addTag('{NAME}', $_POST['name']);
$MAIL->addTag('{EMAIL}', $_POST['email']);
$MAIL->addTag('{COMMENTS}', (ENABLE_HTML ? nl2br($_POST['comments']) : $_POST['comments']));
$MAIL->addTag('{RECIPIENTS}', loadRecipients());
// If enabled, send e-mail to webmaster...
if (EMAIL_WEBMASTER) {
$MAIL->sendMail(WEBSITE_NAME,
EMAIL_ADDRESS,
WEBSITE_NAME,
EMAIL_ADDRESS,
str_replace('{website}',WEBSITE_NAME,$msg_subject),
$MAIL->template(FOLDER_PATH.'templates/email/webmaster.txt')
);
}
// Send to recipients...
$goodFriends = array_unique($goodFriends);
$MAIL->sendMail('', // Not used..
$goodFriends,
$_POST['name'],
$_POST['email'],
str_replace(array('{website}','{sender}'),array(WEBSITE_NAME,$_POST['name']),$msg_subject3),
$MAIL->template(FOLDER_PATH.'templates/email/friend.txt')
);
// If enabled, send thank you message..
if (EMAIL_VISITOR) {
$MAIL->sendMail($_POST['name'],
$_POST['email'],
WEBSITE_NAME,
EMAIL_ADDRESS,
str_replace('{website}',WEBSITE_NAME,$msg_subject2),
$MAIL->template(FOLDER_PATH.'templates/email/thanks.txt')
);
}
// Set flood coookie..
if (FLOOD_CONTROL>0) {
setcookie(md5(FLOOD_COOKIE_NAME), time(), time()+60*60*24*30);
}
// Clear form fields..
$_POST = multiDimensionalArrayMap('trim',$_POST,true);
// Add thanks message to array..
$formMessage[] = $msg_index25;
// Set var..
$formSent = true;
}
}
}
// Render HTML boxes..
$renderHTML = '';
$loadCaptcha = '';
for ($i=1; $i<=MAX_FIELDS; $i++) {
$find = array('{id}','{display}','{friend_name}','{friend_value}','{friend_email}','{email_value}');
$replace = array($i,($i<=MIN_FIELDS ? '' : ' style="display:none"'),
$msg_index13,(isset($_POST['f_name'][$i-1]) ? cleanData($_POST['f_name'][$i-1]) : ''),
$msg_index14,(isset($_POST['f_email'][$i-1]) ? cleanData($_POST['f_email'][$i-1]) : '')
);
$renderHTML .= str_replace($find,$replace,file_get_contents(FOLDER_PATH.'templates/html/friend_boxes.tpl'));
}
// Is captcha enabled?
if (ENABLE_CAPTCHA) {
$find = array('{text}','{enter_code}');
$replace = array($msg_index9,$msg_index10);
$loadCaptcha .= str_replace($find,$replace,file_get_contents(FOLDER_PATH.'templates/html/captcha.tpl'));
}
// Load templates..
include(FOLDER_PATH.'control/header.inc.php');
$tpl = new Savant2();
$tpl->assign('DISPLAY_MSG', (!empty($formMessage) ? showDisplayMessage($formMessage,(isset($formSent) ? true : false)) : ''));
$tpl->assign('CAPTCHA', $loadCaptcha);
$tpl->assign('MSG', $msg_index);
$tpl->assign('MAX', MAX_FIELDS);
$tpl->assign('MIN', MIN_FIELDS);
$tpl->assign('ENTER_YOUR_DETAILS', $msg_index2);
$tpl->assign('NAME', $msg_index3);
$tpl->assign('NAME_VALUE', (isset($_POST['name']) ? htmlentities(cleanData($_POST['name'])) : ''));
$tpl->assign('EMAIL_ADDRESS', $msg_index4);
$tpl->assign('EMAIL_ADDRESS_VALUE', (isset($_POST['email']) ? htmlentities(cleanData($_POST['email'])) : ''));
$tpl->assign('ENTER_COMMENTS', $msg_index18);
$tpl->assign('COMMENTS', $msg_index19);
$tpl->assign('COMMENTS_VALUE', (isset($_POST['comments']) ? htmlentities(cleanData($_POST['comments'])) : loadDefaultMessage()));
$tpl->assign('ADD_FIELD', $msg_index5);
$tpl->assign('REMOVE_FIELD', $msg_index6);
$tpl->assign('ENTER_FRIENDS_DETAILS', str_replace('{max}',MAX_FIELDS,$msg_index7));
$tpl->assign('FRIEND_FIELDS', $renderHTML);
$tpl->assign('SEND_MESSAGE', $msg_index8);
$tpl->display('templates/index.tpl.php');
include(FOLDER_PATH.'control/footer.inc.php');
?>
&nbsp;