public static function get_instance() { if (empty(self::$instance)) { self::$instance = new self(); } return self::$instance; }
function icl_wpcf7_display_warning_message(&$contact_form) { if (!$contact_form) { return; } $has_icl_tags = (bool) $contact_form->form_scan_shortcode(array('type' => array('icl'))); if (!$has_icl_tags) { $messages = (array) $contact_form->messages; $shortcode_manager = new WPCF7_ShortcodeManager(); $shortcode_manager->add_shortcode('icl', create_function('$tag', 'return null;'), true); foreach ($messages as $message) { if ($shortcode_manager->scan_shortcode($message)) { $has_icl_tags = true; break; } } } if (!$has_icl_tags) { return; } $message = __("This contact form contains [icl] tags, but they are obsolete and no longer functioning on this version of Contact Form 7. <a href=\"http://contactform7.com/2009/12/25/contact-form-in-your-language/#Creating_contact_form_in_different_languages\" target=\"_blank\">There is a simpler way for creating contact forms of other languages</a> and you are recommended to use it.", 'wpcf7'); echo '<div class="error"><p><strong>' . $message . '</strong></p></div>'; }
/** * Get an array of all shortcodes from text, via ajax * * @return array Array of shortcodes */ function ajax_generate_dropdowns_from_code() { check_ajax_referer('ctctcf7_generate_dropdowns', 'ctctcf7_generate_dropdowns'); // Fix issue where the WPCF7 plugin isn't around if (!defined('WPCF7_PLUGIN_DIR')) { return; } // Again, attempt to fix // https://github.com/katzwebservices/Contact-Form-7-Newsletter/issues/24 if (!class_exists('WPCF7_ShortcodeManager')) { include_once WPCF7_PLUGIN_DIR . '/includes/shortcodes.php'; } // They must be using version CF7 3.0 or less if (!class_exists('WPCF7_ShortcodeManager')) { return; } $output = array('' => __('Select a Field', 'ctctcf7')); // Form code to scan $code = stripslashes_deep(@$_REQUEST['data']); // Get the tags from the form code $scanned_form_tags = WPCF7_ShortcodeManager::get_instance()->scan_shortcode($code); if (count($scanned_form_tags)) { foreach ($scanned_form_tags as $fe) { if (empty($fe['name'])) { continue; } if ($fe['basetype'] === 'ctct') { continue; } $name = $fe['name']; $is_placeholder = isset($fe['options'][0]) && $fe['options'][0] === 'placeholder'; $label = !empty($fe['labels']) ? $fe['labels'][0] : $name; $type = str_replace('*', '', $fe['type']); $output[$name] = esc_attr("{$label} ({$name})"); } } header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-Type: application/json'); exit(json_encode($output)); }
public function form_scan_shortcode($cond = null) { $manager = WPCF7_ShortcodeManager::get_instance(); if (!empty($this->scanned_form_tags)) { $scanned = $this->scanned_form_tags; } else { $scanned = $manager->scan_shortcode($this->prop('form')); $this->scanned_form_tags = $scanned; } if (empty($scanned)) { return array(); } if (!is_array($cond) || empty($cond)) { return $scanned; } for ($i = 0, $size = count($scanned); $i < $size; $i++) { if (isset($cond['type'])) { if (is_string($cond['type']) && !empty($cond['type'])) { if ($scanned[$i]['type'] != $cond['type']) { unset($scanned[$i]); continue; } } elseif (is_array($cond['type'])) { if (!in_array($scanned[$i]['type'], $cond['type'])) { unset($scanned[$i]); continue; } } } if (isset($cond['name'])) { if (is_string($cond['name']) && !empty($cond['name'])) { if ($scanned[$i]['name'] != $cond['name']) { unset($scanned[$i]); continue; } } elseif (is_array($cond['name'])) { if (!in_array($scanned[$i]['name'], $cond['name'])) { unset($scanned[$i]); continue; } } } } return array_values($scanned); }
function maybe_reset_autop($form) { $form_instance = WPCF7_ContactForm::get_current(); $manager = WPCF7_ShortcodeManager::get_instance(); $form_meta = get_post_meta($form_instance->id(), '_form', true); $form = $manager->do_shortcode($form_meta); $form_instance->set_properties(array('form' => $form)); return $form; }
function icl_wpcf7_collect_strings(&$contact_form) { $scanned = $contact_form->form_scan_shortcode(); foreach ($scanned as $tag) { if (!is_array($tag)) { continue; } $type = $tag['type']; $name = $tag['name']; $options = (array) $tag['options']; $raw_values = (array) $tag['raw_values']; $content = $tag['content']; $icl_option = array(); foreach ($options as $option) { if ('icl' == $option) { $icl_option = array('icl', null); break; } elseif (preg_match('/^icl:(.+)$/', $option, $matches)) { $icl_option = array('icl', $matches[1]); break; } } if (!('icl' == $type || $icl_option)) { continue; } $str_id = $icl_option[1] ? $icl_option[1] : $name; if (!empty($content)) { $string_name = icl_wpcf7_string_name($content, $str_id); icl_wpcf7_register_string($string_name, $content); } elseif (!empty($raw_values)) { foreach ($raw_values as $key => $value) { $value = trim($value); $string_name = icl_wpcf7_string_name($value, $str_id, $key); icl_wpcf7_register_string($string_name, $value); } } } /* From messages */ $messages = (array) $contact_form->messages; $shortcode_manager = new WPCF7_ShortcodeManager(); $shortcode_manager->add_shortcode('icl', create_function('$tag', 'return null;'), true); foreach ($messages as $message) { $tags = $shortcode_manager->scan_shortcode($message); foreach ($tags as $tag) { $name = $tag['name']; $values = (array) $tag['values']; $content = trim($tag['content']); if (!empty($content)) { $string_name = icl_wpcf7_string_name($content, $name); icl_wpcf7_register_string($string_name, $content); } else { foreach ($values as $key => $value) { $value = trim($value); $string_name = icl_wpcf7_string_name($value, $name, $key); icl_wpcf7_register_string($string_name, $value); } } } } }
function wpcf7_mailpoet_before_send_mail($contactform) { // make sure the user has Mailpoet (Wysija) and CF7 installed & active if (!class_exists('WYSIJA') || !class_exists('WPCF7_Submission')) { return; } // if (!empty($contactform->skip_mail)) { return; } // $posted_data = null; // get the instance that was submitted and the posted data $submission = WPCF7_Submission::get_instance(); $posted_data = $submission ? $submission->get_posted_data() : null; // and make sure they have something in their contact form if (empty($posted_data)) { return; } // get the tags that are in the form $manager = WPCF7_ShortcodeManager::get_instance(); $scanned_tags = $manager->get_scanned_tags(); // let's go add the user wpcf7_mailpoet_subscribe_to_lists($posted_data, $scanned_tags); }
/** * Add label and require <em> to CF7 form * * e.g. <li>Name [text* cf7s-name]</li> CHANGED TO * <li><label for="cf7s-name">Name <em class="cf7s-reqd">*</em></label> [text* cf7s-name]</li> * * @param $form Current CF7 form content * @since 0.0.1 */ function modify_form($form) { // Get all current shortcode $manager = WPCF7_ShortcodeManager::get_instance(); $scanned = $manager->scan_shortcode($form); // Get all shortcodes id with tag name as the index $ids = array(); foreach ($scanned as $tag) { $tag = new WPCF7_Shortcode($tag); $ids[$tag->name] = $tag->get_id_option() ? $tag->get_id_option() : $tag->name; } // Patterns for searching all list tag $pattern = "/<li ?.*>(.*)<\\/li>/"; preg_match_all($pattern, $form, $matches); if ($matches[0]) { // Loop trought each match foreach ($matches[0] as $list) { // Process only if the list have a shortcode if (preg_match("/\\[.*?\\]/", $list, $shortcode)) { // Explode shortcode by spaces to get the shortcode name $explode = explode(' ', str_replace(array('[', ']'), '', $shortcode[0])); $name = $explode[1]; $id = isset($ids[$name]) ? $ids[$name] : $name; // Add opening label tag $new_list = preg_replace("/(<li.*?>)(.*)(<\\/li>)/", "\$1<label for='{$id}'>\$2\$3", $list); // Closing label tag with * required em tag if (strpos($shortcode[0], '*') !== false) { $new_list = str_replace('[', '<em class="cf7s-reqd">*</em> </label>[', $new_list); } else { $new_list = str_replace('[', '</label>[', $new_list); } // Add label and em by replacing it. $form = str_replace($list, $new_list, $form); } } } return $form; }
public function validate_form() { $body = $this->contact_form->prop('form'); $pattern = '%<label(?:[ \\t\\n]+.*?)?>(.+?)</label>%s'; if (preg_match_all($pattern, $body, $matches)) { $manager = WPCF7_ShortcodeManager::get_instance(); foreach ($matches[1] as $insidelabel) { $tags = $manager->scan_shortcode($insidelabel); $fields_count = 0; foreach ($tags as $tag) { $tag = new WPCF7_Shortcode($tag); if (in_array($tag->basetype, array('checkbox', 'radio'))) { $fields_count += count($tag->values); if ($tag->has_option('free_text')) { $fields_count += 1; } } elseif (!empty($tag->name)) { $fields_count += 1; } if (1 < $fields_count) { $this->add_error('form.body', self::error_multiple_controls_in_label, array('link' => __('http://contactform7.com/configuration-errors/#form.body:error_multiple_controls_in_label', 'contact-form-7'))); return; } } } } }
public static function get_instance() { wpcf7_deprecated_function(__METHOD__, '4.6', 'WPCF7_FormTagsManager::get_instance'); self::$form_tags_manager = WPCF7_FormTagsManager::get_instance(); return new self(); }