function cf7bs_number_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    $class .= ' wpcf7-validates-as-number';
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $value = (string) reset($tag->values);
    $placeholder = '';
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    } elseif (isset($_GET) && array_key_exists($tag->name, $_GET)) {
        $value = stripslashes_deep(rawurldecode($_GET[$tag->name]));
    }
    $field = new CF7BS_Form_Field(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => wpcf7_support_html5() ? $tag->basetype : 'text', 'value' => $value, 'placeholder' => $placeholder, 'label' => $tag->content, 'options' => array('min' => $tag->get_option('min', 'signed_int', true), 'max' => $tag->get_option('max', 'signed_int', true), 'step' => $tag->get_option('step', 'int', true)), 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'readonly' => $tag->has_option('readonly') ? true : false, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name));
    $html = $field->display(false);
    return $html;
}
Beispiel #2
0
 public static function shortcode_handler($tag)
 {
     $tag = new WPCF7_Shortcode($tag);
     if (empty($tag->name)) {
         return '';
     }
     $validation_error = wpcf7_get_validation_error($tag->name);
     $class = wpcf7_form_controls_class($tag->type, 'wpcf7-date');
     if ($validation_error) {
         $class .= ' wpcf7-not-valid';
     }
     $atts = array();
     $atts['size'] = $tag->get_size_option('40');
     $atts['maxlength'] = $tag->get_maxlength_option();
     $atts['class'] = $tag->get_class_option($class);
     $atts['id'] = $tag->get_option('id', 'id', true);
     $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
     $atts['type'] = 'text';
     if ($tag->has_option('readonly')) {
         $atts['readonly'] = 'readonly';
     }
     if ($tag->is_required()) {
         $atts['aria-required'] = 'true';
     }
     $value = (string) reset($tag->values);
     if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
         $atts['placeholder'] = $value;
         $value = '';
     }
     if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
         $value = stripslashes_deep($_POST[$tag->name]);
     }
     $atts['value'] = $value;
     $dpOptions = array();
     $dpOptions['dateFormat'] = str_replace('_', ' ', $tag->get_option('date-format', '', true));
     $dpOptions['minDate'] = $tag->get_option('min-date', '', true);
     $dpOptions['maxDate'] = $tag->get_option('max-date', '', true);
     $dpOptions['firstDay'] = (int) $tag->get_option('first-day', 'int', true);
     $dpOptions['showAnim'] = $tag->get_option('animate', '', true);
     $dpOptions['yearRange'] = str_replace('-', ':', $tag->get_option('year-range', '', true));
     $dpOptions['numberOfMonths'] = (int) $tag->get_option('months', 'int', true);
     $dpOptions['showButtonPanel'] = $tag->has_option('buttons');
     $dpOptions['changeMonth'] = $tag->has_option('change-month');
     $dpOptions['changeYear'] = $tag->has_option('change-year');
     $dpOptions['noWeekends'] = $tag->has_option('no-weekends');
     $inline = $tag->has_option('inline');
     if ($inline) {
         $dpOptions['altField'] = "#{$tag->name}_alt";
         $atts['id'] = "{$tag->name}_alt";
     }
     $atts['type'] = $inline ? 'hidden' : 'text';
     $atts['name'] = $tag->name;
     $atts = wpcf7_format_atts($atts);
     $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s %4$s</span>', $tag->name, $atts, $validation_error, $inline ? "<div id=\"{$tag->name}_datepicker\"></div>" : '');
     $html = apply_filters('cf7dp_date_input', $html);
     $dp_selector = $inline ? '#' . $tag->name . '_datepicker' : $tag->name;
     $dp = new CF7_DateTimePicker('date', $dp_selector, $dpOptions);
     self::$inline_js[] = $dp->generate_code($inline);
     return $html;
 }
