__('Visitor type:', 'chameleon'),
'name' => __('Contact name:', 'chameleon'),
'email' => __('Email:', 'chameleon'),
'url' => __('Site URL', 'chameleon'));
// Get Form Data
$user = wp_get_current_user();
if ( $user->ID )
{
$form_data = array( 'status' => __('Registered', 'chameleon'),
'name' => $user->display_name,
'email' => $user->user_email,
'url' => $user->user_url);
}
else
{
$form_data = array( 'status' => __('Anonymous', 'chameleon'),
'name' => trim(strip_tags($_POST['user_name'])),
'email' => trim($_POST['user_email']),
'url' => trim($_POST['user_url']));
$captcha_code = strtoupper(trim($_POST['captcha_code']));
}
$msg_text = stripslashes(trim(strip_tags($_POST['user_message'])));
// Check all user data
$form_error = ''; // There are no error at this moment
// Check Captcha
if ( !$user->ID )
{
@session_start();
if ($captcha_code != $_SESSION['captcha_code'])
{
$form_error .= __('CAPTCHA code error. Please, reenter the new code.', 'chameleon') . '
';
}
}
// Check Contact Name
if ( 3 > strlen($form_data['name']) )
{
$form_error .= __('Please, fill your name.', 'chameleon') . '
';
}
// Check Contact Email
if ( empty($form_data['email']) || 6 > strlen($form_data['email']) )
{
$form_error .= __('Please, fill your email address.', 'chameleon') . '
';
}
elseif ( !is_email($form_data['email']) || eregi("\r", $form_data['email']) || eregi("\n", $form_data['email']) || eregi("%0a", $form_data['email']) || eregi("%0d", $form_data['email']) )
{
$form_error .= __('The email address doesn\'t look correct.', 'chameleon') . '
';
}
// Extra Email address Security. Probably it was alredy done in is_email() function.
$injection = array( "/bcc\:/i", "/Content\-Type\:/i", "/Mime\-Version\:/i", "/cc\:/i", "/from\:/i", "/to\:/i", "/Content\-Transfer\-Encoding\:/i");
$form_data['email'] = ( preg_replace ($injection, '', $form_data['email']) );
// Check there is a message
if ( 10 > strlen($msg_text) )
{
$form_error .= __('Your message is too short. Write something longer.', 'chameleon') . '
';
}
// Send the form data
if ( !isset($form_error) || empty($form_error) ) // If no errors
{
// Compose Message
$mail_extra_headers = 'From: ' . get_bloginfo('name')
. ' <' . 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . ">\n"
. 'Reply-To: ' . $form_data['name'] . ' <' . $form_data['email'] . ">\n";
$mail_body = '';
foreach ($form_data as $key => $value)
{
$mail_body .= $msg_strings[$key] . " $value\n";
}
$mail_body .= "\n" . __('MESSAGE:', 'chameleon') . "\n\n{$msg_text}\n\n";
$subject = apply_filters('chameleon_contact_subject', get_the_title());
// Send Mail
if ( wp_mail(get_bloginfo('admin_email'), $subject, $mail_body, $mail_extra_headers) )
{
$mail_end = 'ok';
}
else
{
$mail_end = 'error';
}
}
}
else // If not processing the form (when page shows first time)
{
$form_data = array( 'name' => '',
'email' => '',
'url' => '');
$msg_text = '';
} // End of form post check
// HERE STARTS THE PAGE TEMPLATE
get_header();
?>