コード例 #1
0
ファイル: utilities.php プロジェクト: johnmanlove/NoOn1
function seamless_donations_get_submitted_admin_section($_the_array)
{
    $slug = $_POST['page_slug'];
    for ($i = 0; $i < count($_the_array); ++$i) {
        $key = seamless_donations_name_of($_the_array, $i);
        if (strpos($key, $slug) === 0) {
            // key begins with slug
            if (isset($_the_array[$key]['submit'])) {
                if ($_the_array[$key]['submit'] != NULL) {
                    return $key;
                }
            }
        }
    }
    return false;
}
コード例 #2
0
function seamless_donations_forms_engine_element_list($form_array, $form_html = '')
{
    // process form elements without outer wrapping
    $form_size = count($form_array);
    // so the count only happens once
    $supported_form_types = array('text', 'checkbox', 'radio', 'hidden', 'submit', 'image', 'select', 'static');
    $input_tag_types = array('text', 'checkbox', 'radio', 'hidden', 'submit', 'image');
    if (get_option('dgx_donate_labels_for_input') == true) {
        $generate_input_labels = true;
    } else {
        $generate_input_labels = false;
    }
    for ($element_index = 0; $element_index < $form_size; ++$element_index) {
        $element_html = '';
        $element_type = '';
        // preload the element attributes
        $element_id = '';
        $element_placeholder = '';
        $element_value = '';
        $element_class = '';
        $element_style = '';
        $element_size = '1';
        $element_wrapper = 'div';
        $element_hide = '';
        $element_reveal = '';
        $element_conceal = '';
        $element_check = '';
        $element_uncheck = '';
        $element_before = '';
        $element_after = '';
        $element_prompt = '';
        $element_source = '';
        $element_select = false;
        $element_validation = '';
        $element_options = array();
        $element_name = seamless_donations_name_of($form_array, $element_index);
        // prep hide elements
        if (isset($form_array[$element_name]['cloak'])) {
            $element_hide = trim($form_array[$element_name]['cloak']);
            if (isset($form_array[$element_name]['class'])) {
                $form_array[$element_name]['class'] = trim($form_array[$element_name]['class']) . ' ' . $element_hide;
            } else {
                $form_array[$element_name]['class'] = $element_hide;
            }
            if (isset($form_array[$element_name]['style'])) {
                $element_style = trim($form_array[$element_name]['style']);
                if (substr($element_style, -1) != ';') {
                    $element_style .= ';';
                    // add a semi-colon to the end of the style attr
                }
                $element_style .= ' display:none';
                $form_array[$element_name]['style'] = $element_style;
            } else {
                $form_array[$element_name]['style'] = 'display:none';
            }
        }
        for ($attribute_index = 0; $attribute_index < count($form_array[$element_name]); ++$attribute_index) {
            $attribute_name = seamless_donations_name_of($form_array[$element_name], $attribute_index);
            // don't really need this switch code, but much easer to maintain and manage
            // when each element is clearly seen and testable
            switch ($attribute_name) {
                case 'type':
                    $element_type = trim($form_array[$element_name]['type']);
                    break;
                case 'id':
                    $element_id = trim($form_array[$element_name]['id']);
                    break;
                case 'value':
                    $element_value = trim($form_array[$element_name]['value']);
                    break;
                case 'class':
                    $element_class = trim($form_array[$element_name]['class']);
                    break;
                case 'style':
                    $element_style = trim($form_array[$element_name]['style']);
                    break;
                case 'size':
                    $element_size = trim($form_array[$element_name]['size']);
                    break;
                case 'before':
                    $element_before = trim($form_array[$element_name]['before']);
                    break;
                case 'after':
                    $element_after = trim($form_array[$element_name]['after']);
                    break;
                case 'prompt':
                    $element_prompt = trim($form_array[$element_name]['prompt']);
                    break;
                case 'select':
                    $element_select = $form_array[$element_name]['select'];
                    break;
                case 'check':
                    $element_check = $form_array[$element_name]['check'];
                    break;
                case 'uncheck':
                    $element_uncheck = $form_array[$element_name]['uncheck'];
                    break;
                case 'source':
                    $element_source = trim($form_array[$element_name]['source']);
                    break;
                case 'placeholder':
                    $element_placeholder = trim($form_array[$element_name]['placeholder']);
                    break;
                case 'wrapper':
                    $element_wrapper = strtolower($form_array[$element_name]['wrapper']);
                    if ($element_wrapper != 'div' and $element_wrapper != 'span') {
                        $element_wrapper = 'div';
                    }
                    break;
                case 'reveal':
                    if (!is_array($form_array[$element_name]['reveal'])) {
                        $element_reveal = trim($form_array[$element_name]['reveal']);
                    } else {
                        $element_reveal = $form_array[$element_name]['reveal'];
                    }
                    break;
                case 'conceal':
                    $element_conceal = trim($form_array[$element_name]['conceal']);
                    if ($element_conceal != '') {
                        $conceal_array = explode(' ', $element_conceal);
                        for ($conceal_index = 0; $conceal_index < count($conceal_array); ++$conceal_index) {
                            $conceal_array[$conceal_index] = '.' . $conceal_array[$conceal_index];
                        }
                        $element_conceal = implode(', ', $conceal_array);
                    }
                    break;
                case 'validation':
                    $element_validation = trim($form_array[$element_name]['validation']);
                    break;
                case 'options':
                    if (is_array($form_array[$element_name]['options'])) {
                        $element_options = $form_array[$element_name]['options'];
                    }
                    break;
            }
        }
        // write element HTML code
        if ($element_type != '' and in_array($element_type, $supported_form_types)) {
            // process the element div html code
            $div_span_html = "<{$element_wrapper}";
            // div or span
            $div_span_html .= " id='" . $element_name . "' ";
            if ($element_class != '') {
                $div_span_html .= "class='" . $element_class . "' ";
                // CLASS
            }
            if ($element_style != '') {
                $div_span_html .= "style='" . $element_style . "'";
                // STYLE
            }
            $div_span_html .= ">";
            $element_html .= $div_span_html;
            // now include the error div or span
            $div_span_html = "<{$element_wrapper}";
            // div or span
            $div_span_html .= " id='" . $element_name . "-error-message' ";
            $div_span_html .= " style='display:none'";
            $div_span_html .= " class='seamless-donations-error-message-field'";
            $div_span_html .= "></{$element_wrapper}>";
            $element_html .= $div_span_html;
            if (in_array($element_type, $input_tag_types)) {
                // process input tag
                if ($generate_input_labels == true and $element_type == 'text') {
                    // set up the label tag
                    $element_html .= "<label for='" . sanitize_text_field($element_name) . "'>";
                    $element_html .= esc_html__($element_before, 'seamless-donations');
                    $element_html .= " </label>";
                } else {
                    $element_html .= $element_before;
                    // BEFORE
                }
                $element_html .= "<input type='" . $element_type . "' ";
                // INPUT
                // process the name and radio group
                if (isset($form_array[$element_name]['group'])) {
                    $element_group = $form_array[$element_name]['group'];
                    // GROUP
                    $element_html .= "name='" . sanitize_text_field($element_group) . "' ";
                } else {
                    $element_html .= "name='" . sanitize_text_field($element_name) . "' ";
                    // NAME
                }
                if ($element_select !== false) {
                    // SELECT
                    $element_html .= 'checked ';
                }
                if ($element_type != 'checkbox') {
                    $element_html .= "value='" . $element_value . "' ";
                    // VALUE
                }
                if ($element_type == 'text' and $element_size != '') {
                    // TEXT
                    $element_html .= "size='" . $element_size . "' ";
                    // SIZE
                }
                if ($element_type == 'image' and $element_source != '') {
                    // IMAGE
                    $element_html .= "src='" . $element_source . "' ";
                }
                if ($element_id != '') {
                    $element_html .= "id='" . $element_id . "' ";
                    // ID
                }
                if ($element_placeholder != '') {
                    $element_html .= "placeholder='" . $element_placeholder . "' ";
                    // placeholder
                }
                if ($element_reveal != '') {
                    $element_html .= "data-reveal='.";
                    // jQuery will look for classes with this name
                    $element_html .= $element_reveal;
                    $element_html .= "' ";
                }
                if ($element_conceal != '') {
                    $element_html .= "data-conceal='";
                    // jQuery will look for classes with this name
                    $element_html .= $element_conceal;
                    $element_html .= "' ";
                }
                if ($element_check != '') {
                    $element_html .= "data-check='";
                    // jQuery will look for element names with this name
                    $element_html .= $element_check;
                    $element_html .= "' ";
                }
                if ($element_uncheck != '') {
                    $element_html .= "data-uncheck='";
                    // jQuery will look for element names with this name
                    $element_html .= $element_uncheck;
                    $element_html .= "' ";
                }
                if ($element_validation != '') {
                    $element_html .= "data-validate='";
                    // this is an HTML5 attribute that makes jQuery easier
                    $element_html .= strtolower(trim(str_replace(' ', '', $element_validation)));
                    $element_html .= "' ";
                }
                $element_html .= '/>';
                if ($element_prompt != '') {
                    // PROMPT
                    $element_html .= $element_prompt;
                }
                $element_html .= $element_after;
                // AFTER
            }
            if ($element_type == 'static') {
                // STATIC
                $element_html .= $element_before;
                $element_html .= $element_value;
                $element_html .= $element_after;
            }
            if ($element_type == 'select') {
                // SELECT
                // process select tag
                if (count($element_options) > 0) {
                    // only build the select tag if there are options provided
                    if ($generate_input_labels == true) {
                        // set up the label tag
                        $element_html .= "<label for='" . sanitize_text_field($element_name) . "'>";
                        $element_html .= esc_html__($element_before, 'seamless-donations');
                        $element_html .= " </label>";
                    } else {
                        $element_html .= $element_before;
                        // BEFORE
                    }
                    $element_html .= "<select ";
                    $element_html .= "name='" . sanitize_text_field($element_name) . "' ";
                    if ($element_size != '') {
                        $element_html .= "size='" . $element_size . "' ";
                    }
                    if ($element_id != '') {
                        $element_html .= "id='" . $element_id . "' ";
                    }
                    if ($element_placeholder != '') {
                        $element_html .= "placeholder='" . $element_placeholder . "' ";
                    }
                    if ($element_class != '') {
                        $element_html .= "class='" . $element_class . "' ";
                    }
                    if ($element_style != '') {
                        $element_html .= "style='" . $element_style . "' ";
                    }
                    if ($element_conceal != '') {
                        $element_html .= "data-conceal='" . $element_conceal . "' ";
                    }
                    $element_html = trim($element_html) . '>';
                    if (isset($element_reveal) and is_array($element_reveal)) {
                        foreach ($element_reveal as $element_reveal_key => $element_reveal_item) {
                            $reveal_array = explode(' ', $element_reveal_item);
                            for ($reveal_element_index = 0; $reveal_element_index < count($reveal_array); ++$reveal_element_index) {
                                $reveal_array[$reveal_element_index] = '.' . $reveal_array[$reveal_element_index];
                            }
                            $element_reveal[$element_reveal_key] = implode(', ', $reveal_array);
                        }
                    }
                    for ($options_index = 0; $options_index < count($element_options); ++$options_index) {
                        $option_value = seamless_donations_name_of($element_options, $options_index);
                        $element_html .= "<option value='" . $option_value . "'";
                        if ($element_value != '') {
                            // in a select, the value of the select element determines what's initially chose
                            if ($element_value == $option_value) {
                                $element_html .= " selected='selected'";
                            }
                            if (isset($element_reveal[$option_value])) {
                                $element_html .= " data-reveal='" . $element_reveal[$option_value] . "'";
                            }
                        }
                        $element_html .= ">";
                        $element_html .= $element_options[$option_value];
                        $element_html .= "</option>";
                    }
                    $element_html .= "</select>";
                    $element_html .= $element_after;
                }
            }
            // close the element div
            $element_html .= "</{$element_wrapper}>";
        }
        $form_html .= $element_html;
    }
    return $form_html;
}
コード例 #3
0
function validate_page_slug_seamless_donations_admin_templates_callback($_submitted_array, $_existing_array, $_setup_object)
{
    $_submitted_array = apply_filters('validate_page_slug_seamless_donations_admin_templates_callback', $_submitted_array, $_existing_array, $_setup_object);
    $section = seamless_donations_get_submitted_admin_section($_submitted_array);
    switch ($section) {
        case 'seamless_donations_admin_templates_section_test':
            // SAVE EMAILS //
            $test_mail = $_submitted_array[$section]['email_test_address'];
            $test_mail = sanitize_email($test_mail);
            if (!is_email($test_mail)) {
                // check address
                $_aErrors[$section]['email_test_address'] = __('Valid email address required.', 'seamless-donations');
                $_setup_object->setFieldErrors($_aErrors);
                $_setup_object->setSettingNotice(__('There were errors in your submission.', 'seamless-donations'));
                return $_existing_array;
            }
            dgx_donate_send_thank_you_email(0, $test_mail);
            $_setup_object->setSettingNotice('Test email sent.', 'updated');
            break;
        case 'seamless_donations_admin_templates_section_template':
            // SAVE TEMPLATE //
            // check email address
            $email = $_submitted_array[$section]['dgx_donate_email_reply'];
            $email = sanitize_email($email);
            if (!is_email($email)) {
                $_aErrors[$section]['dgx_donate_paypal_email'] = __('Valid email address required.', 'seamless-donations');
                $_setup_object->setFieldErrors($_aErrors);
                $_setup_object->setSettingNotice(__('There were errors in your submission.', 'seamless-donations'));
                return $_existing_array;
            }
            // check array fields for clean and not-empty
            for ($i = 0; $i < count($_submitted_array[$section]); ++$i) {
                $key = seamless_donations_name_of($_submitted_array[$section], $i);
                $value = trim($_submitted_array[$section][$key]);
                $value = wp_kses_post($value);
                if ($key == 'submit') {
                    continue;
                    // not a text field
                }
                if ($key == 'dgx_donate_email_reply') {
                    continue;
                    // already tested for validation
                }
                if ($value == "") {
                    $_aErrors[$section][$key] = __('This field must not be empty.', 'seamless-donations');
                    $_setup_object->setFieldErrors($_aErrors);
                    $_setup_object->setSettingNotice(__('There were errors in your submission.', 'seamless-donations'));
                    return $_existing_array;
                }
            }
            // save array fields as clean, sanitized options
            for ($i = 0; $i < count($_submitted_array[$section]); ++$i) {
                $key = seamless_donations_name_of($_submitted_array[$section], $i);
                $value = trim($_submitted_array[$section][$key]);
                if ($key == 'dgx_donate_email_reply') {
                    $value = sanitize_email($value);
                } else {
                    $value = wp_kses_post($value);
                }
                if ($key == 'submit') {
                    continue;
                    // not a text field
                }
                update_option($key, $value);
            }
            $_setup_object->setSettingNotice('Form updated successfully.', 'updated');
            break;
        case 'seamless_donations_admin_templates_section_extension':
            // LET EXTENSIONS DO THE PROCESSING
            break;
        default:
            $_setup_object->setSettingNotice(__('There was an unexpected error in your entry.', 'seamless-donations'));
    }
}