Esempio n. 1
0
function wpef7_acceptance_shortcode_handler($tag)
{
    global $wpef7_contact_form;
    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 = '';
    $tabindex_att = '';
    $class_att .= ' wpef7-acceptance';
    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 ('invert' == $option) {
            $class_att .= ' wpef7-invert';
        } 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);
    }
    $default_on = (bool) preg_grep('/^default:on$/i', $options);
    if (wpef7_script_is()) {
        $onclick = ' onclick="wpef7ToggleSubmit(this.form);"';
    } else {
        $onclick = '';
    }
    $checked = $default_on ? ' checked="checked"' : '';
    $html = '<input type="checkbox" name="' . $name . '" value="1"' . $atts . $onclick . $checked . ' />';
    return $html;
}
Esempio n. 2
0
function wpef7_submit_shortcode_handler($tag)
{
    if (!is_array($tag)) {
        return '';
    }
    $options = (array) $tag['options'];
    $values = (array) $tag['values'];
    $atts = '';
    $id_att = '';
    $class_att = '';
    $tabindex_att = '';
    $class_att .= ' wpef7-submit';
    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('%^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);
    }
    $value = isset($values[0]) ? $values[0] : '';
    if (empty($value)) {
        $value = __('Send', 'wpef7');
    }
    $html = '<input type="submit" value="' . esc_attr($value) . '"' . $atts . ' />';
    if (wpef7_script_is()) {
        $src = apply_filters('wpef7_ajax_loader', wpef7_plugin_url('images/ajax-loader.gif'));
        $html .= '<img class="ajax-loader" style="visibility: hidden;" alt="' . esc_attr(__('Sending ...', 'wpef7')) . '" src="' . esc_url_raw($src) . '" />';
    }
    return $html;
}
Esempio n. 3
0
function wpef7_checkbox_shortcode_handler($tag)
{
    global $wpef7_contact_form;
    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 .= ' wpef7-validates-as-required';
    }
    if ('checkbox' == $type || 'checkbox*' == $type) {
        $class_att .= ' wpef7-checkbox';
    }
    if ('radio' == $type) {
        $class_att .= ' wpef7-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];
        }
    }
    if ($id_att) {
        $atts .= ' id="' . trim($id_att) . '"';
    }
    if ($class_att) {
        $atts .= ' class="' . trim($class_att) . '"';
    }
    $multiple = preg_match('/^checkbox[*]?$/', $type) && !preg_grep('%^exclusive$%', $options);
    $html = '';
    if (preg_match('/^checkbox[*]?$/', $type) && !$multiple && wpef7_script_is()) {
        $onclick = ' onclick="wpef7ExclusiveCheckbox(this);"';
    } else {
        $onclick = '';
    }
    $input_type = rtrim($type, '*');
    $posted = is_a($wpef7_contact_form, 'WPEF7_ContactForm') && $wpef7_contact_form->is_posted();
    foreach ($values as $key => $value) {
        $checked = false;
        if (in_array($key + 1, (array) $defaults)) {
            $checked = true;
        }
        if ($posted) {
            if ($multiple && in_array(esc_sql($value), (array) $_POST[$name])) {
                $checked = true;
            }
            if (!$multiple && $_POST[$name] == esc_sql($value)) {
                $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="wpef7-list-item-label">' . esc_html($label) . '</span>&nbsp;';
            $item .= '<input type="' . $input_type . '" name="' . $name . ($multiple ? '[]' : '') . '" value="' . esc_attr($value) . '"' . $checked . $tabindex . $onclick . ' />';
        } else {
            $item = '<input type="' . $input_type . '" name="' . $name . ($multiple ? '[]' : '') . '" value="' . esc_attr($value) . '"' . $checked . $tabindex . $onclick . ' />';
            $item .= '&nbsp;<span class="wpef7-list-item-label">' . esc_html($label) . '</span>';
        }
        if ($use_label_element) {
            $item = '<label>' . $item . '</label>';
        }
        $item = '<span class="wpef7-list-item">' . $item . '</span>';
        $html .= $item;
    }
    $html = '<span' . $atts . '>' . $html . '</span>';
    $validation_error = '';
    if (is_a($wpef7_contact_form, 'WPEF7_ContactForm')) {
        $validation_error = $wpef7_contact_form->validation_error($name);
    }
    $html = '<span class="wpef7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
    return $html;
}
Esempio n. 4
0
function wpef7_head()
{
    // Cached?
    if (wpef7_script_is() && defined('WP_CACHE') && WP_CACHE) {
        ?>
<script type="text/javascript">
//<![CDATA[
var _wpef7 = { cached: 1 };
//]]>
</script>
<?php 
    }
}