Exemplo n.º 1
0
		<?php 
foreach ($this->get_fields() as $field_key => $field) {
    ?>

			<?php 
    //Put errors for this particular field in $field_errors and current value in $field_current
    $field_errors = isset($form_errors[$field_key]) ? $form_errors[$field_key] : "";
    $field_current = isset($current[$field_key]) ? $current[$field_key] : "";
    $unique_key = 'form-' . $this->id . '-' . $field_key;
    ?>

			<?php 
    //Start outputting the field HTML if the field is enabled
    ?>
			<?php 
    if (wpfepp_is_field_supported($field['type'], $this->post_type)) {
        ?>
				<?php 
        if ($field['enabled']) {
            ?>

				<?php 
            if (isset($field['prefix_text']) && $field['prefix_text']) {
                ?>
					<div class="wpfepp-prefix-text">
						<?php 
                echo $field['prefix_text'];
                ?>
					</div>
				<?php 
            }
    /**
     * Outputs the HTML of a single dragable widget. Every widget corresponds to a front-end form field for instance title. Makes extensive use of WordPress' settings API.
     *
     * @var string $field_key Field key.
     * @var string $field Current settings of the field.
     **/
    public function display_item($field_key, $field)
    {
        $page = 'wpfepp_' . $field_key . '_widget';
        $section = $page . '_section';
        $callback = array($this->renderer, 'render');
        $args = array('group' => 'form_fields', 'subgroup' => $field_key, 'curr' => $field);
        add_settings_section($section, '', null, $page);
        add_settings_field('enabled', __('Enabled', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'enabled', 'type' => 'bool'), $args));
        add_settings_field('required', __('Required', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'required', 'type' => 'bool'), $args));
        add_settings_field('label', __('Label', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'label', 'type' => 'text'), $args));
        add_settings_field('width', __('Field Width', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'width', 'type' => 'text', 'desc' => 'Width in pixels or percentage. (e.g. 300px)'), $args));
        if ($field['type'] == 'title' || $field['type'] == 'content' || $field['type'] == 'excerpt' || $field['type'] == 'custom_field') {
            add_settings_field('min_words', __('Min Words', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'min_words', 'type' => 'int'), $args));
            add_settings_field('max_words', __('Max Words', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'max_words', 'type' => 'int'), $args));
            add_settings_field('strip_tags', __('Strip Tags', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'strip_tags', 'type' => 'select', 'desc' => __('These HTML tags will be removed before the post is inserted into the database.', 'wpfepp-plugin'), 'items' => array('none' => __('None', 'wpfepp-plugin'), 'unsafe' => __('Unsafe', 'wpfepp-plugin'), 'all' => __('All', 'wpfepp-plugin'))), $args));
        }
        if ($field['type'] == 'content' || $field['type'] == 'custom_field') {
            add_settings_field('nofollow', __('Nofollow All Links', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'nofollow', 'type' => 'bool'), $args));
        }
        if ($field['type'] == 'content') {
            add_settings_field('media_button', __('Display Media Button', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'media_button', 'type' => 'bool', 'desc' => __('The media button will show up only if the user has permission to upload media.', 'wpfepp-plugin')), $args));
            add_settings_field('max_links', __('Max Links', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'max_links', 'type' => 'int'), $args));
            add_settings_field('element', __('Form Element', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'element', 'type' => 'select', 'items' => array('richtext' => __('Rich Text Editor', 'wpfepp-plugin'), 'plaintext' => __('Textarea', 'wpfepp-plugin'))), $args));
        }
        if ($field['type'] == 'hierarchical_taxonomy') {
            add_settings_field('multiple', __('Allow Multiple Selections', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'multiple', 'type' => 'bool'), $args));
            add_settings_field('hide_empty', __('Hide Empty', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'hide_empty', 'type' => 'bool'), $args));
            add_settings_field('exclude', __('Exclude', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'exclude', 'type' => 'text', 'desc' => __('A comma-seperated list of term IDs that you want to exclude.', 'wpfepp-plugin')), $args));
            add_settings_field('include', __('Include', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'include', 'type' => 'text', 'desc' => __('A comma-seperated list of term IDs that you want to include.', 'wpfepp-plugin')), $args));
        }
        if ($field['type'] == 'non_hierarchical_taxonomy') {
            add_settings_field('min_count', __('Min Count', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'min_count', 'type' => 'int', 'desc' => __('Minimum number of terms that you want the user to enter.', 'wpfepp-plugin')), $args));
            add_settings_field('max_count', __('Max Count', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'max_count', 'type' => 'int', 'desc' => __('Maximum number of terms that you want the user to enter.', 'wpfepp-plugin')), $args));
        }
        if ($field['type'] == 'custom_field') {
            add_settings_field('element', __('Form Element', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'element', 'type' => 'select', 'items' => array('input' => __('Text Field', 'wpfepp-plugin'), 'textarea' => __('Text Area', 'wpfepp-plugin'), 'checkbox' => __('Checkbox', 'wpfepp-plugin'), 'select' => __('Select', 'wpfepp-plugin'), 'radio' => __('Radio Buttons', 'wpfepp-plugin'), 'email' => __('Email', 'wpfepp-plugin'), 'url' => __('URL', 'wpfepp-plugin'), 'image_url' => __('Image URL', 'wpfepp-plugin'))), $args));
            add_settings_field('choices', __('Choices', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'choices', 'type' => 'textarea', 'desc' => __('The choices for select and radio elements. One per line. Key value pairs can be added like this: key|Value', 'wpfepp-plugin')), $args));
        }
        add_settings_field('prefix_text', __('Instructions', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'prefix_text', 'type' => 'textarea', 'desc' => 'The text that you want to place above this field.'), $args));
        add_settings_field('fallback_value', __('Fallback Value', 'wpfepp-plugin'), $callback, $page, $section, array_merge(array('id' => 'fallback_value', 'type' => 'textarea', 'desc' => 'The value to use when this field is disabled. You can leave this empty. For title, content, excerpt and custom fields enter text. For hierarchical taxonomies (e.g. category) enter comma-seperated IDs, for non-hierarchical taxonomies (e.g. tag) add a comma-seperated list of slugs and for post thumb add an image ID.'), $args));
        ?>
				<li class="wpfepp-widget-container <?php 
        echo wpfepp_is_field_supported($field['type'], $this->post_type) ? '' : 'hidden';
        ?>
