private function compose($send = true) { $template = $this->template; $use_html = (bool) $template['use_html']; $subject = $this->replace_tags($template['subject']); $sender = $this->replace_tags($template['sender']); $recipient = $this->replace_tags($template['recipient']); $additional_headers = $this->replace_tags($template['additional_headers']); if ($use_html) { $body = $this->replace_tags($template['body'], true); $body = wpautop($body); } else { $body = $this->replace_tags($template['body']); } $attachments = $this->attachments($template['attachments']); $components = compact('subject', 'sender', 'body', 'recipient', 'additional_headers', 'attachments'); $components = apply_filters('wpcf7_mail_components', $components, wpcf7_get_current_contact_form()); extract($components); $subject = wpcf7_strip_newline($subject); $sender = wpcf7_strip_newline($sender); $recipient = wpcf7_strip_newline($recipient); $headers = "From: {$sender}\n"; if ($use_html) { $headers .= "Content-Type: text/html\n"; } $additional_headers = trim($additional_headers); if ($additional_headers) { $headers .= $additional_headers . "\n"; } if ($send) { return @wp_mail($recipient, $subject, $body, $headers, $attachments); } $components = compact('subject', 'sender', 'body', 'recipient', 'headers', 'attachments'); return $components; }
function wpcf7_response_shortcode_handler($tag) { if ($contact_form = wpcf7_get_current_contact_form()) { $contact_form->responses_count += 1; return $contact_form->form_response_output(); } }
private function compose($send = true) { $components = array('subject' => $this->get('subject', true), 'sender' => $this->get('sender', true), 'body' => $this->get('body', true), 'recipient' => $this->get('recipient', true), 'additional_headers' => $this->get('additional_headers', true), 'attachments' => $this->attachments()); $components = apply_filters('wpcf7_mail_components', $components, wpcf7_get_current_contact_form(), $this); if (!$send) { return $components; } $subject = wpcf7_strip_newline($components['subject']); $sender = wpcf7_strip_newline($components['sender']); $recipient = wpcf7_strip_newline($components['recipient']); $body = $components['body']; $additional_headers = trim($components['additional_headers']); $attachments = $components['attachments']; $headers = "From: {$sender}\n"; if ($this->use_html) { $headers .= "Content-Type: text/html\n"; $headers .= "X-WPCF7-Content-Type: text/html\n"; } else { $headers .= "X-WPCF7-Content-Type: text/plain\n"; } if ($additional_headers) { $headers .= $additional_headers . "\n"; } return wp_mail($recipient, $subject, $body, $headers, $attachments); }
/** * show contact form settings */ public function load_hw_wpcf7_form_settings($oAdminPage) { if ($post = wpcf7_get_current_contact_form()) { $post_id = $post->initial() ? -1 : $post->id(); } //register section $this->addSettingSections('hw_wpcf7_form_settings', array('section_id' => 'general', 'title' => 'Cấu hình', 'description' => 'Cài đặt chung.')); //get list of pages $pages = get_pages(); $list = array('__all__' => 'Tất cả', '__home__' => 'Trang Chủ'); foreach ($pages as $page) { $list[$page->post_name] = $page->post_title; } $this->addSettingFields('general', array('field_id' => 'enable_wpcf7_css', 'type' => 'checkbox', 'title' => __('Kích hoạt WPCF7 CSS', 'hwcf'), 'description' => __('Kích hoạt CSS mặc định.', 'hwcf'), 'value' => '1'), array('field_id' => 'enable_wpcf7_js', 'type' => 'checkbox', 'title' => __('Kích hoạt WPCF7 JS', 'hwcf'), 'description' => __('Kích hoạt tính năng ajax trong WPCF7', 'hwcf'), 'value' => '1'), array('field_id' => 'exclude_pages', 'type' => 'select', 'title' => __('Loại trừ pages'), 'description' => __('Chọn các pages bạn sẽ sử dụng tính năng ajax của Contact Form 7'), 'is_multiple' => true, 'attributes' => array('select' => array('size' => 5)), 'label' => $list), array('field_id' => 'loadingImg', 'type' => 'hw_skin_link', 'title' => __('Chọn ảnh loading khi sử lý lưu contact form'), 'description' => __('Chọn ảnh loading khi sử lý lưu contact form'), 'label' => '', 'external_skins_folder' => 'hw_wpcf7_ajax_images', 'skin_filename' => 'hw-wcf7-ajax-image.php', 'enable_external_callback' => false, 'skins_folder' => 'skins', 'apply_current_path' => HW_WPCF7_PATH, 'plugin_url' => HW_WPCF7_URL, 'files_skin_folder' => 'ajaxLoading'), array('type' => 'submit', 'field_id' => 'submit_button', 'show_title_column' => false)); //webhook API $this->addSettingFields('webhook', array('field_id' => 'webhook_url', 'type' => 'text', 'title' => 'URL nhận dữ liệu qua POST', 'description' => 'Điền URL (bắt đầu với http://) nhận dữ liệu qua phương thức POST sau khi người dùng nhấn submit form.'), array('type' => 'submit', 'field_id' => 'submit_button', 'show_title_column' => false)); }
function wpcf7_listo($data, $options, $args) { if (!function_exists('listo')) { return $data; } $args = wp_parse_args($args, array()); $contact_form = wpcf7_get_current_contact_form(); $args['locale'] = $contact_form->locale; foreach ((array) $options as $option) { $option = explode('.', $option); $type = $option[0]; $args['group'] = isset($option[1]) ? $option[1] : null; if ($list = listo($type, $args)) { $data = array_merge((array) $data, $list); } } return $data; }
/** * Add cf7skins classes to the CF7 HTML form class * * Based on selected template & style * eg. class="wpcf7-form cf7t-fieldset cf7s-wild-west" * * @uses 'wpcf7_form_class_attr' filter in WPCF7_ContactForm->form_html() * @uses wpcf7_get_current_contact_form() * @file wp-content\plugins\contact-form-7\includes\contact-form.php * * @param $class is the CF7 HTML form class * @since 0.0.1 */ function form_class_attr($class, $id) { // Get the current CF7 form ID $cf7 = wpcf7_get_current_contact_form(); // Current contact form 7 object $form_id = get_form_id($cf7); $template_class = ''; $cf7_style_id = get_post_meta($form_id, 'cf7_style_id'); if (isset($cf7_style_id[0])) { $cf7_style_data = get_post($cf7_style_id[0], OBJECT); if (has_term('custom-style', 'style_category', $cf7_style_data)) { $template_class = "cf7-style-" . $cf7_style_id[0]; } else { $template_class = $cf7_style_data->post_name; } } // Return the modified class return $template_class; }
function wpcf7_file_validation_filter($result, $tag) { $tag = new WPCF7_Shortcode($tag); $name = $tag->name; $file = isset($_FILES[$name]) ? $_FILES[$name] : null; if ($file['error'] && UPLOAD_ERR_NO_FILE != $file['error']) { $result['valid'] = false; $result['reason'][$name] = wpcf7_get_message('upload_failed_php_error'); return $result; } if (empty($file['tmp_name']) && $tag->is_required()) { $result['valid'] = false; $result['reason'][$name] = wpcf7_get_message('invalid_required'); return $result; } if (!is_uploaded_file($file['tmp_name'])) { return $result; } $allowed_file_types = array(); if ($file_types_a = $tag->get_option('filetypes')) { foreach ($file_types_a as $file_types) { $file_types = explode('|', $file_types); foreach ($file_types as $file_type) { $file_type = trim($file_type, '.'); $file_type = str_replace(array('.', '+', '*', '?'), array('\\.', '\\+', '\\*', '\\?'), $file_type); $allowed_file_types[] = $file_type; } } } $allowed_file_types = array_unique($allowed_file_types); $file_type_pattern = implode('|', $allowed_file_types); $allowed_size = 1048576; // default size 1 MB if ($file_size_a = $tag->get_option('limit')) { $limit_pattern = '/^([1-9][0-9]*)([kKmM]?[bB])?$/'; foreach ($file_size_a as $file_size) { if (preg_match($limit_pattern, $file_size, $matches)) { $allowed_size = (int) $matches[1]; if (!empty($matches[2])) { $kbmb = strtolower($matches[2]); if ('kb' == $kbmb) { $allowed_size *= 1024; } elseif ('mb' == $kbmb) { $allowed_size *= 1024 * 1024; } } break; } } } /* File type validation */ // Default file-type restriction if ('' == $file_type_pattern) { $file_type_pattern = 'jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv'; } $file_type_pattern = trim($file_type_pattern, '|'); $file_type_pattern = '(' . $file_type_pattern . ')'; $file_type_pattern = '/\\.' . $file_type_pattern . '$/i'; if (!preg_match($file_type_pattern, $file['name'])) { $result['valid'] = false; $result['reason'][$name] = wpcf7_get_message('upload_file_type_invalid'); return $result; } /* File size validation */ if ($file['size'] > $allowed_size) { $result['valid'] = false; $result['reason'][$name] = wpcf7_get_message('upload_file_too_large'); return $result; } $uploads_dir = wpcf7_upload_tmp_dir(); wpcf7_init_uploads(); // Confirm upload dir $filename = $file['name']; // If you get script file, it's a danger. Make it TXT file. if (preg_match('/\\.(php|pl|py|rb|cgi)\\d?$/', $filename)) { $filename .= '.txt'; } $filename = wp_unique_filename($uploads_dir, $filename); $new_file = trailingslashit($uploads_dir) . $filename; if (false === @move_uploaded_file($file['tmp_name'], $new_file)) { $result['valid'] = false; $result['reason'][$name] = wpcf7_get_message('upload_failed'); return $result; } // Make sure the uploaded file is only readable for the owner process @chmod($new_file, 0400); if ($contact_form = wpcf7_get_current_contact_form()) { $contact_form->uploaded_files[$name] = $new_file; if (empty($contact_form->posted_data[$name])) { $contact_form->posted_data[$name] = $filename; } } return $result; }
function wpcf7_file_display_warning_message() { if (!($contact_form = wpcf7_get_current_contact_form())) { return; } $has_tags = (bool) $contact_form->form_scan_shortcode(array('type' => array('file', 'file*'))); if (!$has_tags) { return; } $uploads_dir = wpcf7_upload_tmp_dir(); wpcf7_init_uploads(); if (!is_dir($uploads_dir) || !wp_is_writable($uploads_dir)) { $message = sprintf(__('This contact form contains file uploading fields, but the temporary folder for the files (%s) does not exist or is not writable. You can create the folder or change its permission manually.', 'contact-form-7'), $uploads_dir); echo '<div class="error"><p>' . esc_html($message) . '</p></div>'; } }
function wpcf7_not_allowed_to_edit() { if (!($contact_form = wpcf7_get_current_contact_form())) { return; } $post_id = $contact_form->id(); if (current_user_can('wpcf7_edit_contact_form', $post_id)) { return; } $message = __("You are not allowed to edit this contact form.", 'contact-form-7'); echo sprintf('<div class="notice notice-warning is-dismissible"><p>%s</p></div>', esc_html($message)); }
function wpcf7_acceptance_as_validation() { if (!($contact_form = wpcf7_get_current_contact_form())) { return false; } return $contact_form->is_true('acceptance_as_validation'); }
function wpcf7_get_message($status) { if (!($contact_form = wpcf7_get_current_contact_form())) { return ''; } return $contact_form->message($status); }
function wpcf7_admin_add_new_page() { if ($post = wpcf7_get_current_contact_form()) { $post_id = -1; require_once WPCF7_PLUGIN_DIR . '/admin/includes/meta-boxes.php'; require_once WPCF7_PLUGIN_DIR . '/admin/edit-contact-form.php'; return; } $available_locales = wpcf7_l10n(); $default_locale = get_locale(); if (!isset($available_locales[$default_locale])) { $default_locale = 'en_US'; } ?> <div class="wrap"> <h2><?php echo esc_html(__('Add New Contact Form', 'contact-form-7')); ?> </h2> <?php do_action('wpcf7_admin_notices'); ?> <h3><?php echo esc_html(sprintf(__('Use the default language (%s)', 'contact-form-7'), $available_locales[$default_locale])); ?> </h3> <p><a href="<?php echo esc_url(add_query_arg(array('locale' => $default_locale), menu_page_url('wpcf7-new', false))); ?> " class="button button-primary" /><?php echo esc_html(__('Add New', 'contact-form-7')); ?> </a></p> <?php unset($available_locales[$default_locale]); ?> <h3><?php echo esc_html(__('Or', 'contact-form-7')); ?> </h3> <form action="" method="get"> <input type="hidden" name="page" value="wpcf7-new" /> <select name="locale"> <option value="" selected="selected"><?php echo esc_html(__('(select language)', 'contact-form-7')); ?> </option> <?php foreach ($available_locales as $code => $locale) { ?> <option value="<?php echo esc_attr($code); ?> "><?php echo esc_html($locale); ?> </option> <?php } ?> </select> <input type="submit" class="button" value="<?php echo esc_attr(__('Add New', 'contact-form-7')); ?> " /> </form> </div> <?php }
function wpcf7_notice_config_errors() { if (!($contact_form = wpcf7_get_current_contact_form())) { return; } if (!wpcf7_validate_configuration() || !current_user_can('wpcf7_edit_contact_form', $contact_form->id())) { return; } $config_validator = new WPCF7_ConfigValidator($contact_form); if ($count_errors = $config_validator->count_errors()) { $message = sprintf(_n('%s configuration error found', '%s configuration errors found', $count_errors, 'contact-form-7'), number_format_i18n($count_errors)); $link = wpcf7_link(__('http://contactform7.com/configuration-validator-faq/', 'contact-form-7'), __("What's this?", 'contact-form-7'), array('class' => 'external')); echo sprintf('<div class="misc-pub-section warning">%1$s<br />%2$s</div>', $message, $link); } }
function wpcf7_notice_config_errors() { if (!($contact_form = wpcf7_get_current_contact_form())) { return; } if (!wpcf7_validate_configuration() || !current_user_can('wpcf7_edit_contact_form', $contact_form->id())) { return; } if ($config_errors = $contact_form->get_config_errors()) { $message = sprintf(_n("This contact form has a configuration error.", "This contact form has %s configuration errors.", count($config_errors), 'contact-form-7'), number_format_i18n(count($config_errors))); $link = wpcf7_link(__('http://contactform7.com/configuration-errors/', 'contact-form-7'), __('How to Resolve Configuration Errors', 'contact-form-7')); echo sprintf('<div class="notice notice-warning is-dismissible"><p>%s » %s</p></div>', esc_html($message), $link); } }
function wpcf7_response_form_tag_handler($tag) { if ($contact_form = wpcf7_get_current_contact_form()) { return $contact_form->form_response_output(); } }
function wpcf7_captcha_display_warning_message() { if (!($contact_form = wpcf7_get_current_contact_form())) { return; } $has_tags = (bool) $contact_form->form_scan_shortcode(array('type' => array('captchac'))); if (!$has_tags) { return; } if (!class_exists('ReallySimpleCaptcha')) { return; } $uploads_dir = wpcf7_captcha_tmp_dir(); wpcf7_init_captcha(); if (!is_dir($uploads_dir) || !wp_is_writable($uploads_dir)) { $message = sprintf(__('This contact form contains CAPTCHA fields, but the temporary folder for the files (%s) does not exist or is not writable. You can create the folder or change its permission manually.', 'contact-form-7'), $uploads_dir); echo '<div class="notice notice-error is-dismissible"><p>' . esc_html($message) . '</p></div>'; } if (!function_exists('imagecreatetruecolor') || !function_exists('imagettftext')) { $message = __('This contact form contains CAPTCHA fields, but the necessary libraries (GD and FreeType) are not available on your server.', 'contact-form-7'); echo '<div class="notice notice-error is-dismissible"><p>' . esc_html($message) . '</p></div>'; } }
function wpcf7_recaptcha_check_with_google($spam) { if ($spam) { return $spam; } $contact_form = wpcf7_get_current_contact_form(); if (!$contact_form) { return $spam; } $tags = $contact_form->form_scan_shortcode(array('type' => 'recaptcha')); if (empty($tags)) { return $spam; } $recaptcha = WPCF7_RECAPTCHA::get_instance(); if (!$recaptcha->is_active()) { return $spam; } $response_token = wpcf7_recaptcha_response(); $spam = !$recaptcha->verify($response_token); return $spam; }
function wpcf7_acceptance_as_validation() { if (!($contact_form = wpcf7_get_current_contact_form())) { return false; } $settings = $contact_form->additional_setting('acceptance_as_validation', false); foreach ($settings as $setting) { if (in_array($setting, array('on', 'true', '1'))) { return true; } } return false; }
function wpcf7_scan_shortcode($cond = null) { if (!($contact_form = wpcf7_get_current_contact_form())) { return array(); } return $contact_form->form_scan_shortcode($cond); }
function wpcf7_akismet_comment_check($comment) { global $akismet_api_host, $akismet_api_port; $spam = false; $query_string = ''; foreach ($comment as $key => $data) { $query_string .= $key . '=' . urlencode(stripslashes((string) $data)) . '&'; } $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); if ('true' == $response[1]) { $spam = true; } if ($contact_form = wpcf7_get_current_contact_form()) { $contact_form->akismet = array('comment' => $comment, 'spam' => $spam); } return apply_filters('wpcf7_akismet_comment_check', $spam, $comment); }
function wpcf7_akismet_comment_check($comment) { global $akismet_api_host, $akismet_api_port; $spam = false; $query_string = ''; foreach ($comment as $key => $data) { $query_string .= $key . '=' . urlencode(wp_unslash((string) $data)) . '&'; } if (is_callable(array('Akismet', 'http_post'))) { // Akismet v3.0+ $response = Akismet::http_post($query_string, 'comment-check'); } else { $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port); } if ('true' == $response[1]) { $spam = true; } if ($contact_form = wpcf7_get_current_contact_form()) { $contact_form->akismet = array('comment' => $comment, 'spam' => $spam); } return apply_filters('wpcf7_akismet_comment_check', $spam, $comment); }
/** * Add cf7skins classes to the CF7 HTML form class * * Based on selected template & style * eg. class="wpcf7-form cf7t-fieldset cf7s-wild-west" * * @uses 'wpcf7_form_class_attr' filter in WPCF7_ContactForm->form_html() * @uses wpcf7_get_current_contact_form() * @file wp-content\plugins\contact-form-7\includes\contact-form.php * * @param $class is the CF7 HTML form class * @since 0.0.1 */ function form_class_attr($class) { // Get the current CF7 form ID $cf7 = wpcf7_get_current_contact_form(); // Current contact form 7 object $form_id = $this->get_form_id($cf7); // Get current CF7 form template and style from post meta $template_class = get_post_meta($form_id, 'cf7s_template', true) ? ' cf7t-' . get_post_meta($form_id, 'cf7s_template', true) : ''; $skin_class = get_post_meta($form_id, 'cf7s_style', true) ? ' cf7s-' . get_post_meta($form_id, 'cf7s_style', true) : ''; // CF7 Skins default class $cf7skins_class = $template_class || $skin_class ? ' cf7skins' : ''; $cf7skins_classes = apply_filters('cf7skins_form_classes', $cf7skins_class); // Return the modified class return $class . $cf7skins_classes . $template_class . $skin_class; }