\s*
|', "\n\n", $pee);
// Space things out a little
$allblocks = '(?:address|area|blockquote|caption|colgroup|dd|div|dl|dt|form|h[1-6]|li|map|math|ol|p|pre|table|tbody|td|tfoot|th|thead|tr|ul)';
$pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
$pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
$pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
$pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "
$1
\n", $pee); // make paragraphs, including one at the end $pee = preg_replace('|\s*?
|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace $pee = preg_replace('!([^<]+)\s*?((?:div|address|form)[^>]*>)!', "
$1
$2", $pee); $pee = preg_replace( '||', "$1
", $pee ); $pee = preg_replace('!
\s*(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee); // don't pee all over a tag $pee = preg_replace("|(
]*)>|i', "', $pee); $pee = preg_replace('!', '", $pee); $pee = str_replace('
\s*(?' . $allblocks . '[^>]*>)!', "$1", $pee); $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee); if ($br) { $pee = preg_replace('/<(script|style).*?<\/\\1>/se', 'str_replace("\n", ")(.*?)!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '' ", $pee); $pee = preg_replace( "|\n$|", '', $pee ); return $pee; } function init_switch() { if ('POST' == $_SERVER['REQUEST_METHOD'] && $_POST['_wpcf7_is_ajax_call']) { $this->ajax_json_echo(); exit(); } elseif (! is_admin()) { $this->process_nonajax_submitting(); $this->cleanup_captcha_files(); } } function ajax_json_echo() { if (isset($_POST['_wpcf7'])) { $id = (int) $_POST['_wpcf7']; $unit_tag = $_POST['_wpcf7_unit_tag']; $contact_forms = $this->contact_forms(); if ($cf = $contact_forms[$id]) { $cf = stripslashes_deep($cf); $validation = $this->validate($cf); $captchas = $this->refill_captcha($cf); if (! empty($captchas)) { $captchas_js = array(); foreach ($captchas as $name => $cap) { $captchas_js[] = '"' . $name . '": "' . $cap . '"'; } $captcha = '{ ' . join(', ', $captchas_js) . ' }'; } else { $captcha = 'null'; } @header('Content-Type: text/plain; charset=' . get_option('blog_charset')); if (! $validation['valid']) { // Validation error occured $invalids = array(); foreach ($validation['reason'] as $name => $reason) { $invalids[] = '{ into: "span.wpcf7-form-control-wrap.' . $name . '", message: "' . js_escape($reason) . '" }'; } $invalids = '[' . join(', ', $invalids) . ']'; echo '{ mailSent: 0, message: "' . js_escape($this->message('validation_error')) . '", into: "#' . $unit_tag . '", invalids: ' . $invalids . ', captcha: ' . $captcha . ' }'; } elseif (! $this->acceptance($cf)) { // Not accepted terms echo '{ mailSent: 0, message: "' . js_escape($this->message('accept_terms')) . '", into: "#' . $unit_tag . '", captcha: ' . $captcha . ' }'; } elseif ($this->akismet($cf)) { // Spam! echo '{ mailSent: 0, message: "' . js_escape($this->message('mail_sent_ng')) . '", into: "#' . $unit_tag . '", spam: 1, captcha: ' . $captcha . ' }'; } elseif ($this->mail($cf)) { echo '{ mailSent: 1, message: "' . js_escape($this->message('mail_sent_ok')) . '", into: "#' . $unit_tag . '", captcha: ' . $captcha . ' }'; } else { echo '{ mailSent: 0, message: "' . js_escape($this->message('mail_sent_ng')) . '", into: "#' . $unit_tag . '", captcha: ' . $captcha . ' }'; } } } } function mail($contact_form) { $contact_form = $this->upgrade_160($contact_form); $regex = '/\[\s*([a-zA-Z][0-9a-zA-Z:._-]*)\s*\]/'; $callback = array(&$this, 'mail_callback'); $mail_subject = preg_replace_callback($regex, $callback, $contact_form['mail']['subject']); $mail_sender = preg_replace_callback($regex, $callback, $contact_form['mail']['sender']); $mail_body = preg_replace_callback($regex, $callback, $contact_form['mail']['body']); $mail_recipient = preg_replace_callback($regex, $callback, $contact_form['mail']['recipient']); $mail_headers = "From: $mail_sender\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; if (@wp_mail($mail_recipient, $mail_subject, $mail_body, $mail_headers)) { // Mail 2 if ($contact_form['mail_2']['active']) { $mail_2_subject = preg_replace_callback($regex, $callback, $contact_form['mail_2']['subject']); $mail_2_sender = preg_replace_callback($regex, $callback, $contact_form['mail_2']['sender']); $mail_2_body = preg_replace_callback($regex, $callback, $contact_form['mail_2']['body']); $mail_2_recipient = preg_replace_callback($regex, $callback, $contact_form['mail_2']['recipient']); $mail_2_headers = "From: $mail_2_sender\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; @wp_mail($mail_2_recipient, $mail_2_subject, $mail_2_body, $mail_2_headers); } return true; } else { return false; } } function mail_callback($matches) { if (isset($_POST[$matches[1]])) { $submitted = $_POST[$matches[1]]; if (is_array($submitted)) $submitted = join(', ', $submitted); return stripslashes($submitted); } else { return $matches[0]; } } function akismet($contact_form) { global $akismet_api_host, $akismet_api_port; if (! function_exists('akismet_http_post') || ! (get_option('wordpress_api_key') || $wpcom_api_key)) return false; $akismet_ready = false; $author = $author_email = $author_url = $content = ''; $fes = $this->form_elements($contact_form['form'], false); foreach ($fes as $fe) { if (! is_array($fe['options'])) continue; if (preg_grep('%^akismet:author$%', $fe['options']) && '' == $author) { $author = $_POST[$fe['name']]; $akismet_ready = true; } if (preg_grep('%^akismet:author_email$%', $fe['options']) && '' == $author_email) { $author_email = $_POST[$fe['name']]; $akismet_ready = true; } if (preg_grep('%^akismet:author_url$%', $fe['options']) && '' == $author_url) { $author_url = $_POST[$fe['name']]; $akismet_ready = true; } if ('' != $content) $content .= "\n\n"; $content .= $_POST[$fe['name']]; } if (! $akismet_ready) return false; $c['blog'] = get_option('home'); $c['user_ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']); $c['user_agent'] = $_SERVER['HTTP_USER_AGENT']; $c['referrer'] = $_SERVER['HTTP_REFERER']; $c['comment_type'] = 'contactform7'; if ($permalink = get_permalink()) $c['permalink'] = $permalink; if ('' != $author) $c['comment_author'] = $author; if ('' != $author_email) $c['comment_author_email'] = $author_email; if ('' != $author_url) $c['comment_author_url'] = $author_url; if ('' != $content) $c['comment_content'] = $content; $ignore = array('HTTP_COOKIE'); foreach ($_SERVER as $key => $value) if (! in_array($key, $ignore)) $c["$key"] = $value; $query_string = ''; foreach ($c 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; else return false; } function acceptance($contact_form) { $fes = $this->form_elements($contact_form['form'], false); $accepted = true; foreach ($fes as $fe) { if ('acceptance' != $fe['type']) continue; $invert = (bool) preg_grep('%^invert$%', $fe['options']); if ($invert && $_POST[$fe['name']] || ! $invert && ! $_POST[$fe['name']]) $accepted = false; } return $accepted; } function set_initial() { $wpcf7 = get_option('wpcf7'); if (! is_array($wpcf7)) $wpcf7 = array(); $contact_forms = $wpcf7['contact_forms']; if (! is_array($contact_forms)) $contact_forms = array(); if (0 == count($contact_forms)) $contact_forms[1] = $this->default_pack(__('Contact form', 'wpcf7') . ' 1'); $wpcf7['contact_forms'] = $contact_forms; update_option('wpcf7', $wpcf7); } function load_plugin_textdomain() { // l10n load_plugin_textdomain('wpcf7', 'wp-content/plugins/contact-form-7/languages'); } function contact_forms() { if (is_array($this->contact_forms)) return $this->contact_forms; $wpcf7 = get_option('wpcf7'); $this->contact_forms = $wpcf7['contact_forms']; if (! is_array($this->contact_forms)) $this->contact_forms = array(); return $this->contact_forms; } function update_contact_forms($contact_forms) { $wpcf7 = get_option('wpcf7'); $wpcf7['contact_forms'] = $contact_forms; update_option('wpcf7', $wpcf7); } function upgrade_160($contact_form) { if (! isset($contact_form['mail']['recipient'])) $contact_form['mail']['recipient'] = $contact_form['options']['recipient']; return $contact_form; } /* Admin panel */ function add_pages() { $base_url = get_option('siteurl') . '/wp-admin/options-general.php'; $page = str_replace('\\', '%5C', plugin_basename(__FILE__)); $contact_forms = $this->contact_forms(); if (isset($_POST['wpcf7-save'])) { $id = $_POST['wpcf7-id']; check_admin_referer('wpcf7-save_' . $id); $title = trim($_POST['wpcf7-title']); $form = trim($_POST['wpcf7-form']); $mail = array( 'subject' => trim($_POST['wpcf7-mail-subject']), 'sender' => trim($_POST['wpcf7-mail-sender']), 'body' => trim($_POST['wpcf7-mail-body']), 'recipient' => trim($_POST['wpcf7-mail-recipient']) ); $mail_2 = array( 'active' => (1 == $_POST['wpcf7-mail-2-active']) ? true : false, 'subject' => trim($_POST['wpcf7-mail-2-subject']), 'sender' => trim($_POST['wpcf7-mail-2-sender']), 'body' => trim($_POST['wpcf7-mail-2-body']), 'recipient' => trim($_POST['wpcf7-mail-2-recipient']) ); $options = array( 'recipient' => trim($_POST['wpcf7-options-recipient']) // For backward compatibility. ); if (array_key_exists($id, $contact_forms)) { $contact_forms[$id] = compact('title', 'form', 'mail', 'mail_2', 'options'); $redirect_to = $base_url . '?page=' . $page . '&contactform=' . $id . '&message=saved'; } else { $key = (empty($contact_forms)) ? 1 : max(array_keys($contact_forms)) + 1; $contact_forms[$key] = compact('title', 'form', 'mail', 'mail_2', 'options'); $redirect_to = $base_url . '?page=' . $page . '&contactform=' . $key . '&message=created'; } $this->update_contact_forms($contact_forms); wp_redirect($redirect_to); exit(); } elseif (isset($_POST['wpcf7-delete'])) { $id = $_POST['wpcf7-id']; check_admin_referer('wpcf7-delete_' . $id); unset($contact_forms[$id]); $this->update_contact_forms($contact_forms); wp_redirect($base_url . '?page=' . $page . '&message=deleted'); exit(); } add_options_page(__('Contact Form 7', 'wpcf7'), __('Contact Form 7', 'wpcf7'), 'manage_options', __FILE__, array(&$this, 'option_page')); } function admin_head() { global $plugin_page; if (isset($plugin_page) && $plugin_page == plugin_basename(__FILE__)) { $admin_stylesheet_url = get_option('siteurl') . '/wp-content/plugins/contact-form-7/admin-stylesheet.css'; echo ''; $javascript_url = get_option('siteurl') . '/wp-content/plugins/contact-form-7/wpcf7-admin.js'; ?> contact_forms(); $id = $_POST['wpcf7-id']; switch ($_GET['message']) { case 'created': $updated_message = __('Contact form created.', 'wpcf7'); break; case 'saved': $updated_message = __('Contact form saved.', 'wpcf7'); break; case 'deleted': $updated_message = __('Contact form deleted.', 'wpcf7'); break; } if ('new' == $_GET['contactform']) { $unsaved = true; $current = -1; $cf = $this->default_pack(__('Untitled', 'wpcf7'), true); } elseif (array_key_exists($_GET['contactform'], $contact_forms)) { $current = (int) $_GET['contactform']; $cf = stripslashes_deep($contact_forms[$current]); $cf = $this->upgrade_160($cf); } else { $cf = null; } require_once ABSPATH . PLUGINDIR . '/contact-form-7/includes/admin-panel.php'; } function default_pack($title, $initial = false) { $cf = array('title' => $title, 'form' => $this->default_form_template(), 'mail' => $this->default_mail_template(), 'mail_2' => $this->default_mail_2_template(), 'options' => $this->default_options_template()); if ($initial) $cf['initial'] = true; return $cf; } function default_form_template() { $template .= '' . "\n\n"; $template .= '' . "\n\n"; $template .= '' . "\n\n"; $template .= '' . "\n\n"; $template .= '
[submit "' . __('Send', 'wpcf7') . '"]
'; return $template; } function default_mail_template() { $subject = '[your-subject]'; $sender = '[your-name] <[your-email]>'; $body = '[your-message]'; $recipient = get_option('admin_email'); return compact('subject', 'sender', 'body', 'recipient'); } function default_mail_2_template() { $active = false; $subject = '[your-subject]'; $sender = '[your-name] <[your-email]>'; $body = '[your-message]'; $recipient = '[your-email]'; return compact('active', 'subject', 'sender', 'body', 'recipient'); } function default_options_template() { $recipient = get_option('admin_email'); // For backward compatibility. return compact('recipient'); } function message($status) { switch ($status) { case 'mail_sent_ok': return __('Your message was sent successfully. Thanks.', 'wpcf7'); case 'mail_sent_ng': return __('Failed to send your message. Please try later or contact administrator by other way.', 'wpcf7'); case 'validation_error': return __('Validation errors occurred. Please confirm the fields and submit it again.', 'wpcf7'); case 'accept_terms': return __('Please accept the terms to proceed.', 'wpcf7'); case 'invalid_email': return __('Email address seems invalid.', 'wpcf7'); case 'invalid_required': return __('Please fill the required field.', 'wpcf7'); case 'captcha_not_match': return __('Your entered code is incorrect.', 'wpcf7'); } } function process_nonajax_submitting() { if (! isset($_POST['_wpcf7'])) return; $id = (int) $_POST['_wpcf7']; $contact_forms = $this->contact_forms(); if ($cf = $contact_forms[$id]) { $cf = stripslashes_deep($cf); $validation = $this->validate($cf); if (! $validation['valid']) { $_POST['_wpcf7_validation_errors'] = array('id' => $id, 'messages' => $validation['reason']); } elseif (! $this->acceptance($cf)) { // Not accepted terms $_POST['_wpcf7_mail_sent'] = array('id' => $id, 'ok' => false, 'message' => $this->message('accept_terms')); } elseif ($this->akismet($cf)) { // Spam! $_POST['_wpcf7_mail_sent'] = array('id' => $id, 'ok' => false, 'message' => $this->message('mail_sent_ng'), 'spam' => true); } elseif ($this->mail($cf)) { $_POST['_wpcf7_mail_sent'] = array('id' => $id, 'ok' => true, 'message' => $this->message('mail_sent_ok')); } else { $_POST['_wpcf7_mail_sent'] = array('id' => $id, 'ok' => false, 'message' => $this->message('mail_sent_ng')); } } } /* Post content filtering */ var $processing_unit_tag; var $processing_within; var $unit_count; var $widget_count; function the_content_filter($content) { $this->processing_within = 'p' . get_the_ID(); $this->unit_count = 0; $regex = '/\[\s*contact-form\s+(\d+)(?:\s+.*?)?\s*\]/'; return preg_replace_callback($regex, array(&$this, 'the_content_filter_callback'), $content); $this->processing_within = null; } function widget_text_filter($content) { $this->widget_count += 1; $this->processing_within = 'w' . $this->widget_count; $this->unit_count = 0; $regex = '/\[\s*contact-form\s+(\d+)(?:\s+.*?)?\s*\]/'; return preg_replace_callback($regex, array(&$this, 'the_content_filter_callback'), $content); $this->processing_within = null; } function the_content_filter_callback($matches) { $contact_forms = $this->contact_forms(); $id = (int) $matches[1]; if (! ($cf = $contact_forms[$id])) return $matches[0]; $cf = stripslashes_deep($cf); $this->unit_count += 1; $unit_tag = 'wpcf7-f' . $id . '-' . $this->processing_within . '-o' . $this->unit_count; $this->processing_unit_tag = $unit_tag; $form = '