">
					<div class="wpfepp-widget-head">
						<strong><?php 
        echo $field['widget_label'];
        ?>
</strong>
						<span class="wpfepp-expand"><i class="wpfepp-icon-arrow-down"></i></span>
						<?php 
        if ($field['type'] == 'custom_field') {
            ?>
							<span class="wpfepp-custom-field-delete"><i class="wpfepp-icon-remove"></i></span>
						<?php 
        }
        ?>
					</div>
					<div class="wpfepp-widget-body">
						<?php 
        do_settings_sections($page);
        ?>
						<input type="hidden" name="form_fields[<?php 
        echo $field_key;
        ?>
][type]" value="<?php 
        echo $field['type'];
        ?>
">
						<input type="hidden" name="form_fields[<?php 
        echo $field_key;
        ?>
][widget_label]" value="<?php 
        echo $field['widget_label'];
        ?>
">
					</div>
				</li>
			<?php 
    }
Exemplo n.º 3
0
 /**
  * Checks if the user-submitted data meets the minimum requirements of the form, set by the site administrator in the options panel.
  * 
  * This function goes through each field and makes sure that the submitted data corresponding to that field ($post_data[$key]) meets the requirements set by the admin. Note that the key of each field is used as the name attribute in the form.
  * 
  * @access private
  *
  * @param array $post_data An array containing all the data from the form.
  * @return array $errors A multidimmensional array of errors. Each array member contains all the errors for a particular field.
  **/
 private function check_restrictions($post_data)
 {
     $errors = array();
     $user_defined_errors = get_option('wpfepp_errors');
     if (wpfepp_current_user_has($this->settings['no_restrictions'])) {
         return $errors;
     }
     foreach ($this->get_fields() as $key => $field) {
         if (wpfepp_is_field_supported($field['type'], $this->post_type) && isset($field['enabled']) && $field['enabled'] && isset($field['required']) && $field['required']) {
             $stripped_value = isset($post_data[$key]) ? $post_data[$key] : "";
             if (is_string($stripped_value)) {
                 $stripped_value = strip_tags(trim($stripped_value));
             }
             if (empty($stripped_value) || $stripped_value == -1 || is_array($stripped_value) && !count($stripped_value)) {
                 $errors[$key][] = $user_defined_errors['required'];
             }
             if (isset($field['min_words']) && is_numeric($field['min_words']) && $this->word_count($stripped_value) < $field['min_words']) {
                 $errors[$key][] = sprintf(str_replace('{0}', '%s', $user_defined_errors['min_words']), $field['min_words']);
             }
             if (isset($field['max_words']) && is_numeric($field['max_words']) && $this->word_count($stripped_value) > $field['max_words']) {
                 $errors[$key][] = sprintf(str_replace('{0}', '%s', $user_defined_errors['max_words']), $field['max_words']);
             }
             if (isset($field['min_count']) && is_numeric($field['min_count']) && $this->segment_count($stripped_value) < $field['min_count']) {
                 $errors[$key][] = sprintf(str_replace('{0}', '%s', $user_defined_errors['min_segments']), $field['min_count']);
             }
             if (isset($field['max_count']) && is_numeric($field['max_count']) && $this->segment_count($stripped_value) > $field['max_count']) {
                 $errors[$key][] = sprintf(str_replace('{0}', '%s', $user_defined_errors['max_segments']), $field['max_count']);
             }
             if (isset($field['max_links']) && is_numeric($field['max_links']) && $this->count_links($post_data[$key]) > $field['max_links']) {
                 $errors[$key][] = sprintf(str_replace('{0}', '%s', $user_defined_errors['max_links']), $field['max_links']);
             }
         }
     }
     return $errors;
 }