'0', 'sent' => '0', 'email' => '', 'prefix' => '', 'cc' => '', 'bcc' => '', 'thanks' => '', 'thanks_url' => '', ), $atts); if(!empty($_POST['clean_contact_token'])) { if(clean_contact_send($atts)) { $atts['sent'] = 1; } else { $atts['fail'] = 1; } } return clean_contact($atts); } // {{{ clean_contact_akismet() /* * Filter message through akismet * Requires the akismet plugin activated and configured * @param string $body * @param string $subject * @param string $email * @param string $name * @return bool */ function clean_contact_akismet($body,$subject,$email,$name) { if(!function_exists('akismet_http_post')) return true; global $akismet_api_host, $akismet_api_port; $comment['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] ); $comment['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $comment['referrer'] = $_SERVER['HTTP_REFERER']; $comment['blog'] = get_option('home'); $comment['comment_author_email'] = $email; $comment['comment_author'] = clean_contact_scrub($name); $comment['comment_content'] = clean_contact_scrub($body); $query_string = ''; foreach ( $comment as $key => $data ) $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&'; $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); if ( 'true' == $response[1] ) { return true; } } // {{{ clean_contact_valid_email() /* * Validate email via regex * @param string * @return bool */ function clean_contact_valid_email($str) { $pattern = '/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i'; return preg_match($pattern,$str); } // {{{ clean_contact_send() /* * Deliver e-mail via SMTP * @param array * @return bool */ function clean_contact_send($atts) { $to_email = ($atts['email']) ? $atts['email'] : get_option('clean_contact_email'); $to_email = clean_contact_scrub($to_email); $bcc = ($atts['bcc']) ? $atts['bcc'] : get_option('clean_contact_bcc'); $bcc = clean_contact_scrub($bbc); $cc = ($atts['cc']) ? $atts['cc'] : get_option('clean_contact_cc'); $cc = clean_contact_scrub($cc); $body = clean_contact_scrub($_POST['clean_contact_body']); $from_name = clean_contact_scrub(($_POST['clean_contact_from_name'])); $from_email = clean_contact_scrub($_POST['clean_contact_from_email']); $from = ($from_name) ? "{$from_name} <$from_email>" : $from_email; if(!clean_contact_valid_email($from_email) or !clean_contact_valid_email($to_email) ) return false; $headers = array(); $headers[] = "From: {$from}"; $to = get_bloginfo('name') . "<$to_email>"; if(clean_contact_valid_email($cc)) $headers[] = "CC: {$cc}"; if(clean_contact_valid_email($bcc)) $headers[] = "BCC: {$bcc}"; $headers[] = 'X-Originating-IP: ' . $_SERVER['REMOTE_ADDR']; $headers[] = 'X-Mailer: WP Clean-Contact (' . $_SERVER['SERVER_NAME'] . ')'; if(get_option('clean_contact_akismet') == 1 and clean_contact_akismet($body,$subject,$from_email,$from_name)) { return false; } else { $prefix = ($atts['prefix']) ? $atts['prefix'] : get_option('clean_contact_prefix'); $subject = clean_contact_scrub($_POST['clean_contact_subject']); if($prefix) { $subject = "[{$prefix}] {$subject}"; } mail($to, $subject, $body, implode("\n",$headers)); return true; } } // {{{ clean_contact_scrub() /* * Display e-mail from * @param array * @return string */ function clean_contact_scrub($str) { return stripslashes(trim(strip_tags($str))); } function clean_contact($atts) { $html = clean_contact_css(); $html .= ''; $thanks= (!empty($atts['thanks'])) ? $atts['thanks'] : get_option('clean_contact_thanks'); $thanks_url= (!empty($atts['thanks_url'])) ? $atts['thanks_url'] : get_option('clean_contact_thanks_url'); if(empty($thanks)) $thanks = __('Thank you. Message sent!'); if($atts['sent']) { $html .= '
' . $thanks . '
'; if($thanks_url) { $html .= "" . "\n"; } } elseif($atts['fail']) { $html .= '

' . __('Sorry, unable to deliver this message') . '

'; } else { $html .= '' . "\n"; } $html .= ''; return $html; } // {{{ clean_contact_conf() /* * Add to admin * @param void * @return void */ function clean_contact_conf() { clean_contact_setup(); if ( function_exists('add_submenu_page') ) { add_submenu_page('plugins.php', __('Clean-Contact'), __('Clean-Contact'), 'manage_options', 'clean_contact', 'clean_contact_conf_page'); } } // {{{ clean_contact_conf_page() /* * Display admin * @param void * @return void */ function clean_contact_conf_page() { include(dirname(__FILE__).'/clean_contact_conf.php'); } // {{{ clean_contact_css() /* * Include css * @param void * @return void */ function clean_contact_css() { $html .= ''; return $html; } // {{{ clean_contact_setup() /* * Include css * @param void * @return void */ function clean_contact_setup() { if($_SERVER['REQUEST_METHOD'] == 'POST') return; if(!get_option('clean_contact_email')) { update_option('clean_contact_email',get_bloginfo('admin_email')); update_option('clean_contact_prefix','clean-contact'); update_option('clean_contact_thanks',__('Thank you. Message sent!')); if(!function_exists('akismet_http_post')) { update_option('clean_contact_akismet','-1'); } elseif(get_option('wordpress_api_key')) { update_option('clean_contact_akismet','1'); } } } add_shortcode('clean-contact', 'clean_contact_func'); add_action('admin_menu', 'clean_contact_conf'); ?>