/**
  * 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 wpcf7_do_shortcode($content)
{
    $manager = WPCF7_ShortcodeManager::get_instance();
    return $manager->do_shortcode($content);
}
示例#4
0
 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;
 }
示例#5
0
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);
}
示例#6
0
 /**
  * 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;
                 }
             }
         }
     }
 }