예제 #1
1
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;
}
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 wpcf7dtx_dynamictext_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, 'wpcf7dtx-dynamictext');
    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);
    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 = '';
    }
    $value = $tag->get_default_option($value);
    $value = wpcf7_get_hangover($tag->name, $value);
    $scval = do_shortcode('[' . $value . ']');
    if ($scval != '[' . $value . ']') {
        $value = esc_attr($scval);
    }
    $atts['value'] = $value;
    //echo '<pre>'; print_r( $tag ); echo '</pre>';
    switch ($tag->basetype) {
        case 'dynamictext':
            $atts['type'] = 'text';
            break;
        case 'dynamichidden':
            $atts['type'] = 'hidden';
            break;
        default:
            $atts['type'] = 'text';
            break;
    }
    $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;
}
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 '';
}
예제 #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;
}
예제 #6
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;
 }
예제 #7
0
function quai10_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['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);
    if ($tag->has_option('readonly')) {
        $atts['readonly'] = 'readonly';
    }
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
        $atts['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 = '';
    }
    $value = $tag->get_default_option($value);
    $value = wpcf7_get_hangover($tag->name, $value);
    $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('<input class="%1$s" %2$s />%3$s', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
예제 #8
0
function wpcf7_count_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (empty($tag->name)) {
        return '';
    }
    $target = wpcf7_scan_shortcode(array('name' => $tag->name));
    $maxlength = $minlength = null;
    if ($target) {
        $target = new WPCF7_Shortcode($target[0]);
        $maxlength = $target->get_maxlength_option();
        $minlength = $target->get_minlength_option();
        if ($maxlength && $minlength && $maxlength < $minlength) {
            $maxlength = $minlength = null;
        }
    }
    if ($tag->has_option('down')) {
        $value = (int) $maxlength;
        $class = 'wpcf7-character-count down';
    } else {
        $value = '0';
        $class = 'wpcf7-character-count up';
    }
    $atts = array();
    $atts['id'] = $tag->get_id_option();
    $atts['class'] = $tag->get_class_option($class);
    $atts['data-target-name'] = $tag->name;
    $atts['data-starting-value'] = $value;
    $atts['data-current-value'] = $value;
    $atts['data-maximum-value'] = $maxlength;
    $atts['data-minimum-value'] = $minlength;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span %1$s>%2$s</span>', $atts, $value);
    return $html;
}
예제 #9
0
function wpcf7_number_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-number';
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['class'] = $tag->get_class_option($class);
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    $atts['min'] = $tag->get_option('min', 'signed_int', true);
    $atts['max'] = $tag->get_option('max', 'signed_int', 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 = 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;
}
예제 #10
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('40');
    $atts['rows'] = $tag->get_rows_option('10');
    $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['autocomplete'] = $tag->get_option('autocomplete', '[-0-9a-zA-Z]+', 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 = empty($tag->content) ? (string) reset($tag->values) : $tag->content;
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $atts['placeholder'] = $value;
        $value = '';
    }
    $value = $tag->get_default_option($value);
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %1$s"><textarea %2$s>%3$s</textarea>%4$s</span>', sanitize_html_class($tag->name), $atts, esc_textarea($value), $validation_error);
    return $html;
}
예제 #11
0
function cf7bs_acceptance_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->has_option('invert')) {
        $class .= ' wpcf7-invert';
    }
    $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' => 'checkbox', 'value' => $tag->has_option('default:on') ? '1' : '0', 'options' => array('1' => $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'), 'group_layout' => cf7bs_get_form_property('group_layout'), '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_robottrap_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    // default field name
    if (empty($tag->name)) {
        $tag->name = 'email-verify';
    }
    // per field errors
    $validation_error = wpcf7_get_validation_error($tag->name);
    // add wpcf7 specific classes
    $class = wpcf7_form_controls_class('text');
    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);
    /**
     * Robots may look for the word "hidden".
     *
     * @ignore Commented out.
     */
    //$atts['aria-hidden'] = 'true';
    $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();
    }
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts['value'] = $value;
    $atts['type'] = 'text';
    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<span class="wpcf7-form-control-wrap %s"><input %s />%s</span>', sanitize_html_class($tag->name), $atts, $validation_error);
    return $html;
}
예제 #13
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;
}
예제 #14
0
function wpcf7_birthday_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-birthday');
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $atts = array();
    $atts['size'] = $tag->get_size_option('5');
    $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();
    }
    $value = wpcf7_get_hangover($tag->name, $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;
}
예제 #15
0
function wpcf7_acceptance_validation_filter($result, $tag)
{
    if (!wpcf7_acceptance_as_validation()) {
        return $result;
    }
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = !empty($_POST[$name]) ? 1 : 0;
    $invert = $tag->has_option('invert');
    if ($invert && $value || !$invert && !$value) {
        $result->invalidate($tag, wpcf7_get_message('accept_terms'));
    }
    return $result;
}
예제 #16
0
function wpcf7_acceptance_validation_filter($result, $tag)
{
    if (!wpcf7_acceptance_as_validation()) {
        return $result;
    }
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = !empty($_POST[$name]) ? 1 : 0;
    $invert = $tag->has_option('invert');
    if ($invert && $value || !$invert && !$value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('accept_terms');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
function wpcf7_orders_shortcode_handler($tag)
{
    $tag = new WPCF7_Shortcode($tag);
    if (!is_user_logged_in()) {
        return 'Please login first to show orders';
    }
    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_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $multiple = $tag->has_option('multiple');
    $include_blank = $tag->has_option('include_blank');
    $first_as_label = $tag->has_option('first_as_label');
    // Change order query settings here
    $order_posts = get_posts(array('post_type' => 'shop_order', 'meta_key' => '_customer_user', 'meta_value' => get_current_user_id(), 'post_status' => 'publish', 'numberposts' => -1));
    // Display order options
    $values = array();
    foreach ($order_posts as $order) {
        // Set `values` with order ID & order title
        $values[] = '#' . $order->ID . ' | ' . $order->post_title;
    }
    $values = $values;
    $labels = array_values($values);
    $shifted = false;
    if ($include_blank || empty($values)) {
        array_unshift($labels, '---');
        array_unshift($values, '');
        $shifted = true;
    } elseif ($first_as_label) {
        $values[0] = '';
    }
    $html = '';
    $hangover = wpcf7_get_hangover($tag->name);
    foreach ($values as $key => $value) {
        $selected = false;
        if ($hangover) {
            if ($multiple) {
                $selected = in_array(esc_sql($value), (array) $hangover);
            } else {
                $selected = $hangover == esc_sql($value);
            }
        } else {
            if (!$shifted && in_array((int) $key + 1, (array) $defaults)) {
                $selected = true;
            } elseif ($shifted && in_array((int) $key, (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>', sanitize_html_class($tag->name), $atts, $html, $validation_error);
    return $html;
}
 public static function nocaptcha_shortcode_handler($tag)
 {
     $html = '';
     global $wdm_recaptcha_settings_values;
     $site_key = $wdm_recaptcha_settings_values->get_option('general_site_key');
     $secret_key = $wdm_recaptcha_settings_values->get_option('general_secret_key');
     if (trim($site_key) != '' && trim($secret_key) != '') {
         $tag = new WPCF7_Shortcode($tag);
         if (empty($tag->name)) {
             return '';
         }
         $validation_error = wpcf7_get_validation_error($tag->name);
         if ($validation_error) {
             $class .= ' wpcf7-not-valid';
         }
         $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
         wp_enqueue_script('wdm_render_recaptcha', plugins_url('/assets/js/render_recaptcha.js', dirname(dirname(__FILE__))), array(), false, true);
         if ($tag->has_option('theme:dark')) {
             wp_localize_script('wdm_render_recaptcha', 'wdm_recaptcha', array('sitekey' => $site_key, 'theme' => 'dark'));
         } else {
             wp_localize_script('wdm_render_recaptcha', 'wdm_recaptcha', array('sitekey' => $site_key, 'theme' => 'light'));
         }
         if (is_ssl()) {
             $protocol_to_be_used = 'https://';
         } else {
             $protocol_to_be_used = 'http://';
         }
         wp_register_script('google-nocaptcha-recaptcha-api', "{$protocol_to_be_used}www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit", array('wdm_render_recaptcha'), '1.0.0', false);
         wp_enqueue_script('google-nocaptcha-recaptcha-api');
         $class = wpcf7_form_controls_class($tag->type);
         $atts = array();
         $atts['class'] = "wdm-nocapt-recapt " . $tag->get_class_option($class);
         $atts['id'] = "wdm-nocapt-recapt-id";
         $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
         $atts['type'] = 'recaptcha';
         $atts = wpcf7_format_atts($atts);
         $html = sprintf('<div %1$s></div>', $atts);
         if (isset($validation_error)) {
             $html .= sprintf('<span class="wpcf7-form-control-wrap %1$s">%2$s</span>', sanitize_html_class($tag->name), $validation_error);
             wp_enqueue_script('google-nocaptcha-recaptcha-api');
         }
     }
     return $html;
 }
예제 #19
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_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;
    }
}
 /**
  * contact form submision
  * @param object $WPCF7_ContactForm: current contact form object
  */
 public function _hw_wpcf7_do_something($WPCF7_ContactForm)
 {
     /* Use WPCF7_Submission object's get_posted_data() method to get it. */
     $properties = $WPCF7_ContactForm->get_properties();
     //get google form ID of this form
     $gformID = $properties['hw_gformID'];
     // get the contact form object
     $wpcf7 = WPCF7_ContactForm::get_current();
     if (isset($properties['enable_email_by_gapp']) && $properties['enable_email_by_gapp']) {
         //  do not send the email
         $wpcf7->skip_mail = true;
         //turn off default send mail by wpcf7, use google drive instead
     }
     $atts = $WPCF7_ContactForm->form_scan_shortcode();
     $fields_title = array();
     //fields title
     $data = array();
     //fields value
     //submission data
     $submission = WPCF7_Submission::get_instance();
     if ($submission) {
         //get storage service
         $storage_hook = $WPCF7_ContactForm->prop('hwcf_data_hook');
         //get posted form data
         $posted_data = $submission->get_posted_data();
         //parse email template into user data
         $mail_temp = $WPCF7_ContactForm->prop('mail');
         $result = wpcf7_mail_replace_tags($mail_temp);
         $admin_email = !empty($mail_temp['recipient']) ? $mail_temp['recipient'] : get_option('admin_email');
         //set special field value
         $special_fields_value['sendEmail'] = $result['body'];
         $special_fields_value['admin_email'] = $admin_email;
         #admin email
         $special_fields_value['website'] = hw_wpcf7_current_page_url();
         #site url
         foreach ($atts as $field) {
             //loop each field
             $tag = new WPCF7_Shortcode($field);
             $name = $tag->name;
             //get field name
             if ($tag->has_option('gfield') && $tag->type != 'hw_wpcf7_special_fields') {
                 if ($tag->get_option('gfield', '', true)) {
                     $name = $tag->get_option('gfield', '', true);
                     //modify field value
                     $data[$name] = apply_filters('hwwpcf7_field_value', $posted_data[$tag->name], array('name' => $name, 'tag' => $tag, 'data' => &$data, 'wpcf7' => $wpcf7));
                     /*if(isset($_POST['product_id']) && $tag->name=='order_detail'){
                           $sp=get_post($_POST['product_id']);
                           $data[$name] = '[ID='.$sp->ID.']'.PHP_EOL.$sp->post_title.PHP_EOL.get_permalink($sp->ID);
                       }*/
                     //else $data[$name] = $posted_data[$tag->name];
                 }
             }
             /**
              * get field title
              */
             if ($tag->has_option('placeholder') && $tag->type != 'hw_wpcf7_special_fields') {
                 $fields_title[$name] = (string) reset($tag->values);
                 #$tag->get_option('placeholder','',true);
             }
             /**
              * special tag to get special fields
              */
             if ($tag->type == 'hw_wpcf7_special_fields') {
                 foreach (HW_WPCF7::$special_gfields as $fname => $desc) {
                     if ($tag->has_option($fname) && isset($special_fields_value[$fname])) {
                         $data[$tag->get_option($fname, '', true)] = $special_fields_value[$fname];
                         //add special field value to data
                     }
                 }
             }
         }
         //storage
         if ($storage_hook == 'google_form') {
             //get google form id
             $gform_id = $WPCF7_ContactForm->prop('hw_gformID');
             //from google spreadsheet as responses that link to google form. Create event onSubmitForm. you can send mail using google script.
             hw_wpcf7_post_gform($gform_id, $data);
         } elseif ($storage_hook == 'url') {
             $hook_url = $WPCF7_ContactForm->prop('hook_url');
             //web hook url
             $data['labels'] = serialize($fields_title);
             //nest labels for all fields in one data together
             HW_CURL::curl_post($hook_url, $data);
         }
         /*hw_mail(array(
            'subject'=>'Khách hàng liên hệ từ '.home_url(),
            'body'=>$body
           ));*/
     }
 }
예제 #22
0
파일: select.php 프로젝트: crazyyy/octagram
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_id_option();
    $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
    if ($tag->is_required()) {
        $atts['aria-required'] = 'true';
    }
    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    $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');
    $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);
    if ($empty_select || $include_blank) {
        array_unshift($labels, '---');
        array_unshift($values, '');
    } elseif ($first_as_label) {
        $values[0] = '';
    }
    $html = '';
    $hangover = wpcf7_get_hangover($tag->name);
    foreach ($values as $key => $value) {
        $selected = false;
        if ($hangover) {
            if ($multiple) {
                $selected = in_array(esc_sql($value), (array) $hangover);
            } else {
                $selected = $hangover == esc_sql($value);
            }
        } 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>', sanitize_html_class($tag->name), $atts, $html, $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;
}
예제 #24
0
function wpcf7_checkbox_posted_data($posted_data)
{
    $tags = wpcf7_scan_shortcode(array('type' => array('checkbox', 'checkbox*', 'radio')));
    if (empty($tags)) {
        return $posted_data;
    }
    foreach ($tags as $tag) {
        $tag = new WPCF7_Shortcode($tag);
        if (!isset($posted_data[$tag->name])) {
            continue;
        }
        $posted_items = (array) $posted_data[$tag->name];
        if ($tag->has_option('free_text')) {
            if (WPCF7_USE_PIPE) {
                $values = $tag->pipes->collect_afters();
            } else {
                $values = $tag->values;
            }
            $last = array_pop($values);
            $last = html_entity_decode($last, ENT_QUOTES, 'UTF-8');
            if (in_array($last, $posted_items)) {
                $posted_items = array_diff($posted_items, array($last));
                $free_text_name = sprintf('_wpcf7_%1$s_free_text_%2$s', $tag->basetype, $tag->name);
                $free_text = $posted_data[$free_text_name];
                if (!empty($free_text)) {
                    $posted_items[] = trim($last . ' ' . $free_text);
                } else {
                    $posted_items[] = $last;
                }
            }
        }
        $posted_data[$tag->name] = $posted_items;
    }
    return $posted_data;
}
예제 #25
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 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;
}
예제 #27
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;
}
 function shortcode_handler($tag)
 {
     $tag = new WPCF7_Shortcode($tag);
     if (empty($tag->name)) {
         return '';
     }
     // The lists are in {name of list}::#{id} format.
     // This parses them into an array
     $print_lists = array();
     foreach ($tag->values as $key => $value) {
         list($name, $id) = explode('::#', $value);
         $print_lists[(int) $id] = trim(rtrim($name));
     }
     /**
      * Get the list type
      *
      * @uses WPCF7_Shortcode::get_option()
      */
     $options['type'] = $tag->get_option('type', 'id', true);
     $options['label'] = urldecode($tag->get_option('label', '', true));
     $options['first'] = urldecode($tag->get_option('first', '', true));
     $options['lists'] = $print_lists;
     $options['name_attr'] = $tag->name;
     if ($tag->has_option('default:on')) {
         $options['checked'] = 'checked';
     }
     $output = $this->outputHTML($options);
     $class = wpcf7_form_controls_class($tag->type);
     $validation_error = wpcf7_get_validation_error($tag->name);
     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 = wpcf7_format_atts($atts);
     $output = sprintf('<span class="wpcf7-form-control-wrap %1$s"><span %2$s>%3$s</span>%4$s</span>', $tag->name, $atts, $output, $validation_error);
     return $output;
 }
예제 #29
0
     $class .= ' wpcf7-validates-as-' . $tag->basetype;
 }
 if ($validation_error) {
     $class .= ' wpcf7-not-valid';
 }
 $atts = [];
 $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);
 if ($tag->has_option('readonly')) {
     $atts['readonly'] = 'readonly';
 }
 if ($tag->is_required()) {
     $atts['aria-required'] = 'true';
     $atts['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 = '';
 }
 $value = $tag->get_default_option($value);
 $value = wpcf7_get_hangover($tag->name, $value);
 $atts['value'] = $value;
예제 #30
0
파일: hidden.php 프로젝트: jrald1291/atu
function wpcf7_hidden_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-hidden');
    if ($validation_error) {
        $class .= ' wpcf7-not-valid';
    }
    $class .= ' wpcf7-hidden';
    if ('hidden*' === $tag->type) {
        $class .= ' wpcf7-validates-as-required';
    }
    $value = (string) reset($tag->values);
    $placeholder = '';
    if ($tag->has_option('placeholder') || $tag->has_option('watermark')) {
        $placeholder = $value;
        $value = '';
    }
    $default_value = $tag->get_default_option($value);
    $value = contact_form_7_hidden_fields_fill_post_data($value, $tag);
    // Post data hasn't filled yet. No arrays.
    if ($default_value === $value) {
        $value = contact_form_7_hidden_fields_fill_user_data($value);
    }
    // Arrays get imploded.
    $value = is_array($value) ? implode(apply_filters('wpcf7_hidden_field_implode_glue', ', '), $value) : $value;
    // Make sure we're using a string. Objects get JSON-encoded.
    if (!is_string($value)) {
        $value = json_encode($value);
    }
    $value = apply_filters('wpcf7_hidden_field_value', apply_filters('wpcf7_hidden_field_value_' . $tag->get_id_option(), $value));
    $value = wpcf7_get_hangover($tag->name, $value);
    $atts = array('type' => 'hidden', 'class' => $tag->get_class_option($class), 'id' => $tag->get_id_option(), 'name' => $tag->name, 'tabindex' => $tag->get_option('tabindex', 'int', true), 'placeholder' => $placeholder, 'value' => $value);
    $atts = wpcf7_format_atts($atts);
    $html = sprintf('<input %1$s />%2$s', $atts, $validation_error);
    return $html;
}