function cf7bs_file_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    // size is not used since Bootstrap input fields always scale 100%
    //$atts['size'] = $tag->get_size_option( '40' );
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $value = (string) reset($tag->values);
    $placeholder = '';
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    } elseif (empty($value)) {
        $value = $tag->get_default_option();
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    }
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => 'file', 'value' => '1', 'label' => $tag->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name), $tag->basetype, $tag->name));
    $html = $field->display(false);
    return $html;
}
function cf7bs_captcha_shortcode_handler($tag)
{
    $tag_obj = new WPCF7_Shortcode($tag);
    if ('captchac' == $tag_obj->type && !class_exists('ReallySimpleCaptcha')) {
        return '<em>' . __('To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'bootstrap-for-contact-form-7') . '</em>';
    }
    if (empty($tag_obj->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag_obj->name);
    if ('captchac' == $tag_obj->type) {
        if ($image_sizes_array = preg_grep('%^size:[smlSML]$%', $tag['options'])) {
            $tag['options'] = array_values(array_diff_key($tag['options'], $image_sizes_array));
        }
        $size = cf7bs_get_form_property('size');
        $image_size = 'large' == $size ? 'l' : ('small' == $size ? 's' : 'm');
        $tag['options'][] = 'size:' . $image_size;
        $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => wpcf7_captcha_shortcode_handler($tag), 'type' => 'custom', 'label' => $tag_obj->content, 'help_text' => $validation_error, 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'tabindex' => false, 'wrapper_class' => ''), $tag_obj->basetype, $tag_obj->name));
        $html = $field->display(false);
        return $html;
    } elseif ('captchar' == $tag_obj->type) {
        $mode = $status = 'default';
        $class = wpcf7_form_controls_class($tag_obj->type, 'wpcf7-text');
        if ($validation_error) {
            $class .= ' wpcf7-not-valid';
            $status = 'error';
        }
        // size is not used since Bootstrap input fields always scale 100%
        //$atts['size'] = $tag->get_size_option( '40' );
        $value = (string) reset($tag_obj->values);
        $placeholder = '';
        if (wpcf7_is_posted()) {
            $value = '';
        }
        if ($tag_obj->has_option('placeholder') || $tag_obj->has_option('watermark')) {
            $placeholder = $value;
            $value = '';
        }
        $input_before = $input_after = '';
        if ($tag_obj->has_option('include_captchac') && class_exists('ReallySimpleCaptcha')) {
            $captchac_mode = $tag_obj->get_option('include_captchac', '[A-Za-z]+', true);
            if ($captchac_mode && 'after' == strtolower($captchac_mode)) {
                $captchac_mode = 'input_after';
            } else {
                $captchac_mode = 'input_before';
            }
            $tag = cf7bs_captchar_to_captchac($tag);
            ${$captchac_mode} = wpcf7_captcha_shortcode_handler($tag);
        }
        $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag_obj->name, 'id' => $tag_obj->get_option('id', 'id', true), 'class' => $tag_obj->get_class_option($class), 'type' => 'text', 'value' => $value, 'placeholder' => $placeholder, 'label' => $tag_obj->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'maxlength' => $tag_obj->get_maxlength_option(), 'tabindex' => $tag_obj->get_option('tabindex', 'int', true), 'wrapper_class' => $tag_obj->name, 'input_before' => $input_before, 'input_after' => $input_after, 'input_before_class' => 'input-group-addon input-group-has-image', 'input_after_class' => 'input-group-addon input-group-has-image'), $tag_obj->basetype, $tag_obj->name));
        $html = $field->display(false);
        return $html;
    }
    return '';
}
Beispiel #5
0
function wpcf7_text_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type, 'wpcf7-text');
    if (in_array($tag->basetype, array('email', 'url', 'tel'))) {
        $class .= ' wpcf7-validates-as-' . $tag->basetype;
    }
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('40');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    } elseif (empty($value) && is_user_logged_in()) {
        $user = wp_get_current_user();
        $user_options = array('default:user_login' => 'user_login', 'default:user_email' => 'user_email', 'default:user_url' => 'user_url', 'default:user_first_name' => 'first_name', 'default:user_last_name' => 'last_name', 'default:user_nickname' => 'nickname', 'default:user_display_name' => 'display_name');
        foreach ($user_options as $option => $prop) {
            if ($tag->has_option($option)) {
                $value = $user->{$prop};
                break;
            }
        }
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    }
    $atts['value'] = $value;
    if (wpcf7_support_html5()) {
        $atts['type'] = $tag->basetype;
    } else {
        $atts['type'] = 'text';
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', $tag->name, $atts, $validation_error);
    return $html;
}
Beispiel #6
0
function wpcf7_text_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type, 'wpcf7-text');
    if (in_array($tag->basetype, array('email', 'url', 'tel'))) {
        $class .= ' wpcf7-validates-as-' . $tag->basetype;
    }
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('40');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    } elseif ('' === $value) {
        $value = $tag->get_default_option();
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = wp_unslash($_POST[$tag->name]);
    }
    $atts['value'] = $value;
    if (wpcf7_support_html5()) {
        $atts['type'] = $tag->basetype;
    } else {
        $atts['type'] = 'text';
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
Beispiel #7
0
function wpcf7_date_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    $class .= ' wpcf7-validates-as-date';
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    $atts['min'] = $tag->get_option('min', 'date', true);
    $atts['max'] = $tag->get_option('max', 'date', true);
    $atts['step'] = $tag->get_option('step', 'int', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    }
    $atts['value'] = $value;
    if (wpcf7_support_html5()) {
        $atts['type'] = $tag->basetype;
    } else {
        $atts['type'] = 'text';
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', $tag->name, $atts, $validation_error);
    return $html;
}
Beispiel #8
0
function wpcf7_textarea_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['cols'] = $tag->get_cols_option('');
    $atts['rows'] = $tag->get_rows_option('');
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $value = (string) reset($tag->values);
    if ('' !== $tag->content) {
        $value = $tag->content;
    }
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    }
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<textarea %2$s></textarea>', $tag->name, $atts, esc_textarea($value), $validation_error);
    return $html;
}
function cf7bs_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    $exclusive = $tag->has_option('exclusive');
    $free_text = $tag->has_option('free_text');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $values = (array) $tag->values;
    $labels = (array) $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        if ($free_text) {
            $values = array_merge(array_slice($values, 0, -1), array_values($data), array_slice($values, -1));
            $labels = array_merge(array_slice($labels, 0, -1), array_values($data), array_slice($labels, -1));
        } else {
            $values = array_merge($values, array_values($data));
            $labels = array_merge($labels, array_values($data));
        }
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = array_merge($defaults, explode('_', $matches[1]));
    }
    $defaults = array_unique($defaults);
    $options = array();
    $checked = '';
    if ($multiple) {
        $checked = array();
    }
    if (isset($_POST[$tag->name])) {
        $post = $_POST[$tag->name];
    } else {
        if (isset($_GET[$tag->name])) {
            if ($multiple) {
                $get = cf7bs_array_decode(rawurldecode($_GET[$tag->name]));
            } else {
                $get = rawurldecode($_GET[$tag->name]);
            }
        }
        $post = $multiple ? array() : '';
    }
    $posted = wpcf7_is_posted();
    $count = 0;
    foreach ((array) $tag->values as $key => $value) {
        if ($free_text && $count == count($tag->values) - 1) {
            $options[$value] = '<input type="text" name="' . sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name) . '" class="wpcf7-free-text">';
        } else {
            $options[$value] = isset($labels[$key]) ? $labels[$key] : $value;
        }
        if ($posted && !empty($post)) {
            if ($multiple && in_array(esc_sql($value), (array) $post)) {
                $checked[] = $value;
            }
            if (!$multiple && $post == esc_sql($value)) {
                $checked = $value;
            }
        } elseif (isset($get) && !empty($get)) {
            if ($multiple && in_array(esc_sql($value), (array) $get)) {
                $checked[] = $value;
            }
            if (!$multiple && $get == esc_sql($value)) {
                $checked = $value;
            }
        } elseif (in_array($key + 1, (array) $defaults)) {
            if ($multiple) {
                $checked[] = $value;
            } else {
                $checked = $value;
            }
        }
        $count++;
    }
    $label = $tag->content;
    if (count($options) < 1) {
        if ($free_text) {
            $options = array('true' => '<input type="text" name="' . sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name) . '" class="wpcf7-free-text">');
        } else {
            $options = array('true' => $label);
            $label = '';
        }
    }
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => '', 'type' => $tag->basetype, 'value' => $checked, 'label' => $label, 'options' => $options, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'group_layout' => cf7bs_get_form_property('group_layout'), 'group_type' => cf7bs_get_form_property('group_type'), 'mode' => $mode, 'status' => $status, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->get_class_option($class . ' ' . $tag->name)), $tag->basetype, $tag->name));
    $html = $field->display(false);
    return $html;
}
Beispiel #10
0
function wpcf7_captcha_shortcode_handler($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    if (empty($name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($name);
    $atts = $id_att = $size_att = $maxlength_att = $tabindex_att = $title_att = '';
    $class_att = wpcf7_form_controls_class($type);
    if ('captchac' == $type) {
        $class_att .= ' wpcf7-captcha-' . $name;
    }
    if ($validation_error && 'captchar' == $type) {
        $class_att .= ' wpcf7-not-valid';
    }
    foreach ($options as $option) {
        if (preg_match('%^id:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $id_att = $matches[1];
        } elseif (preg_match('%^class:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $class_att .= ' ' . $matches[1];
        } elseif (preg_match('%^([0-9]*)[/x]([0-9]*)$%', $option, $matches)) {
            $size_att = (int) $matches[1];
            $maxlength_att = (int) $matches[2];
        } elseif (preg_match('%^tabindex:(\\d+)$%', $option, $matches)) {
            $tabindex_att = (int) $matches[1];
        }
    }
    // Value.
    $value = '';
    if ('captchar' == $type && !wpcf7_is_posted() && isset($values[0])) {
        $value = $values[0];
        if (wpcf7_script_is() && preg_grep('%^watermark$%', $options)) {
            $class_att .= ' wpcf7-use-title-as-watermark';
            $title_att .= sprintf(' %s', $value);
            $value = '';
        }
    }
    if ($id_att) {
        $atts .= ' id="' . trim($id_att) . '"';
    }
    if ($class_att) {
        $atts .= ' class="' . trim($class_att) . '"';
    }
    if ('captchac' == $type) {
        if (!class_exists('ReallySimpleCaptcha')) {
            return '<em>' . __('To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'wpcf7') . '</em>';
        }
        $op = array();
        // Default
        $op['img_size'] = array(72, 24);
        $op['base'] = array(6, 18);
        $op['font_size'] = 14;
        $op['font_char_width'] = 15;
        $op = array_merge($op, wpcf7_captchac_options($options));
        if (!($filename = wpcf7_generate_captcha($op))) {
            return '';
        }
        if (is_array($op['img_size'])) {
            $atts .= ' width="' . $op['img_size'][0] . '" height="' . $op['img_size'][1] . '"';
        }
        $captcha_url = trailingslashit(wpcf7_captcha_tmp_url()) . $filename;
        $html = '<img alt="captcha" src="' . $captcha_url . '"' . $atts . ' />';
        $ref = substr($filename, 0, strrpos($filename, '.'));
        $html = '<input type="hidden" name="_wpcf7_captcha_challenge_' . $name . '" value="' . $ref . '" />' . $html;
        return $html;
    } elseif ('captchar' == $type) {
        if ($size_att) {
            $atts .= ' size="' . $size_att . '"';
        } else {
            $atts .= ' size="40"';
        }
        // default size
        if ($maxlength_att) {
            $atts .= ' maxlength="' . $maxlength_att . '"';
        }
        if ('' !== $tabindex_att) {
            $atts .= sprintf(' tabindex="%d"', $tabindex_att);
        }
        if ('' !== $title_att) {
            $atts .= sprintf(' title="%s"', trim(esc_attr($title_att)));
        }
        $html = '<input type="text" name="' . $name . '" value="' . esc_attr($value) . '"' . $atts . ' />';
        $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
        return $html;
    }
}
Beispiel #11
0
function wpcf7_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $label_first = $tag->has_option('label_first');
    $use_label_element = $tag->has_option('use_label_element');
    $exclusive = $tag->has_option('exclusive');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        // radio
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $tabindex = $tag->get_option('tabindex', 'int', true);
    if (false !== $tabindex) {
        $tabindex = absint($tabindex);
    }
    $defaults = array();
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = explode('_', $matches[1]);
    }
    if (isset($_POST[$tag->name])) {
        $post = $_POST[$tag->name];
    } else {
        $post = $multiple ? array() : '';
    }
    $is_posted = wpcf7_is_posted();
    $html = '';
    foreach ((array) $tag->values as $key => $value) {
        $checked = false;
        if ($is_posted && !empty($post)) {
            if ($multiple && in_array(esc_sql($value), (array) $post)) {
                $checked = true;
            }
            if (!$multiple && $post == esc_sql($value)) {
                $checked = true;
            }
        } else {
            if (in_array($key + 1, (array) $defaults)) {
                $checked = true;
            }
        }
        if (isset($tag->labels[$key])) {
            $label = $tag->labels[$key];
        } else {
            $label = $value;
        }
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => $value, 'checked' => $checked ? 'checked' : '', 'tabindex' => $tabindex ? $tabindex : '');
        $item_atts = wpcf7_format_atts($item_atts);
        if ($label_first) {
            // put label first, input last
            $item = sprintf('<span class="wpcf7-list-item-label">%1$s</span>&nbsp;<input %2$s />', esc_html($label), $item_atts);
        } else {
            $item = sprintf('<input %2$s />&nbsp;<span class="wpcf7-list-item-label">%1$s</span>', esc_html($label), $item_atts);
        }
        if ($use_label_element) {
            $item = '<label>' . $item . '</label>';
        }
        $item = '<span class="wpcf7-list-item">' . $item . '</span>';
        $html .= $item;
        if (false !== $tabindex) {
            $tabindex += 1;
        }
    }
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>', $tag->name, $atts, $html, $validation_error);
    return $html;
}
Beispiel #12
0
function cf7bs_select_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    if ($tag->is_required()) {
        $mode = 'required';
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = explode('_', $matches[1]);
    }
    $defaults = array_unique($defaults);
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $first_as_label = $tag->has_option('first_as_label');
    $values = $tag->values;
    $labels = $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        $values = array_merge($values, array_values($data));
        $labels = array_merge($labels, array_values($data));
    }
    $empty_select = empty($values);
    $shifted = false;
    if ($empty_select || $include_blank) {
        array_unshift($labels, '---');
        array_unshift($values, '');
        $shifted = true;
    } elseif ($first_as_label) {
        $values[0] = '';
    }
    $options = array();
    $selected = '';
    if ($multiple) {
        $selected = array();
    }
    if (isset($_POST[$tag->name])) {
        $post = $_POST[$tag->name];
    } else {
        if (isset($_GET[$tag->name])) {
            if ($multiple) {
                $get = cf7bs_array_decode(rawurldecode($_GET[$tag->name]));
            } else {
                $get = rawurldecode($_GET[$tag->name]);
            }
        }
        $post = $multiple ? array() : '';
    }
    $posted = wpcf7_is_posted();
    foreach ($values as $key => $value) {
        $options[$value] = isset($labels[$key]) ? $labels[$key] : $value;
        if ($posted && !empty($post)) {
            if ($multiple && in_array(esc_sql($value), (array) $post)) {
                $selected[] = $value;
            }
            if (!$multiple && $post == esc_sql($value)) {
                $selected = $value;
            }
        } elseif (isset($get) && !empty($get)) {
            if ($multiple && in_array(esc_sql($value), (array) $get)) {
                $selected[] = $value;
            }
            if (!$multiple && $get == esc_sql($value)) {
                $selected = $value;
            }
        } elseif (!$shifted && in_array((int) $key + 1, (array) $defaults) || $shifted && in_array((int) $key, (array) $defaults)) {
            if ($multiple) {
                $selected[] = $value;
            } else {
                $selected = $value;
            }
        }
    }
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => $multiple ? 'multiselect' : 'select', 'value' => $selected, 'label' => $tag->content, 'options' => $options, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name), $tag->basetype, $tag->name));
    $html = $field->display(false);
    return $html;
}
function wpcf7_checkbox_shortcode_handler($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    $labels = (array) $tag['labels'];
    if (empty($name)) {
        return '';
    }
    $atts = '';
    $id_att = '';
    $class_att = '';
    $tabindex_att = '';
    $defaults = array();
    $label_first = false;
    $use_label_element = false;
    if ('checkbox*' == $type) {
        $class_att .= ' wpcf7-validates-as-required';
    }
    if ('checkbox' == $type || 'checkbox*' == $type) {
        $class_att .= ' wpcf7-checkbox';
    }
    if ('radio' == $type) {
        $class_att .= ' wpcf7-radio';
    }
    foreach ($options as $option) {
        if (preg_match('%^id:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $id_att = $matches[1];
        } elseif (preg_match('%^class:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $class_att .= ' ' . $matches[1];
        } elseif (preg_match('/^default:([0-9_]+)$/', $option, $matches)) {
            $defaults = explode('_', $matches[1]);
        } elseif (preg_match('%^label[_-]?first$%', $option)) {
            $label_first = true;
        } elseif (preg_match('%^use[_-]?label[_-]?element$%', $option)) {
            $use_label_element = true;
        } elseif (preg_match('%^tabindex:(\\d+)$%', $option, $matches)) {
            $tabindex_att = (int) $matches[1];
        }
    }
    $multiple = false;
    $exclusive = (bool) preg_grep('%^exclusive$%', $options);
    if ('checkbox' == $type || 'checkbox*' == $type) {
        $multiple = !$exclusive;
    } else {
        // radio
        $exclusive = false;
    }
    if ($exclusive) {
        $class_att .= ' wpcf7-exclusive-checkbox';
    }
    if ($id_att) {
        $atts .= ' id="' . trim($id_att) . '"';
    }
    if ($class_att) {
        $atts .= ' class="' . trim($class_att) . '"';
    }
    $html = '';
    $input_type = rtrim($type, '*');
    $posted = wpcf7_is_posted();
    foreach ($values as $key => $value) {
        $checked = false;
        if ($posted && !empty($_POST[$name])) {
            if ($multiple && in_array(esc_sql($value), (array) $_POST[$name])) {
                $checked = true;
            }
            if (!$multiple && $_POST[$name] == esc_sql($value)) {
                $checked = true;
            }
        } else {
            if (in_array($key + 1, (array) $defaults)) {
                $checked = true;
            }
        }
        $checked = $checked ? ' checked="checked"' : '';
        if ('' !== $tabindex_att) {
            $tabindex = sprintf(' tabindex="%d"', $tabindex_att);
            $tabindex_att += 1;
        } else {
            $tabindex = '';
        }
        if (isset($labels[$key])) {
            $label = $labels[$key];
        } else {
            $label = $value;
        }
        if ($label_first) {
            // put label first, input last
            $item = '<span class="wpcf7-list-item-label">' . esc_html($label) . '</span>&nbsp;';
            $item .= '<input type="' . $input_type . '" name="' . $name . ($multiple ? '[]' : '') . '" value="' . esc_attr($value) . '"' . $checked . $tabindex . ' />';
        } else {
            $item = '<input type="' . $input_type . '" name="' . $name . ($multiple ? '[]' : '') . '" value="' . esc_attr($value) . '"' . $checked . $tabindex . ' />';
            $item .= '&nbsp;<span class="wpcf7-list-item-label">' . esc_html($label) . '</span>';
        }
        if ($use_label_element) {
            $item = '<label>' . $item . '</label>';
        }
        $item = '<span class="wpcf7-list-item">' . $item . '</span>';
        $html .= $item;
    }
    $html = '<span' . $atts . '>' . $html . '</span>';
    $validation_error = wpcf7_get_validation_error($name);
    $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
    return $html;
}
Beispiel #14
0
function wpcf7_select_shortcode_handler($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    $labels = (array) $tag['labels'];
    if (empty($name)) {
        return '';
    }
    $atts = '';
    $id_att = '';
    $class_att = '';
    $tabindex_att = '';
    $defaults = array();
    $class_att .= ' wpcf7-select';
    if ('select*' == $type) {
        $class_att .= ' wpcf7-validates-as-required';
    }
    foreach ($options as $option) {
        if (preg_match('%^id:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $id_att = $matches[1];
        } elseif (preg_match('%^class:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $class_att .= ' ' . $matches[1];
        } elseif (preg_match('/^default:([0-9_]+)$/', $option, $matches)) {
            $defaults = explode('_', $matches[1]);
        } elseif (preg_match('%^tabindex:(\\d+)$%', $option, $matches)) {
            $tabindex_att = (int) $matches[1];
        }
    }
    if ($id_att) {
        $atts .= ' id="' . trim($id_att) . '"';
    }
    if ($class_att) {
        $atts .= ' class="' . trim($class_att) . '"';
    }
    if ('' !== $tabindex_att) {
        $atts .= sprintf(' tabindex="%d"', $tabindex_att);
    }
    $multiple = (bool) preg_grep('%^multiple$%', $options);
    $include_blank = (bool) preg_grep('%^include_blank$%', $options);
    $empty_select = empty($values);
    if ($empty_select || $include_blank) {
        array_unshift($labels, '---');
        array_unshift($values, '---');
    }
    $html = '';
    $posted = wpcf7_is_posted();
    foreach ($values as $key => $value) {
        $selected = false;
        if ($posted) {
            if ($multiple && in_array(esc_sql($value), (array) $_POST[$name])) {
                $selected = true;
            }
            if (!$multiple && $_POST[$name] == esc_sql($value)) {
                $selected = true;
            }
        } else {
            if (!$empty_select && in_array($key + 1, (array) $defaults)) {
                $selected = true;
            }
        }
        $selected = $selected ? ' selected="selected"' : '';
        if (isset($labels[$key])) {
            $label = $labels[$key];
        } else {
            $label = $value;
        }
        $html .= '<option value="' . esc_attr($value) . '"' . $selected . '>' . esc_html($label) . '</option>';
    }
    if ($multiple) {
        $atts .= ' multiple="multiple"';
    }
    $html = '<select name="' . $name . ($multiple ? '[]' : '') . '"' . $atts . '>' . $html . '</select>';
    $validation_error = wpcf7_get_validation_error($name);
    $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
    return $html;
}
Beispiel #15
0
function wpcf7_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $label_first = $tag->has_option('label_first');
    $use_label_element = $tag->has_option('use_label_element');
    $exclusive = $tag->has_option('exclusive');
    $free_text = $tag->has_option('free_text');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        // radio
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $tabindex = $tag->get_option('tabindex', 'int', true);
    if (false !== $tabindex) {
        $tabindex = absint($tabindex);
    }
    $html = '';
    $count = 0;
    $values = (array) $tag->values;
    $labels = (array) $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        if ($free_text) {
            $values = array_merge(array_slice($values, 0, -1), array_values($data), array_slice($values, -1));
            $labels = array_merge(array_slice($labels, 0, -1), array_values($data), array_slice($labels, -1));
        } else {
            $values = array_merge($values, array_values($data));
            $labels = array_merge($labels, array_values($data));
        }
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = array_merge($defaults, explode('_', $matches[1]));
    }
    $defaults = array_unique($defaults);
    $hangover = wpcf7_get_hangover($tag->name, $multiple ? array() : '');
    foreach ($values as $key => $value) {
        $class = 'wpcf7-list-item';
        $checked = false;
        if ($hangover) {
            if ($multiple) {
                $checked = in_array(esc_sql($value), (array) $hangover);
            } else {
                $checked = $hangover == esc_sql($value);
            }
        } else {
            $checked = in_array($key + 1, (array) $defaults);
        }
        if (isset($labels[$key])) {
            $label = $labels[$key];
        } else {
            $label = $value;
        }
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => $value, 'checked' => $checked ? 'checked' : '', 'tabindex' => $tabindex ? $tabindex : '');
        $item_atts = wpcf7_format_atts($item_atts);
        if ($label_first) {
            // put label first, input last
            $item = sprintf('<span class="wpcf7-list-item-label">%1$s</span>&nbsp;<input %2$s />', esc_html($label), $item_atts);
        } else {
            $item = sprintf('<input %2$s />&nbsp;<span class="wpcf7-list-item-label">%1$s</span>', esc_html($label), $item_atts);
        }
        if ($use_label_element) {
            $item = '<label>' . $item . '</label>';
        }
        if (false !== $tabindex) {
            $tabindex += 1;
        }
        $count += 1;
        if (1 == $count) {
            $class .= ' first';
        }
        if (count($values) == $count) {
            // last round
            $class .= ' last';
            if ($free_text) {
                $free_text_name = sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name);
                $free_text_atts = array('name' => $free_text_name, 'class' => 'wpcf7-free-text', 'tabindex' => $tabindex ? $tabindex : '');
                if (wpcf7_is_posted() && isset($_POST[$free_text_name])) {
                    $free_text_atts['value'] = wp_unslash($_POST[$free_text_name]);
                }
                $free_text_atts = wpcf7_format_atts($free_text_atts);
                $item .= sprintf(' <input type="text" %s />', $free_text_atts);
                $class .= ' has-free-text';
            }
        }
        $item = '<span class="' . esc_attr($class) . '">' . $item . '</span>';
        $html .= $item;
    }
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>', sanitize_html_class($tag->name), $atts, $html, $validation_error);
    return $html;
}
function wpcf7_select_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $defaults = array();
    if ($matches = $tag->get_first_match_option('/^default:([0-9_]+)$/')) {
        $defaults = explode('_', $matches[1]);
    }
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $name = $tag->name;
    $values = $tag->values;
    $labels = $tag->labels;
    $empty_select = empty($values);
    if ($empty_select || $include_blank) {
        array_unshift($labels, '---');
        array_unshift($values, '');
    }
    $html = '';
    $posted = wpcf7_is_posted();
    foreach ($values as $key => $value) {
        $selected = false;
        if ($posted && !empty($_POST[$name])) {
            if ($multiple && in_array(esc_sql($value), (array) $_POST[$name])) {
                $selected = true;
            }
            if (!$multiple && $_POST[$name] == esc_sql($value)) {
                $selected = true;
            }
        } else {
            if (!$empty_select && in_array($key + 1, (array) $defaults)) {
                $selected = true;
            }
        }
        $item_atts = array('value' => $value, 'selected' => $selected ? 'selected' : '');
        $item_atts = wpcf7_format_atts($item_atts);
        $label = isset($labels[$key]) ? $labels[$key] : $value;
        $html .= sprintf('<option %1$s>%2$s</option>', $item_atts, esc_html($label));
    }
    if ($multiple) {
        $atts['multiple'] = 'multiple';
    }
    $atts['name'] = $tag->name . ($multiple ? '[]' : '');
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><select %2$s>%3$s</select>%4$s</span>', $tag->name, $atts, $html, $validation_error);
    return $html;
}
Beispiel #17
0
function wpcf7_mailpoetsignup_shortcode_handler($tag)
{
    // if cf7 is not active, leave
    if (!class_exists('WPCF7_Shortcode')) {
        return;
    }
    // create a new tag
    $tag = new WPCF7_Shortcode($tag);
    // if the tag doesn't have a name, return empty handed
    if (empty($tag->name)) {
        return '';
    }
    // check for errors and set the class
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    // if there were errors, add class
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    // init the atts array, add the class and id set in the shortcode
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_option('id', 'id', true);
    // get checkbox value
    // first get all of the lists
    $lists = wpcf7_mailpoetsignup_get_lists();
    if (!empty($lists)) {
        $checkbox_values = array();
        // go through each list
        foreach ($lists as $key => $l) {
            // check if that list was added to the form
            if ($tag->has_option('mailpoet_list_' . $l['list_id'])) {
                // add the list into the array of checkbox values
                $checkbox_values[] = 'mailpoet_list_' . $l['list_id'];
            }
        }
    }
    // do we have any lists?
    if (!empty($checkbox_values)) {
        // implode them all into a comma separated string
        $atts['value'] = implode($checkbox_values, ',');
    } else {
        // we apparently have no lists
        // set a 0 so we know to add the user to Mailpoet but not to any specific list
        $atts['value'] = '0';
    }
    // is it required?
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    // set default checked state
    $atts['checked'] = $tag->has_option('default:on') ? 'checked' : '';
    // default tag value
    $value = (string) reset($tag->values);
    // if the tag has a default value, add it
    if ('' !== $tag->content) {
        $value = $tag->content;
    }
    // if the tag has a posted value, add it
    if (wpcf7_is_posted() && isset($_POST[$tag->name])) {
        $value = stripslashes_deep($_POST[$tag->name]);
    }
    // set the name and the id of the field
    $atts['name'] = $tag->name;
    $id = !empty($atts['id']) ? $atts['id'] : $atts['name'];
    // put all of the atts into a string for the field
    $atts = wpcf7_format_atts($atts);
    // get the content from the tag to make the checkbox label
    $label = __('Sign up for the newsletter', 'mpcf7');
    $values = $tag->values;
    if (isset($values) && !empty($values)) {
        $label = esc_textarea($values[0]);
    }
    // should the label be inside the span?
    if ($tag->has_option('label-inside-span')) {
        // create the field
        $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input type="checkbox" %2$s />&nbsp;<label for="%3$s">%4$s</label></span>&nbsp;%5$s', $tag->name, $atts, $id, $value, $validation_error);
    } else {
        // create the field
        $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input type="checkbox" %2$s />&nbsp;</span><label for="%3$s">%4$s</label>&nbsp;%5$s', $tag->name, $atts, $id, $value, $validation_error);
    }
    return $html;
}
function wpcf7_mailpoetsignup_shortcode_handler( $tag ) {

	$tag = new WPCF7_Shortcode( $tag );

	if ( empty( $tag->name ) ) {
		return '';
	}

	$validation_error = wpcf7_get_validation_error( $tag->name );

	$class = wpcf7_form_controls_class( $tag->type );

	if ( $validation_error ) {
		$class .= ' wpcf7-not-valid';
	}

	$atts = array();

	$atts['class'] = $tag->get_class_option( $class );
	$atts['id'] = $tag->get_option( 'id', 'id', true );

	// get checkbox value
	// first get all of the lists
	$lists = wpcf7_mailpoetsignup_get_lists();
	if ( ! empty ( $lists ) ) {
		$checkbox_values = array();
		foreach ( $lists as $key => $l ) {
			// check if that list was added to the form
			if ( $tag->has_option( 'mailpoet_list_' . $l['list_id'] ) ) {
				// add the list id into the array of checkbox values
				$checkbox_values[] = $l['list_id'];
			}
		}
	}

	// we still want a value for the checkbox so *some* data gets posted
	if ( ! empty ( $checkbox_values ) ) {
		// now implode them all into a comma separated string
		$atts['value'] = implode( $checkbox_values, "," );
	} else {
		// set a 0 so we know to add the user to Mailpoet but not to any specific list
		$atts['value'] = "0";
	}


	if ( $tag->is_required() ) {
		$atts['aria-required'] = 'true';
	}

	// set default checked state
	$atts['checked'] = "";
	if ( $tag->has_option( 'default:on' ) ) {
		$atts['checked'] = 'checked';
	}

	$value = (string) reset( $tag->values );

	if ( '' !== $tag->content ) {
		$value = $tag->content;
	}

	if ( wpcf7_is_posted() && isset( $_POST[$tag->name] ) ) {
		$value = stripslashes_deep( $_POST[$tag->name] );
	}

	$atts['name'] = $tag->name;
	$id = $atts['id'] = $atts['name'];

	$atts = wpcf7_format_atts( $atts );

	// get the content from the tag to make the checkbox label
	$label = __( 'Sign up for the newsletter', 'mpcf7' );
	$values = $tag->values;
	if( isset( $values ) && !empty ($values) ){
		$label = esc_textarea( $values[0] );
	}

	$html = sprintf(
		'<span class="wpcf7-form-control-wrap %1$s"><input type="checkbox" %2$s />&nbsp;</span><label for="%3$s">%4$s</label>&nbsp;%5$s',
		$tag->name, $atts, $id, $value, $validation_error );

	return $html;
}
function cf7bs_text_shortcode_handler($tag)
{
    $tag_obj = new WPCF7_Shortcode($tag);
    if (empty($tag_obj->name)) {
        return '';
    }
    $mode = $status = 'default';
    $validation_error = wpcf7_get_validation_error($tag_obj->name);
    $class = wpcf7_form_controls_class($tag_obj->type, 'wpcf7-text');
    if (in_array($tag_obj->basetype, array('email', 'url', 'tel'))) {
        $class .= ' wpcf7-validates-as-' . $tag_obj->basetype;
    }
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
        $status = 'error';
    }
    // size is not used since Bootstrap input fields always scale 100%
    //$atts['size'] = $tag_obj->get_size_option( '40' );
    if ($tag_obj->is_required()) {
        $mode = 'required';
    }
    $value = (string) reset($tag_obj->values);
    $placeholder = '';
    if ($tag_obj->has_option('placeholder') || $tag_obj->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    }
    $value = $tag_obj->get_default_option($value);
    if (wpcf7_is_posted() && isset($_POST[$tag_obj->name])) {
        $value = stripslashes_deep($_POST[$tag_obj->name]);
    } elseif (isset($_GET) && array_key_exists($tag_obj->name, $_GET)) {
        $value = stripslashes_deep(rawurldecode($_GET[$tag_obj->name]));
    }
    $input_before = $tag_obj->get_first_match_option('/input_before:([^\\s]+)/');
    $input_after = $tag_obj->get_first_match_option('/input_after:([^\\s]+)/');
    if (is_array($input_before) && isset($input_before[1])) {
        $input_before = str_replace('---', ' ', $input_before[1]);
    } else {
        $input_before = '';
    }
    if (is_array($input_after) && isset($input_after[1])) {
        $input_after = str_replace('---', ' ', $input_after[1]);
    } else {
        $input_after = '';
    }
    if ($tag_obj->has_option('include_count')) {
        $count_mode = 'input_after';
        $count_down = false;
        $count_options = $tag_obj->get_option('include_count', '[A-Za-z]+(:[A-Za-z]+)?', true);
        if ($count_options) {
            $count_options = explode(':', $count_options);
            foreach ($count_options as $count_option) {
                switch ($count_option) {
                    case 'down':
                    case 'DOWN':
                        $count_down = true;
                        break;
                    case 'before':
                    case 'BEFORE':
                        $count_mode = 'input_before';
                        break;
                    default:
                }
            }
        }
        $tag = cf7bs_text_to_count($tag, $count_down);
        if (!empty(${$count_mode})) {
            ${$count_mode} = wpcf7_count_shortcode_handler($tag) . ' ' . ${$count_mode};
        } else {
            ${$count_mode} = wpcf7_count_shortcode_handler($tag);
        }
    }
    $field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag_obj->name, 'id' => $tag_obj->get_option('id', 'id', true), 'class' => $tag_obj->get_class_option($class), 'type' => wpcf7_support_html5() ? $tag_obj->basetype : 'text', 'value' => $value, 'placeholder' => $placeholder, 'label' => $tag_obj->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'mode' => $mode, 'status' => $status, 'readonly' => $tag_obj->has_option('readonly') ? true : false, 'minlength' => $tag_obj->get_minlength_option(), 'maxlength' => $tag_obj->get_maxlength_option(), 'tabindex' => $tag_obj->get_option('tabindex', 'int', true), 'wrapper_class' => $tag_obj->name, 'input_before' => $input_before, 'input_after' => $input_after), $tag_obj->basetype, $tag_obj->name));
    $html = $field->display(false);
    return $html;
}
Beispiel #20
0
function wpcf7_hidden_shortcode_handler($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $type = $tag['type'];
    $name = $raw_name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    if (empty($name)) {
        return '';
    }
    $atts = '';
    $id_att = '';
    $class_att = '';
    $size_att = '';
    $maxlength_att = '';
    $tabindex_att = '';
    $title_att = '';
    $class_att .= ' wpcf7-hidden';
    if ('hidden*' == $type) {
        $class_att .= ' wpcf7-validates-as-required';
    }
    foreach ($options as $option) {
        if (preg_match('%^id:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $id_att = $matches[1];
        } elseif (preg_match('%^class:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $class_att .= ' ' . $matches[1];
        }
    }
    $value = (string) reset($values);
    if (wpcf7_script_is() && $value && preg_grep('%^watermark$%', $options)) {
        $class_att .= ' wpcf7-use-title-as-watermark';
        $title_att .= sprintf(' %s', $value);
        $value = '';
    }
    if (wpcf7_is_posted()) {
        $value = stripslashes_deep($_POST[$name]);
    }
    if ($id_att) {
        $id_att = trim($id_att);
        $atts .= ' id="' . trim($id_att) . '"';
    }
    if ($class_att) {
        $atts .= ' class="' . trim($class_att) . '"';
    }
    // Add support for new CF7 format
    if (preg_match('/hidden/ism', $name)) {
        $name = isset($values[0]) ? $values[0] : $name;
    }
    $sanitized_name = strtolower(trim($name));
    global $post;
    if (is_object($post)) {
        switch ($sanitized_name) {
            case 'post_title':
            case 'post-title':
                $value = $post->post_title;
                break;
            case 'page_url':
            case 'post_url':
                $value = get_permalink($post->ID);
                if (empty($value) && isset($post->guid)) {
                    $value = $post->guid;
                }
                $value = esc_url($value);
                break;
            case 'post_category':
                $categories = get_the_category($post->ID);
                $catnames = array();
                // Get the category names
                foreach ($categories as $cat) {
                    $catnames[] = $cat->cat_name;
                }
                $value = implode(', ', $catnames);
                break;
            case 'post_author_id':
                $value = $post->post_author;
                break;
            case 'post_author':
                $user = get_userdata($post->post_author);
                $value = $user->display_name;
                break;
            default:
                // You want post_modified? just use [hidden hidden-123 "post_modified"]
                if (isset($post->{$name})) {
                    $value = $post->{$name};
                }
                break;
        }
        if (preg_match('/^custom_field\\-(.*?)$/ism', $sanitized_name)) {
            $custom_field = preg_replace('/custom_field\\-(.*?)/ism', '$1', $name);
            $value = get_post_meta($post->ID, $custom_field, false) ? get_post_meta($post->ID, $custom_field, false) : '';
        }
    }
    // Process user stuff
    if (preg_match('/user/ism', $sanitized_name) && is_user_logged_in()) {
        global $current_user;
        get_currentuserinfo();
        switch ($sanitized_name) {
            case 'user_name':
                $value = $current_user->user_login;
                break;
            case 'user_id':
                $value = $current_user->ID;
                break;
            case 'caps':
                $value = $current_user->caps;
                break;
            case 'allcaps':
                $value = $current_user->allcaps;
                break;
            case 'user_roles':
                $value = $current_user->roles;
                break;
            default:
                // Gets the values for `user_email`, others that have `user_` prefix.
                if ($current_user->has_prop($sanitized_name)) {
                    $value = $current_user->get($sanitized_name);
                } else {
                    // Define some other item in the WP_User object using the `user_[what you want to get]` format
                    // This works for the `user_display_name` setting
                    $user_key = preg_replace('/user[_-](.+)/ism', '$1', $sanitized_name);
                    if ($current_user->has_prop($user_key)) {
                        $value = $current_user->get($user_key);
                    }
                }
                break;
        }
    }
    // Arrays get imploded.
    $value = is_array($value) ? implode(apply_filters('wpcf7_hidden_field_implode_glue', ', '), $value) : $value;
    // Make sure we're using a string
    if (!is_string($value)) {
        $value = json_encode($value);
    }
    $value = apply_filters('wpcf7_hidden_field_value', apply_filters('wpcf7_hidden_field_value_' . $id_att, $value));
    $html = '<input type="hidden" name="' . $raw_name . '" value="' . esc_attr($value) . '"' . $atts . ' />' . "\n";
    if ($name !== $raw_name) {
        $html .= '<input type="hidden" name="' . $name . '" value="' . esc_attr($value) . '"' . $atts . ' />';
    }
    return $html;
}
function wpcf7_text_shortcode_handler($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    if (empty($name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($name);
    $atts = $id_att = $size_att = $maxlength_att = '';
    $tabindex_att = $title_att = '';
    $class_att = wpcf7_form_controls_class($type, 'wpcf7-text');
    if ('email' == $type || 'email*' == $type) {
        $class_att .= ' wpcf7-validates-as-email';
    }
    if ($validation_error) {
        $class_att .= ' wpcf7-not-valid';
    }
    foreach ($options as $option) {
        if (preg_match('%^id:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $id_att = $matches[1];
        } elseif (preg_match('%^class:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $class_att .= ' ' . $matches[1];
        } elseif (preg_match('%^([0-9]*)[/x]([0-9]*)$%', $option, $matches)) {
            $size_att = (int) $matches[1];
            $maxlength_att = (int) $matches[2];
        } elseif (preg_match('%^tabindex:(\\d+)$%', $option, $matches)) {
            $tabindex_att = (int) $matches[1];
        }
    }
    $value = (string) reset($values);
    if (wpcf7_script_is() && preg_grep('%^watermark$%', $options)) {
        $class_att .= ' wpcf7-use-title-as-watermark';
        $title_att .= sprintf(' %s', $value);
        $value = '';
    } elseif (empty($value) && is_user_logged_in()) {
        $user = wp_get_current_user();
        $user_options = array('default:user_login' => 'user_login', 'default:user_email' => 'user_email', 'default:user_url' => 'user_url', 'default:user_first_name' => 'first_name', 'default:user_last_name' => 'last_name', 'default:user_nickname' => 'nickname', 'default:user_display_name' => 'display_name');
        foreach ($user_options as $option => $prop) {
            if (preg_grep('%^' . $option . '$%', $options)) {
                $value = $user->{$prop};
                break;
            }
        }
    }
    if (wpcf7_is_posted() && isset($_POST[$name])) {
        $value = stripslashes_deep($_POST[$name]);
    }
    if ($id_att) {
        $atts .= ' id="' . trim($id_att) . '"';
    }
    if ($class_att) {
        $atts .= ' class="' . trim($class_att) . '"';
    }
    if ($size_att) {
        $atts .= ' size="' . $size_att . '"';
    } else {
        $atts .= ' size="40"';
    }
    // default size
    if ($maxlength_att) {
        $atts .= ' maxlength="' . $maxlength_att . '"';
    }
    if ('' !== $tabindex_att) {
        $atts .= sprintf(' tabindex="%d"', $tabindex_att);
    }
    if ($title_att) {
        $atts .= sprintf(' title="%s"', trim(esc_attr($title_att)));
    }
    $html = '<input type="text" name="' . $name . '" value="' . esc_attr($value) . '"' . $atts . ' />';
    $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
    return $html;
}
Beispiel #22
0
function wpcf7_text_shortcode_handler($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    if (empty($name)) {
        return '';
    }
    $atts = '';
    $id_att = '';
    $class_att = '';
    $size_att = '';
    $maxlength_att = '';
    $tabindex_att = '';
    $title_att = '';
    $class_att .= ' wpcf7-text';
    if ('email' == $type || 'email*' == $type) {
        $class_att .= ' wpcf7-validates-as-email';
    }
    if ('text*' == $type || 'email*' == $type) {
        $class_att .= ' wpcf7-validates-as-required';
    }
    foreach ($options as $option) {
        if (preg_match('%^id:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $id_att = $matches[1];
        } elseif (preg_match('%^class:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $class_att .= ' ' . $matches[1];
        } elseif (preg_match('%^([0-9]*)[/x]([0-9]*)$%', $option, $matches)) {
            $size_att = (int) $matches[1];
            $maxlength_att = (int) $matches[2];
        } elseif (preg_match('%^tabindex:(\\d+)$%', $option, $matches)) {
            $tabindex_att = (int) $matches[1];
        }
    }
    $value = (string) reset($values);
    if (wpcf7_script_is() && preg_grep('%^watermark$%', $options)) {
        $class_att .= ' wpcf7-use-title-as-watermark';
        $title_att .= sprintf(' %s', $value);
        $value = '';
    }
    if (wpcf7_is_posted()) {
        $value = stripslashes_deep($_POST[$name]);
    }
    if ($id_att) {
        $atts .= ' id="' . trim($id_att) . '"';
    }
    if ($class_att) {
        $atts .= ' class="' . trim($class_att) . '"';
    }
    if ($size_att) {
        $atts .= ' size="' . $size_att . '"';
    } else {
        $atts .= ' size="40"';
    }
    // default size
    if ($maxlength_att) {
        $atts .= ' maxlength="' . $maxlength_att . '"';
    }
    if ('' !== $tabindex_att) {
        $atts .= sprintf(' tabindex="%d"', $tabindex_att);
    }
    if ($title_att) {
        $atts .= sprintf(' title="%s"', trim(esc_attr($title_att)));
    }
    $html = '<input type="text" name="' . $name . '" value="' . esc_attr($value) . '"' . $atts . ' />';
    $validation_error = wpcf7_get_validation_error($name);
    $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
    return $html;
}
function wpcf7_captcha_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if ('captchac' == $tag->type && !class_exists('ReallySimpleCaptcha')) {
        return '<em>' . __('To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'contact-form-7') . '</em>';
    }
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ('captchac' == $tag->type) {
        // CAPTCHA-Challenge (image)
        $class .= ' wpcf7-captcha-' . $tag->name;
        $atts = array();
        $atts['class'] = $tag->get_class_option($class);
        $atts['id'] = $tag->get_id_option();
        $op = array('img_size' => array(72, 24), 'base' => array(6, 18), 'font_size' => 14, 'font_char_width' => 15);
        $op = array_merge($op, wpcf7_captchac_options($tag->options));
        if (!($filename = wpcf7_generate_captcha($op))) {
            return '';
        }
        if (!empty($op['img_size'])) {
            if (isset($op['img_size'][0])) {
                $atts['width'] = $op['img_size'][0];
            }
            if (isset($op['img_size'][1])) {
                $atts['height'] = $op['img_size'][1];
            }
        }
        $atts['alt'] = 'captcha';
        $atts['src'] = wpcf7_captcha_url($filename);
        $atts = wpcf7_format_atts($atts);
        $prefix = substr($filename, 0, strrpos($filename, '.'));
        $html = sprintf('<input type="hidden" name="_wpcf7_captcha_challenge_%1$s" value="%2$s" /><img %3$s />', $tag->name, $prefix, $atts);
        return $html;
    } elseif ('captchar' == $tag->type) {
        // CAPTCHA-Response (input)
        if ($validation_error) {
            $class .= ' wpcf7-not-valid';
        }
        $atts = array();
        $atts['size'] = $tag->get_size_option('40');
        $atts['maxlength'] = $tag->get_maxlength_option();
        $atts['minlength'] = $tag->get_minlength_option();
        if ($atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength']) {
            unset($atts['maxlength'], $atts['minlength']);
        }
        $atts['class'] = $tag->get_class_option($class);
        $atts['id'] = $tag->get_id_option();
        $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
        $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
        $value = (string) reset($tag->values);
        if (wpcf7_is_posted()) {
            $value = '';
        }
        if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
            $atts['placeholder'] = $value;
            $value = '';
        }
        $atts['value'] = $value;
        $atts['type'] = 'text';
        $atts['name'] = $tag->name;
        $atts = wpcf7_format_atts($atts);
        $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
        return $html;
    }
}
Beispiel #24
0
function wpcf7_textarea_shortcode_handler($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $type = $tag['type'];
    $name = $tag['name'];
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    $content = $tag['content'];
    if (empty($name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($name);
    $atts = '';
    $id_att = '';
    $class_att = '';
    $cols_att = '';
    $rows_att = '';
    $tabindex_att = '';
    $title_att = '';
    $class_att = wpcf7_form_controls_class($type);
    if ($validation_error) {
        $class_att .= ' wpcf7-not-valid';
    }
    foreach ($options as $option) {
        if (preg_match('%^id:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $id_att = $matches[1];
        } elseif (preg_match('%^class:([-0-9a-zA-Z_]+)$%', $option, $matches)) {
            $class_att .= ' ' . $matches[1];
        } elseif (preg_match('%^([0-9]*)[x/]([0-9]*)$%', $option, $matches)) {
            $cols_att = (int) $matches[1];
            $rows_att = (int) $matches[2];
        } elseif (preg_match('%^tabindex:(\\d+)$%', $option, $matches)) {
            $tabindex_att = (int) $matches[1];
        }
    }
    $value = (string) reset($values);
    if (!empty($content)) {
        $value = $content;
    }
    if (wpcf7_script_is() && preg_grep('%^watermark$%', $options)) {
        $class_att .= ' wpcf7-use-title-as-watermark';
        $title_att .= sprintf(' %s', $value);
        $value = '';
    }
    if (wpcf7_is_posted() && isset($_POST[$name])) {
        $value = stripslashes_deep($_POST[$name]);
    }
    if ($id_att) {
        $atts .= ' id="' . trim($id_att) . '"';
    }
    if ($class_att) {
        $atts .= ' class="' . trim($class_att) . '"';
    }
    if ($cols_att) {
        $atts .= ' cols="' . $cols_att . '"';
    } else {
        $atts .= ' cols="40"';
    }
    // default size
    if ($rows_att) {
        $atts .= ' rows="' . $rows_att . '"';
    } else {
        $atts .= ' rows="10"';
    }
    // default size
    if ('' !== $tabindex_att) {
        $atts .= sprintf(' tabindex="%d"', $tabindex_att);
    }
    if ($title_att) {
        $atts .= sprintf(' title="%s"', trim(esc_attr($title_att)));
    }
    $html = '<textarea name="' . $name . '"' . $atts . '>' . esc_textarea($value) . '</textarea>';
    $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
    return $html;
}
function wpcf7_get_hangover($name, $default = null)
{
    if (!wpcf7_is_posted()) {
        return $default;
    }
    $submission = WPCF7_Submission::get_instance();
    if (!$submission || $submission->is('mail_sent')) {
        return $default;
    }
    return isset($_POST[$name]) ? wp_unslash($_POST[$name]) : $default;
}
Beispiel #26
0
function mango_checkbox_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $validation_error = wpcf7_get_validation_error($tag->name);
    $class = wpcf7_form_controls_class($tag->type);
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $label_first = $tag->has_option('label_first');
    $use_label_element = $tag->has_option('use_label_element');
    $exclusive = $tag->has_option('exclusive');
    $free_text = $tag->has_option('free_text');
    $multiple = false;
    if ('checkbox' == $tag->basetype) {
        $multiple = !$exclusive;
    } else {
        // radio
        $exclusive = false;
    }
    if ($exclusive) {
        $class .= ' wpcf7-exclusive-checkbox';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $tabindex = $tag->get_option('tabindex', 'int', true);
    if (false !== $tabindex) {
        $tabindex = absint($tabindex);
    }
    $html = '';
    $count = 0;
    $values = (array) $tag->values;
    $labels = (array) $tag->labels;
    if ($data = (array) $tag->get_data_option()) {
        if ($free_text) {
            $values = array_merge(array_slice($values, 0, -1), array_values($data), array_slice($values, -1));
            $labels = array_merge(array_slice($labels, 0, -1), array_values($data), array_slice($labels, -1));
        } else {
            $values = array_merge($values, array_values($data));
            $labels = array_merge($labels, array_values($data));
        }
    }
    $defaults = array();
    $default_choice = $tag->get_default_option(null, 'multiple=1');
    foreach ($default_choice as $value) {
        $key = array_search($value, $values, true);
        if (false !== $key) {
            $defaults[] = (int) $key + 1;
        }
    }
    $defaults = array_unique($defaults);
    $hangover = wpcf7_get_hangover($tag->name, $multiple ? array() : '');
    $i = 0;
    foreach ($values as $key => $value) {
        if ($value == 'mango_same_line' || $value == 'mango_custom') {
            continue;
        }
        $ex = explode("|", $tag->raw_values[$i]);
        $i++;
        if (count($ex) == 1) {
            $disable = '';
        } else {
            $disable = $ex[1];
        }
        $class = 'wpcf7-list-item';
        $checked = false;
        if ($hangover) {
            if ($multiple) {
                $checked = in_array(esc_sql($value), (array) $hangover);
            } else {
                $checked = $hangover == esc_sql($value);
            }
        } else {
            $checked = in_array($key + 1, (array) $defaults);
        }
        if (isset($labels[$key])) {
            $label = $labels[$key];
        } else {
            $label = $value;
        }
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => $value, 'checked' => $checked ? 'checked' : '', 'tabindex' => $tabindex ? $tabindex : '');
        $item_atts = wpcf7_format_atts($item_atts);
        if ($label_first) {
            // put label first, input last
            if (in_array('mango_custom', $values)) {
                $item = sprintf('<span>%1$s</span><span class="custom-' . esc_attr($tag->basetype) . '-container"><input %2$s  /><span class="custom-' . esc_attr($tag->basetype) . '-icon"></span></span>', esc_html($label), $item_atts);
            } else {
                $item = sprintf('%1$s&nbsp;<input %2$s %3$s />', esc_html($label), $item_atts, $disable);
            }
        } else {
            if (in_array('mango_custom', $values)) {
                $item = sprintf('<span class="custom-' . esc_attr($tag->basetype) . '-container"><input %2$s  /><span class="custom-' . esc_attr($tag->basetype) . '-icon"></span></span><span>%1$s</span>', esc_html($label), $item_atts);
            } else {
                $item = sprintf('<input %2$s %3$s />&nbsp;%1$s', esc_html($label), $item_atts, $disable);
            }
        }
        if ($use_label_element) {
            if (in_array('mango_same_line', $values)) {
                if (in_array('mango_custom', $values)) {
                    if (!empty($disable)) {
                        $item = '<label class="' . esc_attr($tag->basetype) . '-inline custom-' . esc_attr($tag->basetype) . '-wrapper disabled">' . $item . '</label>';
                    } else {
                        $item = '<label class="' . esc_attr($tag->basetype) . '-inline custom-' . esc_attr($tag->basetype) . '-wrapper">' . $item . '</label>';
                    }
                } else {
                    if (!empty($disable)) {
                        $item = '<label class="' . esc_attr($tag->basetype) . '-inline disabled">' . $item . '</label>';
                    } else {
                        $item = '<label class="' . esc_attr($tag->basetype) . '-inline">' . $item . '</label>';
                    }
                }
            } else {
                if (in_array('mango_custom', $values)) {
                    if (!empty($disable)) {
                        $item = '<div class="' . esc_attr($tag->basetype) . ' disabled"><label class="custom-' . esc_attr($tag->basetype) . '-wrapper">' . $item . '</label></div>';
                    } else {
                        $item = '<div class="' . esc_attr($tag->basetype) . '"><label class="custom-' . esc_attr($tag->basetype) . '-wrapper">' . $item . '</label></div>';
                    }
                } else {
                    if (!empty($disable)) {
                        $item = '<div class="' . esc_attr($tag->basetype) . ' disabled"><label>' . $item . '</label></div>';
                    } else {
                        $item = '<div class="' . esc_attr($tag->basetype) . '"><label>' . $item . '</label></div>';
                    }
                }
            }
        }
        if (false !== $tabindex) {
            $tabindex += 1;
        }
        $count += 1;
        if (1 == $count) {
            $class .= ' first';
        }
        if (count($values) == $count) {
            $class .= ' last';
            if ($free_text) {
                $free_text_name = sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name);
                $free_text_atts = array('name' => $free_text_name, 'class' => 'wpcf7-free-text', 'tabindex' => $tabindex ? $tabindex : '');
                if (wpcf7_is_posted() && isset($_POST[$free_text_name])) {
                    $free_text_atts['value'] = wp_unslash($_POST[$free_text_name]);
                }
                $free_text_atts = wpcf7_format_atts($free_text_atts);
                $item .= sprintf(' <input type="text" %s />', $free_text_atts);
                $class .= ' has-free-text';
            }
        }
        $disable = '';
        $html .= $item;
    }
    $atts = wpcf7_format_atts($atts);
    if (empty($values)) {
        $item_atts = array('type' => $tag->basetype, 'name' => $tag->name . ($multiple ? '[]' : ''), 'value' => 'yes');
        $item_atts = wpcf7_format_atts($item_atts);
        $html = sprintf('<span class="input-group-addon no-minwidth custom-' . esc_attr($tag->basetype) . '-wrapper">
			<span class="custom-' . esc_attr($tag->basetype) . '-container">
			<input %1$s>
			<span class="custom-' . esc_attr($tag->basetype) . '-icon"></span>
			</span>
			</span>', $item_atts);
        $html = sprintf('%1$s%2$s', $html, $validation_error);
    } else {
        $html = sprintf('<div %1$s>%2$s&nbsp;%3$s</div>', $atts, $html, $validation_error);
    }
    return $html;
}