290 lines
8.0 KiB
PHP
290 lines
8.0 KiB
PHP
<?php
|
|
|
|
//response generation function
|
|
|
|
$response = "";
|
|
|
|
//function to generate response
|
|
function my_contact_form_generate_response($type, $message){
|
|
|
|
global $response;
|
|
|
|
if($type == "success") $response = "<div class='success'>{$message}</div>";
|
|
else $response = "<div class='error'>{$message}</div>";
|
|
|
|
}
|
|
|
|
//http://www.binarymoon.co.uk/2010/03/akismet-plugin-theme-stop-spam-dead/
|
|
|
|
function bm_checkSpam ($content) {
|
|
|
|
// innocent until proven guilty
|
|
$isSpam = FALSE;
|
|
|
|
$content = (array) $content;
|
|
|
|
if (function_exists('akismet_init')) {
|
|
|
|
$wpcom_api_key = get_option('wordpress_api_key');
|
|
|
|
if (!empty($wpcom_api_key)) {
|
|
|
|
global $akismet_api_host, $akismet_api_port;
|
|
|
|
// set remaining required values for akismet api
|
|
$content['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
|
|
$content['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
|
|
$content['referrer'] = $_SERVER['HTTP_REFERER'];
|
|
$content['blog'] = get_option('home');
|
|
|
|
if (empty($content['referrer'])) {
|
|
$content['referrer'] = get_permalink();
|
|
}
|
|
|
|
$queryString = '';
|
|
|
|
foreach ($content as $key => $data) {
|
|
if (!empty($data)) {
|
|
$queryString .= $key . '=' . urlencode(stripslashes($data)) . '&';
|
|
}
|
|
}
|
|
//echo $queryString;
|
|
|
|
$response = akismet_http_post($queryString, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
|
|
|
|
if ($response[1] == 'true') {
|
|
update_option('akismet_spam_count', get_option('akismet_spam_count') + 1);
|
|
$isSpam = TRUE;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $isSpam;
|
|
|
|
}
|
|
|
|
//response messages
|
|
$not_human = __( "Human verification incorrect.", 'twentyten-child' );
|
|
$missing_content = __( "Please supply all information.", 'twentyten-child' );
|
|
$email_invalid = __( "Email Address Invalid.", 'twentyten-child' );
|
|
$message_unsent = __( "Message was not sent. Try Again.", 'twentyten-child' );
|
|
$message_sent = __( "Thanks! Your message has been sent.", 'twentyten-child' );
|
|
$message_spam = __( "SPAM !!!", 'twentyten-child' );
|
|
|
|
//user posted variables
|
|
$name = $_POST['message_name'];
|
|
$email = $_POST['message_email'];
|
|
$message = $_POST['message_text'];
|
|
$human = $_POST['message_human'];
|
|
$website = "";
|
|
|
|
$content['comment_author'] = $name;
|
|
$content['comment_author_email'] = $email;
|
|
$content['comment_author_url'] = $website;
|
|
$content['comment_content'] = $message;
|
|
//print_r($content);
|
|
/*
|
|
if (bm_checkSpam ($content)) {
|
|
// stuff here
|
|
echo "spam !!";
|
|
}
|
|
else {
|
|
echo "No spam !!";
|
|
}
|
|
*/
|
|
|
|
//php mailer variables
|
|
$to = get_option('admin_email');
|
|
//$subject = "Someone sent a message from ".get_bloginfo('name');
|
|
$subject = __( "Someone sent a message from ", 'twentyten-child' ).get_bloginfo('name');
|
|
$headers = 'From: '. $email . "\r\n" .
|
|
'Reply-To: ' . $email . "\r\n";
|
|
|
|
if(!$human == 0){
|
|
|
|
if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
|
|
|
|
else { //human!
|
|
|
|
//validate email
|
|
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
|
|
my_contact_form_generate_response("error", $email_invalid);
|
|
else //email is valid
|
|
{
|
|
//validate presence of name and message
|
|
if(empty($name) || empty($message)){
|
|
my_contact_form_generate_response("error", $missing_content);
|
|
}
|
|
else
|
|
{
|
|
// spam
|
|
if (bm_checkSpam ($content)) {
|
|
my_contact_form_generate_response("error", $message_spam);
|
|
}
|
|
else { //ready to go!
|
|
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
|
|
if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
|
|
else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
|
|
|
|
?>
|
|
|
|
<?php get_header(); ?>
|
|
|
|
<div id="container2">
|
|
<div id="content2" role="main">
|
|
|
|
<?php while ( have_posts() ) : the_post(); ?>
|
|
|
|
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
|
|
|
<header class="entry-header">
|
|
<h1 class="entry-title"><?php the_title(); ?></h1>
|
|
</header>
|
|
|
|
<div class="entry-content">
|
|
<?php the_content(); ?>
|
|
|
|
<style type="text/css">
|
|
.error{
|
|
padding: 5px 9px;
|
|
border: 1px solid red;
|
|
color: red;
|
|
border-radius: 3px;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.success{
|
|
padding: 5px 9px;
|
|
border: 1px solid green;
|
|
color: green;
|
|
border-radius: 3px;
|
|
margin-bottom: 30px;
|
|
}
|
|
/*
|
|
form span{
|
|
color: red;
|
|
}*/
|
|
#first{
|
|
width:400px;
|
|
height:610px;
|
|
box-shadow:0 0 15px rgba(14,41,57,0.12),0 2px 5px rgba(14,41,57,0.44),inset 0 -1px 2px rgba(14,41,57,0.15);
|
|
float:left;
|
|
padding:50px 50px 0;
|
|
/*background-image:url(../images/1.jpg);*/
|
|
margin:2% 30%;
|
|
border-radius:5px
|
|
}
|
|
|
|
span{
|
|
float:left;
|
|
margin-top:8px;
|
|
/*margin-left:8px;*/
|
|
font-size:17px
|
|
}
|
|
.one{
|
|
display:block;
|
|
margin-left:22px;
|
|
margin-top:10px
|
|
}
|
|
.two{
|
|
display:block;
|
|
margin-left:27px;
|
|
margin-top:10px
|
|
}
|
|
.three{
|
|
display:block;
|
|
margin-left:-10px;
|
|
margin-top:10px
|
|
}
|
|
.four{
|
|
display:block;
|
|
margin-left:-10px;
|
|
margin-top:10px
|
|
}
|
|
input.email, input.name{
|
|
width:300px;
|
|
padding:6px;
|
|
border-radius:5px;
|
|
border:1px solid #cbcbcb;
|
|
box-shadow:inset 0 1px 2px rgba(0,0,0,0.18);
|
|
font-family:Cursive
|
|
}
|
|
input.verif{
|
|
width: 30px;
|
|
text-align:center;
|
|
padding:6px;
|
|
border-radius:5px;
|
|
border:1px solid #cbcbcb;
|
|
box-shadow:inset 0 1px 2px rgba(0,0,0,0.18);
|
|
}
|
|
textarea{
|
|
width:300px;
|
|
padding:7px;
|
|
height:100px;
|
|
border-radius:5px;
|
|
border:1px solid #cbcbcb;
|
|
box-shadow:inset 0 1px 2px rgba(0,0,0,0.18)
|
|
}
|
|
input.submit{
|
|
width:100px;
|
|
margin-left:283px;
|
|
padding:10px;
|
|
margin-top:20px;
|
|
background:linear-gradient(#A4A4A4,#424242);
|
|
color:#fff !important;
|
|
font-weight:700
|
|
border-radius:5px !important;
|
|
border:1px solid #cbcbcb;
|
|
}
|
|
.submit:hover{
|
|
background:linear-gradient(#424242,#A4A4A4)
|
|
}
|
|
.star{
|
|
font-style: italic;
|
|
color: #9a9a9a;
|
|
}
|
|
</style>
|
|
|
|
<div id="first">
|
|
<?php echo $response; ?>
|
|
<form action="<?php the_permalink(); ?>" method="post">
|
|
|
|
<label for="name" class="one"><span><?php _e('Name', 'twentyten-child' ); ?>: </span>*
|
|
<input type="text" name="message_name" placeholder="<?php _e('Your name', 'twentyten-child' ); ?>" class="name" value="<?php echo esc_attr($_POST['message_name']); ?>"></label>
|
|
|
|
<label for="message_email" class="two"><span><?php _e('Email', 'twentyten-child' ); ?>: </span>*
|
|
<input type="text" name="message_email" placeholder="<?php _e('Your email', 'twentyten-child' ); ?>" class="email" value="<?php echo esc_attr($_POST['message_email']); ?>"></label>
|
|
|
|
<label for="message_text" class="three"><span><?php _e('Message', 'twentyten-child' ); ?>: </span>*
|
|
<textarea type="text" name="message_text" placeholder="<?php _e('Your Message...', 'twentyten-child' ); ?>" class="text"><?php echo esc_textarea($_POST['message_text']); ?></textarea></label>
|
|
|
|
<label for="message_human" class="four"><span><?php _e('Human ?', 'twentyten-child' ); ?>: </span>*
|
|
<input type="text" class="verif" name="message_human"> + 3 = 5</label>
|
|
|
|
<input type="hidden" name="submitted" value="1">
|
|
<input type="submit" class="submit" value="<?php _e('Send', 'twentyten-child' ); ?>">
|
|
</form>
|
|
|
|
<p class="star">( * ) Veuillez remplir tous les champs</p>
|
|
</div>
|
|
|
|
|
|
</div><!-- .entry-content -->
|
|
|
|
</article><!-- #post -->
|
|
|
|
<?php endwhile; // end of the loop. ?>
|
|
|
|
</div><!-- #content2 -->
|
|
</div><!-- #container2 -->
|
|
|
|
<?php get_footer(); ?>
|