コード例 #1
0
/**
 * 
 * Views-Shortcode: wpv-control
 *
 * Description: Add filters for View
 *
 * Parameters:
 * type: type of retrieved field layout (radio, checkbox, select, textfield, checkboxes, datepicker)
 * url_param: the URL parameter passed as an argument
 * values: Optional. a list of supplied values
 * display_values: Optional. A list of values to display for the corresponding values
 * auto_fill: Optional. When set to a "field-slug" the control will be populated with custom field values from the database.
 * auto_fill_default: Optional. Used to set the default, unselected, value of the control. eg Ignore or Don't care
 * auto_fill_sort: Optional. 'asc', 'desc', 'ascnum', 'descnum', 'none'. Defaults to ascending.
 * field: Optional. a Types field to retrieve values from
 * title: Optional. Use for the checkbox title
 * taxonomy: Optional. Use when a taxonomy control should be displayed.
 * default_label: Optional. Use when a taxonomy control should be displayed using select input type.
 * date_format: Optional. Used for a datepicker control
 *
 * Example usage:
 *
 * Link:
 * More details about this shortcode here: <a href="http://wp-types.com/documentation/wpv-control-fields-in-front-end-filters/" title="wpv-control – Displaying fields in front-end filters">http://wp-types.com/documentation/wpv-control-fields-in-front-end-filters/</a>
 *
 * Note:
 *
 */
function wpv_shortcode_wpv_control($atts)
{
    if (!isset($atts['url_param'])) {
        return __('The url_param is missing from the wpv-control shortcode argument.', 'wpv-views');
    }
    if ((!isset($atts['type']) || $atts == '') && !isset($atts['field'])) {
        return __('The "type" or "field" needs to be set in the wpv-control shortcode argument.', 'wpv-views');
    }
    extract(shortcode_atts(array('type' => '', 'values' => array(), 'display_values' => array(), 'field' => '', 'url_param' => '', 'title' => '', 'taxonomy' => '', 'default_label' => '', 'auto_fill' => '', 'auto_fill_default' => '', 'auto_fill_sort' => '', 'date_format' => ''), $atts));
    if ($taxonomy != '') {
        // pass the new shortcode attribute $default_label
        return _wpv_render_taxonomy_control($taxonomy, $type, $url_param, $default_label);
    }
    if ($auto_fill != '') {
        // See if we should handle types checkboxes
        $types_checkboxes_field = false;
        if (_wpv_is_field_of_type($auto_fill, 'checkboxes')) {
            if (!function_exists('wpcf_admin_fields_get_fields')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                }
            }
            if (function_exists('wpcf_admin_fields_get_fields')) {
                $fields = wpcf_admin_fields_get_fields();
                $field_name = substr($auto_fill, 5);
                if (isset($fields[$field_name])) {
                    $types_checkboxes_field = true;
                    $db_values = array();
                    $options = $fields[$field_name]['data']['options'];
                    foreach ($options as $option) {
                        $db_values[] = $option['title'];
                    }
                    switch (strtolower($auto_fill_sort)) {
                        case 'desc':
                            sort($db_values);
                            $db_values = array_reverse($db_values);
                            break;
                        case 'descnum':
                            sort($db_values, SORT_NUMERIC);
                            $db_values = array_reverse($db_values);
                            break;
                        case 'none':
                            break;
                        case 'ascnum':
                            sort($db_values, SORT_NUMERIC);
                            break;
                        default:
                            sort($db_values);
                            break;
                    }
                }
            }
        }
        if (!$types_checkboxes_field) {
            if (!function_exists('wpcf_admin_fields_get_fields')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                }
            }
            if (function_exists('wpcf_admin_fields_get_fields')) {
                $fields = wpcf_admin_fields_get_fields();
            }
            $field_name = substr($auto_fill, 5);
            if (isset($fields) && isset($fields[$field_name]) && isset($fields[$field_name]['data']['options'])) {
                $display_text = array();
                $options = $fields[$field_name]['data']['options'];
                if (isset($options['default'])) {
                    unset($options['default']);
                }
                // remove the default option from the array
                if (isset($fields[$field_name]['data']['display'])) {
                    $display_option = $fields[$field_name]['data']['display'];
                }
                foreach ($options as $option) {
                    if (isset($option['value'])) {
                        $db_values[] = $option['value'];
                    }
                    if (isset($display_option) && 'value' == $display_option && isset($option['display_value'])) {
                        $display_text[$option['value']] = $option['display_value'];
                        // fill an array with the actual display values
                    } else {
                        $display_text[$option['value']] = $option['title'];
                    }
                }
            } else {
                global $wpdb;
                switch (strtolower($auto_fill_sort)) {
                    case 'desc':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value DESC");
                        break;
                    case 'descnum':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value + 0 DESC");
                        break;
                    case 'none':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}'");
                        break;
                    case 'ascnum':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value + 0 ASC");
                        break;
                    default:
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value ASC");
                        break;
                }
            }
        }
        if ($auto_fill_default != '') {
            $values = '';
            $display_values = $auto_fill_default;
            $first = false;
        } else {
            $values = '';
            $display_values = '';
            $first = true;
        }
        foreach ($db_values as $value) {
            if ($value) {
                if (!$first) {
                    $values .= ',';
                    $display_values .= ',';
                }
                $values .= $value;
                if (isset($display_text[$value])) {
                    $display_values .= $display_text[$value];
                } else {
                    $display_values .= $value;
                }
                $first = false;
            }
        }
    }
    $out = '';
    // Use when values attributes are defined (predefined values to list)
    if (!empty($values)) {
        $values_arr = explode(',', $values);
        if (!empty($display_values)) {
            $display_values = explode(',', $display_values);
        }
        $options = array();
        if (!in_array($type, array('radio', 'radios', 'select', 'checkboxes'))) {
            $type = 'select';
        }
        if ($type == 'radio') {
            $type = 'radios';
        }
        switch ($type) {
            case 'checkboxes':
                $defaults = array();
                $original_get = null;
                if (isset($auto_fill_default)) {
                    // check if the defaul value already exists and set the appropriate arrays and values
                    $num_auto_fill_default_display = array_count_values($display_values);
                    if (isset($num_auto_fill_default_display[$auto_fill_default]) && $num_auto_fill_default_display[$auto_fill_default] > 1 || in_array($auto_fill_default, $values_arr)) {
                        // if the default value is an existing display value or stored value
                        $values_arr_def = array_shift($values_arr);
                        $display_values_def = array_shift($display_values);
                    }
                    $defaults = explode(',', $auto_fill_default);
                    $defaults = array_map('trim', $defaults);
                }
                if (isset($_GET[$url_param])) {
                    $original_get = $_GET[$url_param];
                    $defaults = $_GET[$url_param];
                    if (is_string($defaults)) {
                        $defaults = explode(',', $defaults);
                    }
                    unset($_GET[$url_param]);
                }
                for ($i = 0; $i < count($values_arr); $i++) {
                    $value = $values_arr[$i];
                    $value = trim($value);
                    // Check for a display value.
                    if (isset($display_values[$i])) {
                        $display_value = $display_values[$i];
                    } else {
                        $display_value = $value;
                    }
                    $options[$value]['#name'] = $url_param . '[]';
                    $options[$value]['#title'] = $display_value;
                    $options[$value]['#value'] = $value;
                    $options[$value]['#default_value'] = in_array($value, $defaults) || in_array($options[$value]['#title'], $defaults);
                    // set default using option titles too
                    //                    $options[$value]['#inline'] = true;
                    //                    $options[$value]['#after'] = '&nbsp;&nbsp;';
                }
                $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options)));
                if ($original_get) {
                    $_GET[$url_param] = $original_get;
                }
                break;
            default:
                for ($i = 0; $i < count($values_arr); $i++) {
                    $value = $values_arr[$i];
                    $value = trim($value);
                    // Check for a display value.
                    if (isset($display_values[$i])) {
                        $display_value = $display_values[$i];
                    } else {
                        $display_value = $value;
                    }
                    $options[$display_value] = $value;
                }
                if (count($values_arr) != count($options)) {
                    // if the $values_arr has one more item than $options, there is a repeating value reset on creation: the existing default
                    $default_value = reset($options);
                } else {
                    // so the default value in this case is the first element in $values_arr
                    $default_value = $values_arr[0];
                }
                if (isset($_GET[$url_param]) && in_array($_GET[$url_param], $options)) {
                    $default_value = $_GET[$url_param];
                }
                $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value)));
                break;
        }
        return $element;
    } else {
        if (!empty($field)) {
            // check if Types is active
            if (!function_exists('wpcf_admin_fields_get_field')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                } else {
                    return __('Types plugin is required.', 'wpv-views');
                }
            }
            if (!function_exists('wpv_form_control')) {
                include '../common/functions.php';
            }
            // get field options
            $field_options = wpcf_admin_fields_get_field($field);
            if (empty($field_options)) {
                return __('Empty field values or incorrect field defined. ', 'wpv-views');
            }
            $field_options['name'] = wpcf_translate('field ' . $field_options['id'] . ' name', $field_options['name']);
            // get the type of custom field (radio, checkbox, other)
            $field_type = $field_options['type'];
            // override with type
            if (!empty($type)) {
                $field_type = $type;
            }
            if (!in_array($field_type, array('radio', 'checkbox', 'checkboxes', 'select', 'textfield', 'date', 'datepicker'))) {
                $field_type = 'textfield';
            }
            // Radio field
            if ($field_type == 'radio') {
                $field_radio_options = $field_options['data']['options'];
                $options = array();
                foreach ($field_radio_options as $key => $opts) {
                    if (is_array($opts)) {
                        if (isset($field_options['data']['display']) && 'value' == $field_options['data']['display'] && isset($opts['display_value'])) {
                            $options[$opts['display_value']] = $opts['value'];
                            // if we have an actual display value and is set to be used, use it
                        } else {
                            $options[$opts['title']] = $opts['value'];
                            // else, use the field value title
                        }
                    }
                }
                // get the form content
                $element = wpv_form_control(array('field' => array('#type' => 'radios', '#id' => 'wpv_control_radio_' . $field, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => isset($_GET[$url_param]) ? $_GET[$url_param] : null)));
                return $element;
            } else {
                if ($field_type == 'checkbox') {
                    if (isset($atts['title'])) {
                        $checkbox_name = $title;
                    } else {
                        $checkbox_name = $field_options['name'];
                    }
                    $element = wpv_form_control(array('field' => array('#type' => 'checkbox', '#id' => 'wpv_control_checkbox_' . $field, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#title' => $checkbox_name, '#value' => $field_options['data']['set_value'], '#default_value' => 0)));
                    return $element;
                } else {
                    if ($field_type == 'checkboxes') {
                        $defaults = array();
                        $original_get = null;
                        if (isset($_GET[$url_param])) {
                            $original_get = $_GET[$url_param];
                            $defaults = $_GET[$url_param];
                            if (is_string($defaults)) {
                                $defaults = explode(',', $defaults);
                            }
                            unset($_GET[$url_param]);
                        }
                        foreach ($field_options['data']['options'] as $value) {
                            $value = trim($value['title']);
                            $display_value = $value;
                            $options[$value]['#name'] = $url_param . '[]';
                            $options[$value]['#title'] = $display_value;
                            $options[$value]['#value'] = $value;
                            $options[$value]['#default_value'] = in_array($value, $defaults);
                            //                $options[$value]['#inline'] = true;
                            //                $options[$value]['#after'] = '&nbsp;&nbsp;';
                        }
                        $element = wpv_form_control(array('field' => array('#type' => 'checkboxes', '#id' => 'wpv_control_checkbox_' . $field, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options)));
                        if ($original_get) {
                            $_GET[$url_param] = $original_get;
                        }
                        return $element;
                    } else {
                        if ($field_type == 'select') {
                            $field_select_options = $field_options['data']['options'];
                            $options = array();
                            foreach ($field_select_options as $key => $opts) {
                                if (is_array($opts)) {
                                    $options[$opts['title']] = $opts['value'];
                                }
                            }
                            $default_value = false;
                            if (isset($_GET[$url_param]) && in_array($_GET[$url_param], $options)) {
                                $default_value = $_GET[$url_param];
                            }
                            $element = wpv_form_control(array('field' => array('#type' => 'select', '#id' => 'wpv_control_select_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value)));
                            return $element;
                        } else {
                            if ($field_type == 'textfield') {
                                $default_value = '';
                                if (isset($_GET[$url_param])) {
                                    $default_value = esc_attr($_GET[$url_param]);
                                }
                                $element = wpv_form_control(array('field' => array('#type' => 'textfield', '#id' => 'wpv_control_textfield_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value)));
                                return $element;
                            } else {
                                if ($field_type == 'date' || $field_type == 'datepicker') {
                                    $out = wpv_render_datepicker($url_param, $date_format);
                                    return $out;
                                }
                            }
                        }
                    }
                }
            }
            return '';
        } else {
            // type parameter without values
            $default_value = '';
            if (isset($_GET[$url_param])) {
                $default_value = $_GET[$url_param];
            }
            switch ($type) {
                case 'checkbox':
                    $element = array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value));
                    $element['field']['#title'] = $title;
                    $element = wpv_form_control($element);
                    break;
                case 'datepicker':
                    $element = wpv_render_datepicker($url_param, $date_format);
                    break;
                default:
                    $element = array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value));
                    $element = wpv_form_control($element);
                    break;
            }
            return $element;
        }
    }
}
コード例 #2
0
	static function wpv_render_custom_field_options( $args, $view_settings = array() ) {
		global $WP_Views_fapi;
		$compare = array( 
			'=' => __( 'equal to', 'wpv-views' ),
			'!=' => __( 'different from', 'wpv-views' ),
			'>' => __( 'greater than', 'wpv-views' ),
			'>=' => __( 'greater than or equal', 'wpv-views' ),
			'<' => __( 'lower than', 'wpv-views' ),
			'<=' => __( 'lower than or equal', 'wpv-views' ),
			'LIKE' => __( 'like', 'wpv-views' ),
			'NOT LIKE' => __( 'not like', 'wpv-views' ),
			'IN' => __( 'in', 'wpv-views' ),
			'NOT IN' => __( 'not in', 'wpv-views' ),
			'BETWEEN' => __( 'between', 'wpv-views' ),
			'NOT BETWEEN' => __( 'not between', 'wpv-views' )
		);
		$types = array( 
			'CHAR' => __( 'string', 'wpv-views' ), 
			'NUMERIC' => __( 'number', 'wpv-views' ),
			'BINARY' => __( 'boolean', 'wpv-views' ),
			'DECIMAL' => 'DECIMAL',
			'DATE' => 'DATE',
			'DATETIME' => 'DATETIME',
			'TIME' => 'TIME',
			'SIGNED' => 'SIGNED',
			'UNSIGNED' => 'UNSIGNED'
		);
		$options = array(
			__( 'Constant', 'wpv-views' ) => 'constant',
			__( 'URL parameter', 'wpv-views' ) => 'url',
			__( 'Shortcode attribute', 'wpv-views' ) => 'attribute',
			'NOW' => 'now',
			'TODAY' => 'today',
			'FUTURE_DAY' => 'future_day',
			'PAST_DAY' => 'past_day',
			'THIS_MONTH' => 'this_month',
			'FUTURE_MONTH' => 'future_month',
			'PAST_MONTH' => 'past_month',
			'THIS_YEAR' => 'this_year',
			'FUTURE_YEAR' => 'future_year',
			'PAST_YEAR' => 'past_year',
			'SECONDS_FROM_NOW' => 'seconds_from_now',
			'MONTHS_FROM_NOW' => 'months_from_now',
			'YEARS_FROM_NOW' => 'years_from_now',
			'DATE' => 'date'
		);
		$options_with_framework = array(
			__( 'Constant', 'wpv-views' ) => 'constant',
			__( 'URL parameter', 'wpv-views' ) => 'url',
			__( 'Shortcode attribute', 'wpv-views' ) => 'attribute',
			__( 'Framework value', 'wpv-views' ) => 'framework',
			'NOW' => 'now',
			'TODAY' => 'today',
			'FUTURE_DAY' => 'future_day',
			'PAST_DAY' => 'past_day',
			'THIS_MONTH' => 'this_month',
			'FUTURE_MONTH' => 'future_month',
			'PAST_MONTH' => 'past_month',
			'THIS_YEAR' => 'this_year',
			'FUTURE_YEAR' => 'future_year',
			'PAST_YEAR' => 'past_year',
			'SECONDS_FROM_NOW' => 'seconds_from_now',
			'MONTHS_FROM_NOW' => 'months_from_now',
			'YEARS_FROM_NOW' => 'years_from_now',
			'DATE' => 'date'
		);
		$options_with_framework_broken = array(
			__( 'Select one option...', 'wpv-views' ) => '',
			__( 'Constant', 'wpv-views' ) => 'constant',
			__( 'URL parameter', 'wpv-views' ) => 'url',
			__( 'Shortcode attribute', 'wpv-views' ) => 'attribute',
			'NOW' => 'now',
			'TODAY' => 'today',
			'FUTURE_DAY' => 'future_day',
			'PAST_DAY' => 'past_day',
			'THIS_MONTH' => 'this_month',
			'FUTURE_MONTH' => 'future_month',
			'PAST_MONTH' => 'past_month',
			'THIS_YEAR' => 'this_year',
			'FUTURE_YEAR' => 'future_year',
			'PAST_YEAR' => 'past_year',
			'SECONDS_FROM_NOW' => 'seconds_from_now',
			'MONTHS_FROM_NOW' => 'months_from_now',
			'YEARS_FROM_NOW' => 'years_from_now',
			'DATE' => 'date'
		);
		$fw_key_options = array();
		$fw_key_options = apply_filters( 'wpv_filter_extend_framework_options_for_custom_field', $fw_key_options );
		$name_sanitized = str_replace( ' ', '_', $args['name'] );
		if ( isset( $view_settings['custom-field-' . $name_sanitized . '_value'] ) ) {
			$value = $view_settings['custom-field-' . $name_sanitized . '_value'];
		} else {
			$value = '';
		}
		$parts = array( $value );
		$value = WPV_Filter_Item::encode_date( $value );
		if ( isset( $view_settings['custom-field-' . $name_sanitized . '_compare'] ) ) {
			$compare_selected = $view_settings['custom-field-' . $name_sanitized . '_compare'];
		} else {
			$compare_selected = '=';
		}
		if ( isset( $view_settings['custom-field-' . $name_sanitized . '_type'] ) ) {
			$type_selected = $view_settings['custom-field-' . $name_sanitized . '_type'];
		} else {
			$type_selected = 'CHAR';
		}
		$name = 'custom-field-' . $name_sanitized . '%s';
		switch ( $compare_selected ) {
			case 'BETWEEN':
			case 'NOT BETWEEN':
				$parts = explode( ',', $value );
				// Make sure we have only 2 items
				while ( count( $parts ) < 2 ) {
					$parts[] = '';
				}
				while ( count( $parts ) > 2 ) {
					array_pop($parts);
				}
				break;
			case 'IN':
			case 'NOT IN':
				$parts = explode( ',', $value );
				if ( count( $parts ) < 1 ) {
					$parts = array( $value );
				}
				break;
		}
		$value = WPV_Filter_Item::unencode_date( $value );
		?>
			<?php echo sprintf( __( 'The custom field %s is a', 'wpv-views' ), $args['nicename'] ); ?>
			<select name="<?php echo esc_attr( sprintf( $name, '_type' ) ); ?>" class="js-wpv-custom-field-type-select" autocomplete="off">
				<?php
				foreach ( $types as $type_key => $type_val ) {
				?>
				<option value="<?php echo esc_attr( $type_key ); ?>" <?php selected( $type_selected, $type_key ); ?>><?php echo $type_val; ?></option>
				<?php
				}
				?>
			</select>
			<?php _e( 'that is', 'wpv-views' ); ?>
			<select name="<?php echo esc_attr( sprintf( $name, '_compare' ) ); ?>" class="wpv_custom_field_compare_select js-wpv-custom-field-compare-select" autocomplete="off">
				<?php
				foreach ( $compare as $com_key => $com_val ) {
				?>
				<option value="<?php echo esc_attr( $com_key ); ?>" <?php selected( $compare_selected, $com_key ); ?>><?php echo $com_val; ?></option>
				<?php
				}
				?>
			</select>
			<div class="wpv-filter-multiple-element-options-mode js-wpv-custom-field-values">
				<input type="hidden" class="js-wpv-custom-field-values-real" name="<?php echo esc_attr( sprintf( $name, '_value' ) ); ?>" value="<?php echo esc_attr( $value ); ?>" autocomplete="off" />
				<?php
				foreach ( $parts as $i => $value_part ) {
					?>
					<div class="wpv_custom_field_value_div js-wpv-custom-field-value-div">
						<?php _e( 'the', 'wpv-views' ); ?>
						<?php
						$function_value = WPV_Filter_Item::get_custom_filter_function_and_value( $value_part );
						$selected_function = $function_value['function'];
						$options_to_pass = $options;
						if ( $WP_Views_fapi->framework_valid ) {
							$options_to_pass = $options_with_framework;
						} else if ( $selected_function == 'framework' ) {
							$options_to_pass = $options_with_framework_broken;
						}
						echo wpv_form_control( 
							array(
								'field' => array(
									'#name' => 'wpv_custom_field_compare_mode-' . $name_sanitized . $i ,
									'#type' => 'select',
									'#attributes' => array(
										'style' => '',
										'class' => 'wpv_custom_field_compare_mode js-wpv-custom-field-compare-mode js-wpv-element-not-serialize js-wpv-filter-validate',
										'data-type' => 'select',
										'autocomplete' => 'off'
									),
									'#inline' => true,
									'#options' => $options_to_pass,
									'#default_value' => $selected_function,
								)
							)
						);
						$validate_class = '';
						$validate_type = 'none';
						$hidden_input = '';
						$hidden_date = '';
						$hidden_framework_select = '';
						switch ( $selected_function ) {
							case 'constant':
							case 'future_day':
							case 'past_day':
							case 'future_month':
							case 'past_month':
							case 'future_year':
							case 'past_year':
							case 'seconds_from_now':
							case 'months_from_now':
							case 'years_from_now':
								$hidden_date = ' style="display:none"';
								$hidden_framework_select = ' style="display:none"';
								break;
							case 'url':
								$validate_class = 'js-wpv-filter-validate';
								$validate_type = 'url';
								$hidden_date = ' style="display:none"';
								$hidden_framework_select = ' style="display:none"';
								break;
							case 'attribute':
								$validate_class = 'js-wpv-filter-validate';
								$validate_type = 'shortcode';
								$hidden_date = ' style="display:none"';
								$hidden_framework_select = ' style="display:none"';
								break;
							case 'date':
								$hidden_input = ' style="display:none"';
								$hidden_framework_select = ' style="display:none"';
								break;
							case 'framework':
								$hidden_input = ' style="display:none"';
								$hidden_date = ' style="display:none"';
								break;
							default:
								$hidden_input = ' style="display:none"';
								$hidden_date = ' style="display:none"';
								$hidden_framework_select = ' style="display:none"';
								break;
						}
						?>
						<span class="js-wpv-custom-field-value-combo-input" <?php echo $hidden_input; ?>>
						<input type="text" class="js-wpv-custom-field-value-text js-wpv-element-not-serialize <?php echo $validate_class; ?>" value="<?php echo esc_attr( $function_value['value'] ); ?>" data-class="js-wpv-custom-field-<?php echo esc_attr( $args['name'] ); ?>-value-text" data-type="<?php echo esc_attr( $validate_type ); ?>" name="wpv-custom-field-<?php echo esc_attr( $args['name'] ); ?>-value-text" autocomplete="off" />
						</span>
						<span class="js-wpv-custom-field-value-combo-framework" <?php echo $hidden_framework_select; ?>>
						<?php
						if ( $WP_Views_fapi->framework_valid ) {
							?>
							<select class="js-wpv-custom-field-framework-value js-wpv-custom-field-framework-value-text js-wpv-element-not-serialize" name="wpv-custom-field-<?php echo esc_attr( $args['name'] ); ?>-framework-value-text" autocomplete="off">
								<option value=""><?php _e( 'Select a key', 'wpv-views' ); ?></option>
								<?php
								foreach ( $fw_key_options as $index => $value ) {
								?>
								<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $function_value['value'], $index ); ?>><?php echo $value; ?></option>
								<?php
								}
								?>
							</select>
							<?php
						} else {
							?>
							<span class="wpv-combo">
							<input type="hidden" class="js-wpv-custom-field-framework-value js-wpv-custom-field-framework-value-text js-wpv-element-not-serialize" value="" autocomplete="off" />
							<?php
							$WP_Views_fapi->framework_missing_message_for_filters( false, false );
							?>
							</span>
							<?php
						}
						?>
						</span>
						<span class="js-wpv-custom-field-value-combo-date" <?php echo $hidden_date; ?>>
						<?php
						WPV_Filter_Item::date_field_controls( $function_value['function'], $function_value['value'] );
						?>
						</span>
						<button class="button-secondary js-wpv-custom-field-remove-value"><i class="icon-remove"></i> <?php echo __( 'Remove', 'wpv-views' ); ?></button>
					</div>
					<?php
				}
				?>
				<button class="button button-secondary js-wpv-custom-field-add-value" style="margin-top:10px;"><i class="icon-plus"></i> <?php echo __( 'Add another value', 'wpv-views' ); ?></button>
			</div>
	<?php
	}
コード例 #3
0
function wpv_shortcode_wpv_control_item( $atts, $value ) {
	global $sitepress;
	// First control checks
	if ( !function_exists( 'wpcf_pr_get_belongs' ) ) {
		return __( 'You need the Types plugin to render this parametric search control', 'wpv-views' );
	}
	if ( !isset( $atts['url_param'] ) || empty( $atts['url_param'] ) ) {
		return __('The url_param argument is missing from the wpv-control-set shortcode.', 'wpv-views');
	}
	if ( !isset( $atts['type'] ) || empty( $atts['type'] ) ) {
		return __('The type argument needs to be set in the wpv-control-item shortcode.', 'wpv-views');
	}
	if ( !isset( $atts['ancestor_type'] ) || empty( $atts['ancestor_type'] ) ) {
		return __('The ancestor_type argument is missing from the wpv-control-item shortcode.', 'wpv-views');
	}
	if ( !isset( $atts['ancestor_tree'] ) || empty( $atts['ancestor_tree'] ) ) {
		return __('The ancestors argument is missing from the wpv-control-set shortcode.', 'wpv-views');
	}
	if ( !isset( $atts['returned_pt_parents'] ) || empty( $atts['returned_pt_parents'] ) ) {
		return __('The post types listed in this View do not have ancestors.', 'wpv-views');
	}
	extract(
		shortcode_atts( array(
				'type' => '', // select, multi-select, checbox, checkboxes, radio/radios, date/datepicker, textfield
				'url_param' => '', // URL parameter to be used
				'ancestor_type' => '',
				'ancestor_tree' => '',
				'default_label' => '',
				'returned_pt' => '',
				'returned_pt_parents' => '',
				'format' => false,
				'orderby' => 'title', // can be any key of $allowed_orderby_values
				'order' => 'ASC', // ASC or DESC
                'style' => '', // inline styles for input
                'class' => '', // input classes
                'label_style' => '', // inline styles for input label
                'label_class' => '' // classes for input label
			), $atts)
	);
    
    $style = esc_attr( $style );
    $class = esc_attr( $class );
    $label_style = esc_attr( $label_style );
    $label_class = esc_attr( $label_class );   
    
	$ancestor_tree_array = explode( '>', $ancestor_tree ); // NOTE this makes it useful for just one-branch scenarios, might extend this
	if ( !in_array( $ancestor_type, $ancestor_tree_array ) ) {
		return __( 'The ancestor_type argument refers to a post type that is not included in the ancestors tree.', 'wpv-views' );
	}
	global $wpdb, $WP_Views;
	$return = '';
	$this_type_parent_classes = array();
	$returned_post_types = explode( ',', $returned_pt );
	$returned_post_type_parents = explode( ',', $returned_pt_parents );
	
	$filter_full_list = false;
	
	$this_tree_ground = end( $ancestor_tree_array );
	$this_tree_roof = reset( $ancestor_tree_array );
	if ( !in_array( $this_tree_ground, $returned_post_type_parents ) ) {
		return __( 'The ancestors argument does not end with a valid parent for the returned post types on this View.', 'wpv-views' );
	}
	
	if ( !empty( $default_label ) ) {
		$aux_array = $WP_Views->view_used_ids;
		$view_name = get_post_field( 'post_name', end($aux_array));
		$default_label = wpv_translate( $ancestor_type . '_default_label', $default_label, false, 'View ' . $view_name );
	}

	// Validate order and orderby arguments for SQL query (ignore invalid values).

	// Allowed values and their translation into names of wp_posts columns.
	$allowed_orderby_values = array(
			'id' => 'ID',
			'title' => 'post_title',
			'date' => 'post_date',
			'date_modified' => 'post_modified',
			'comment_count' => 'comment_count' );
	if( ! isset( $allowed_orderby_values[ $orderby ] ) ) {
		$orderby = 'title';
	}
	// Now $orderby contains a valid column name at all times.
	$orderby = $allowed_orderby_values[ $orderby ];
	// Default to ASC on invalid $order value.
	$order = ( 'DESC' == strtoupper( $order ) ) ? 'DESC' : 'ASC';
	
	$view_settings = $WP_Views->get_view_settings();
	$dependant = false;
	$counters = false;
	$empty_action = array();
	if ( isset( $view_settings['dps'] ) && is_array( $view_settings['dps'] ) && isset( $view_settings['dps']['enable_dependency'] ) && $view_settings['dps']['enable_dependency'] == 'enable' ) {
		$dependant = true;
		$force_disable_dependant = $WP_Views->get_force_disable_dependant_parametric_search();
		if ( $force_disable_dependant ) {
			$dependant = false;
		}
	}
	if ( $format && strpos( $format, '%%COUNT%%' ) !== false ) {
		$counters = true;
	}
	
	if ( ( $dependant || $counters ) && $this_tree_ground == $ancestor_type ) {
		$wpv_data_cache = array();
		// Construct $wpv_data_cache
		if ( !isset( $_GET[$url_param] ) || empty( $_GET[$url_param] ) || $_GET[$url_param] === 0 || ( is_array( $_GET[$url_param] ) && in_array( (string) 0, $_GET[$url_param] ) ) ) {
			// This is when there is no value selected
			global $wp_object_cache;
			$wpv_data_cache = isset( $wp_object_cache->cache ) ? $wp_object_cache->cache : array();
		} else {
			// When there is a selected value, create a pseudo-cache based on all the other filters
			$query = wpv_get_dependant_view_query_args();
			$aux_cache_query = null;
			$filter_full_list = true;
			if ( isset( $query['post__in'] ) && is_array( $query['post__in'] ) && isset( $query['pr_filter_post__in'] ) && is_array( $query['pr_filter_post__in'] ) ) {
				$diff = array_diff( $query['post__in'], $query['pr_filter_post__in'] );
				if ( empty( $diff ) ) {// TODO maybe we can skip the query here
					unset( $query['post__in'] );
				} else {
					$query['post__in'] = $diff;
				}
			}
			$aux_cache_query = new WP_Query($query);
			if ( is_array( $aux_cache_query->posts ) && !empty( $aux_cache_query->posts ) ) {
				$f_fields = array( '_wpcf_belongs_' . $ancestor_type . '_id' );
				$wpv_data_cache = wpv_custom_cache_metadata( $aux_cache_query->posts, array( 'cf' => $f_fields ) );
			}
		}
		if ( !isset( $wpv_data_cache['post_meta'] ) ) {
			$wpv_data_cache['post_meta'] = array();
		}
		$empty_default = 'hide';
		$empty_alt = 'disable';
		$empty_options = array( 'select', 'radios', 'checkboxes' ); // multi-select is a special case because of dashes and underscores
		foreach ( $empty_options as $empty_opt ) {
			if ( isset( $view_settings['dps']['empty_' . $empty_opt] ) && $view_settings['dps']['empty_' . $empty_opt] == $empty_alt ) {
				$empty_action[$empty_opt] = $empty_alt;
			} else {
				$empty_action[$empty_opt] = $empty_default;
			}
		}
		if ( isset( $view_settings['dps']['empty_multi_select'] ) && $view_settings['dps']['empty_multi_select'] == $empty_alt ) {
			$empty_action['multi-select'] = $empty_alt;
		} else {
			$empty_action['multi-select'] = $empty_default;
		}
	}
	
	if ( $this_tree_ground == $ancestor_type ) {
	//	$this_type_parent_classes[] = 'js-wpv-post-relationship-real-parent';
		$this_type_parent_classes[] = 'js-wpv-filter-trigger';
	} else {
		$this_type_parent_classes[] = 'js-wpv-post-relationship-update';
	}
	
	if ( $this_tree_roof == $ancestor_type ) {
		$values_to_prepare = array();
		// Adjust query for WPML support
		$wpml_join = $wpml_where = "";
		if (
			isset( $sitepress ) 
			&& function_exists( 'icl_object_id' )
		) {
			$current_pt_translatable = $sitepress->is_translated_post_type( $ancestor_type );
			if ( $current_pt_translatable ) {
				$wpml_current_language = $sitepress->get_current_language();
				$wpml_join = " JOIN {$wpdb->prefix}icl_translations t ";
				$wpml_where = " AND p.ID = t.element_id AND t.language_code = %s ";
				$values_to_prepare[] = $wpml_current_language;
			}
		}
		$values_to_prepare[] = $ancestor_type;
		$pa_results = $wpdb->get_results(
			$wpdb->prepare(
				"SELECT p.ID, p.post_title
				FROM {$wpdb->posts} p {$wpml_join}
				WHERE p.post_status = 'publish' 
				{$wpml_where} 
				AND p.post_type = %s 
				ORDER BY p.{$orderby} {$order}",
				$values_to_prepare
			)
		);
	} else {
		$aux_position_array = array_keys( $ancestor_tree_array, $ancestor_type );
		if ( count( $aux_position_array ) > 1 ) {
			return __( 'There seems to be some kind of infinite loop happening.', 'wpv-views' );
		}
		$this_type_parents = array_slice( $ancestor_tree_array, 0, $aux_position_array[0] );
		foreach ( $this_type_parents as $ttp_item )  {
			$this_type_parent_classes[] = 'js-wpv-' . $ttp_item . '-watch';
		}
		
		$this_parent_parents = array();
		$this_parent_parents = wpcf_pr_get_belongs( $ancestor_type );
		if ( $this_parent_parents != false && is_array( $this_parent_parents ) ) {
			$this_parent_parents_array = array_merge( array_values( array_keys( $this_parent_parents ) ) );
		}
		
		$real_influencer_array = array_intersect( $this_parent_parents_array, $this_type_parents );
		$query_here = array();
		$query_here['posts_per_page'] = -1;
		$query_here['paged'] = 1;
		$query_here['offset'] = 0;
		$query_here['fields'] = 'ids';
		$query_here['post_type'] = $ancestor_type;
		foreach ( $real_influencer_array as $real_influencer ) {
			if ( isset( $_GET[$url_param . '-' . $real_influencer] ) && !empty( $_GET[$url_param . '-' . $real_influencer] ) && $_GET[$url_param . '-' . $real_influencer] != array( 0 ) ) {
				$query_here['meta_query'][] = array(
					'key' => '_wpcf_belongs_' . $real_influencer . '_id',
					'value' => $_GET[$url_param . '-' . $real_influencer]
				);
			}
		}
		if ( isset( $query_here['meta_query'] ) ) {
			$query_here['meta_query']['relation'] = 'AND';
			$aux_relationship_query = new WP_Query( $query_here );
			if ( 
				is_array( $aux_relationship_query->posts ) 
				&& count( $aux_relationship_query->posts ) 
			) {
				// If there are posts with those requirements, get their ID and post_title
				// We do not really need sanitization here, as $aux_relationship_query->posts only contains IDs come from the database, but still
				$values_to_prepare = array();
				$aux_rel_count = count( $aux_relationship_query->posts );
				$aux_rel_placeholders = array_fill( 0, $aux_rel_count, '%d' );
				foreach ( $aux_relationship_query->posts as $aux_rel_id ) {
					$values_to_prepare[] = $aux_rel_id;
				}
				$pa_results = $wpdb->get_results(
					$wpdb->prepare(
						"SELECT ID, post_title
						FROM {$wpdb->posts}
						WHERE post_status = 'publish' AND ID IN (" . implode( ",", $aux_rel_placeholders ) . ")
						ORDER BY {$orderby} {$order}",
						$values_to_prepare
					)
				);
			} else {
				//If there are no posts with those requeriments, render no posts
				$pa_results = array();
			}
		} else {
			$pa_results = array();
		}
	}
	//$pa_results = $wpdb->get_results( "SELECT ID, post_title FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_type = '{$ancestor_type}'" );
	// Render different controls based on the $type attribute
	switch ( $type ) {
		case 'select':
		case 'multi-select':
			// Add the default value to the top of the options if $type is select, with a 0 value
			$options = array();
			if ( $type == 'select' ) {
				if ( empty( $default_label ) ) {
					$options[''] = 0;
				} else {
					$options[$default_label] = 0;
				}
			}
			// Create the basic $element that will hold the wpv_form_control attributes
			$element = array( 'field' => array(
							'#type' => 'select',
							'#attributes' => array( 'style' => $style, 'class' => $class . ' ', 'data-currentposttype' => $ancestor_type ),
							'#inline' => true
					)
			);
			// Build the name, id and default values depending whether we are dealing with a real parent or not
			$element['field']['#default_value'] = array( 0 );
			if ( $ancestor_type == $this_tree_ground ) {
				$element['field']['#name'] = $url_param . '[]';
				$element['field']['#id'] = 'wpv_control_' . $type . '_' . $url_param;
				if ( isset( $_GET[$url_param] ) ) {
					$element['field']['#default_value'] = $_GET[$url_param];
				}
			} else {
				$element['field']['#name'] = $url_param . '-' . $ancestor_type . '[]';
				$element['field']['#id'] = 'wpv_control_' . $type . '_' . $url_param . '_' . $ancestor_type;
				if ( isset( $_GET[$url_param . '-' . $ancestor_type] ) ) {
					$element['field']['#default_value'] = $_GET[$url_param . '-' . $ancestor_type];
				}
			}
			// Security check: this must always be an array!
			if ( ! is_array( $element['field']['#default_value'] ) ) {
				$element['field']['#default_value'] = array( $element['field']['#default_value'] );
			}
			// Loop through the posts and add them as options like post_title => ID
			foreach ( $pa_results as $pa_item ) {
				
				$options[$pa_item->post_title] = array(
					'#title' => $pa_item->post_title,
					'#value' => $pa_item->ID,
					'#inline' => true,
					'#after' => '<br />'
				);
				// Dependant stuf
				if ( $this_tree_ground == $ancestor_type ) {
					if ( $format ) {
						$display_value_formatted_name = str_replace( '%%NAME%%', $options[$pa_item->post_title]['#title'], $format );
						$options[$pa_item->post_title]['#title'] = $display_value_formatted_name;
					}
					if ( $dependant || $counters  ) {
						$val = $pa_item->ID;
						$this_query = $WP_Views->get_query();
						if ( isset( $_GET[$url_param] ) && is_array( $_GET[$url_param] ) && in_array( $val, $_GET[$url_param] ) && is_object( $this_query ) && !$counters ) {
							$this_checker = $this_query->found_posts;
						} else {
							$meta_criteria_to_filter = array( '_wpcf_belongs_' . $ancestor_type . '_id' => array( $val ) );
							$data = array();
							$data['list'] = $wpv_data_cache['post_meta'];
							$data['args'] = $meta_criteria_to_filter;
							$data['kind'] = '';
							$data['comparator'] = 'equal';
							$data['filter_full_list'] = $filter_full_list;
							if ( $counters ) {
								$data['count_matches'] = true;
							}
							$this_checker = wpv_list_filter_checker( $data );
						}
						if ( $counters ) {
							$display_value_formatted_counter = $options[$pa_item->post_title]['#title'];
							$display_value_formatted_counter = str_replace( '%%COUNT%%', $this_checker, $display_value_formatted_counter );
							$options[$pa_item->post_title]['#title'] = $display_value_formatted_counter;
						}
						if ( !$this_checker && !in_array( $pa_item->ID, $element['field']['#default_value'] ) && $dependant ) {
							$options[$pa_item->post_title]['#disable'] = 'true';
							$options[$pa_item->post_title]['#labelclass'] = 'wpv-parametric-disabled';
							if ( isset( $empty_action[$type] ) && $empty_action[$type] == 'hide' ) {
								unset( $options[$pa_item->post_title] );
							}
						}
					}
				}
			}
			$element['field']['#options'] = $options;
			// If there are no options and is multi-select, break NOTE this break is for hide, maybe disable, we will see
			if ( $type == 'multi-select' && count( $options ) == 0 ) {
			//	break;
			}
			// Add classnames js-wpv-{slug}-watch for each post type slug in any tree that is ancestor of the current one, to be able to act on their changes
			if ( count( $this_type_parent_classes ) ) {
				$element['field']['#attributes']['class'] .= implode( ' ', $this_type_parent_classes );
			}
			// If there is only one option for select or none for multi-select, disable this form control NOTE review this
			if ( count( $options ) == 1 && $type == 'select' ) {
				$element['field']['#attributes']['disabled'] = 'disabled';
			}
			// If $type is multi-select, use it
			if ( $type == 'multi-select' ) {
				$element['field']['#multiple'] = 'multiple';
			}
			// Create the form control and add it to the $returned_value
			$return .= wpv_form_control( $element );
			break;
		case 'checkboxes':
			// If there are no options, break
			if ( count( $pa_results ) == 0 ) {
				$options = array();
			}
			// Create the basic $element that will hold the wpv_form_control attributes
			$element = array( 'field' => array(
						'#type' => $type,
						'#attributes' => array( 'style' => $style, 'class' => $class ),
						'#inline' => true,
						'#before' => '<div class="wpcf-checkboxes-grou">', //we need to wrap them for js purposes
						'#after' => '</div>'
			) );
			// Build the name, id and default values depending whether we are dealing with a real parent or not
			$element['field']['#default_value'] = array( -1 );
			if ( $ancestor_type == $this_tree_ground ) {
				$checkbox_url_param = $url_param . '[]';
				if ( isset( $_GET[$url_param] ) ) {
					$element['field']['#default_value'] = $_GET[$url_param];
				}
				$element['field']['#name'] = $url_param . '[]';
				$element['field']['#id'] = 'wpv_control_' . $type . '_' . $url_param;
			} else {
				$checkbox_url_param = $url_param . '-' . $ancestor_type . '[]';
				if ( isset( $_GET[$url_param . '-' . $ancestor_type] ) ) {
					$element['field']['#default_value'] = $_GET[$url_param . '-' . $ancestor_type];
				}
				$element['field']['#name'] = $url_param . '-' . $ancestor_type . '[]';
				$element['field']['#id'] = 'wpv_control_' . $type . '_' . $url_param . '_' . $ancestor_type;
			}
			// Security check: this must always be an array!
			if ( ! is_array( $element['field']['#default_value'] ) ) {
				$element['field']['#default_value'] = array( $element['field']['#default_value'] );
			}
			// Add classnames js-wpv-{slug}-watch for each post type slug in any tree that is ancestor of the current one, to be able to act on their changes
			$checkboxes_classes = '';
			if ( count( $this_type_parent_classes ) ) {
				$checkboxes_classes = implode( ' ', $this_type_parent_classes );
			}
			// Loop through the posts and add them as options
			foreach ( $pa_results as $pa_item ) {
				$options[$pa_item->ID]['#name'] = $checkbox_url_param;
				$options[$pa_item->ID]['#title'] = $pa_item->post_title;
				$options[$pa_item->ID]['#value'] = $pa_item->ID;
				$options[$pa_item->ID]['#default_value'] = in_array( $pa_item->ID, $element['field']['#default_value'] ); // set default using option titles too
				$options[$pa_item->ID]['#inline'] = true;
				$options[$pa_item->ID]['#after'] = '&nbsp;&nbsp;';
				$options[$pa_item->ID]['#attributes']['data-currentposttype'] = $ancestor_type;
				$options[$pa_item->ID]['#attributes']['data-triggerer'] = 'rel-relationship';
                $options[$pa_item->ID]['#attributes']['style'] = $style;
                $options[$pa_item->ID]['#attributes']['class'] = $class;
				if ( !empty( $checkboxes_classes ) ) {
					$options[$pa_item->ID]['#attributes']['class'] .= ' ' . $checkboxes_classes;
				}
                $options[$pa_item->ID]['#labelclass'] = $label_class;
                $options[$pa_item->ID]['#labelstyle'] = $label_style;
				// Dependant stuff
				if ( $this_tree_ground == $ancestor_type ) {
					if ( $format ) {
						$display_value_formatted_name = str_replace( '%%NAME%%', $options[$pa_item->ID]['#title'], $format );
						$options[$pa_item->ID]['#title'] = $display_value_formatted_name;
					}
					if ( $dependant || $counters  ) {
						$val = $pa_item->ID;
						$this_query = $WP_Views->get_query();
						if ( isset( $_GET[$url_param] ) && is_array( $_GET[$url_param] ) && in_array( $val, $_GET[$url_param] ) && is_object( $this_query ) && !$counters ) {
							$this_checker = $this_query->found_posts;
						} else {
							$meta_criteria_to_filter = array( '_wpcf_belongs_' . $ancestor_type . '_id' => array( $val ) );
							$data = array();
							$data['list'] = $wpv_data_cache['post_meta'];
							$data['args'] = $meta_criteria_to_filter;
							$data['kind'] = '';
							$data['comparator'] = 'equal';
							if ( $counters ) {
								$data['count_matches'] = true;
							}
							$data['filter_full_list'] = $filter_full_list;
							$this_checker = wpv_list_filter_checker( $data );
						}
						if ( $counters ) {
							$display_value_formatted_counter = $options[$pa_item->ID]['#title'];
							$display_value_formatted_counter = str_replace( '%%COUNT%%', $this_checker, $display_value_formatted_counter );
							$options[$pa_item->ID]['#title'] = $display_value_formatted_counter;
						}
						if ( !$this_checker && !in_array( $pa_item->ID, $element['field']['#default_value'] ) && $dependant ) {
							$options[$pa_item->ID]['#attributes']['#disabled'] = 'true';
							$options[$pa_item->ID]['#labelclass'] .= ' wpv-parametric-disabled';
							if ( isset( $empty_action['checkboxes'] ) && $empty_action['checkboxes'] == 'hide' ) {
								unset( $options[$pa_item->ID] );
							}
						}
					}
				}
			}
			$element['field']['#options'] = $options;
			// Calculate the control
			$return .= wpv_form_control( $element );
			break;
		case 'radio':
		case 'radios':
			// Create the basic $element that will hold the wpv_form_control attributes
			$element = array( 'field' => array(
							'#type' => 'radios',
							'#attributes' => array( 'style' => $style, 'class' => $class, 'data-currentposttype' => $ancestor_type, 'data-triggerer' => 'rel-relationship' ),
							'#inline' => true
						)
			);
			// If there are no options, break
			if ( count( $pa_results ) == 0 ) {
				$options = array();
			}
			if ( !empty( $default_label ) ) {
				$options[$default_label] = array(
					'#title' => $default_label,
					'#value' => 0,
					'#inline' => true,
					'#after' => '<br />'
				);
				if ( 
					$this_tree_ground == $ancestor_type 
					&& $dependant 
					&& count( $pa_results ) == 0 
					&& (
						! isset( $_GET[$url_param] ) 
						|| $_GET[$url_param] != '' 
					)
				) {
					$options[$default_label]['#disable'] = 'true';
					$options[$default_label]['#labelclass'] = ' wpv-parametric-disabled';
				}
			}
			// Build the name, id and default values depending whether we are dealing with a real parent or not
			$element['field']['#default_value'] = 0;
			if ( $ancestor_type == $this_tree_ground ) {
				$element['field']['#name'] = $url_param;
				$element['field']['#id'] = 'wpv_control_' . $type . '_' . $url_param;
				if ( 
					isset( $_GET[$url_param] ) 
					&& $_GET[$url_param] != 0 
				) {
					$element['field']['#default_value'] = $_GET[$url_param];
				}
			} else {
				$element['field']['#name'] = $url_param . '-' . $ancestor_type;
				$element['field']['#id'] = 'wpv_control_' . $type . '_' . $url_param . '_' . $ancestor_type;
				if ( 
					isset( $_GET[$url_param . '-' . $ancestor_type] ) 
					&& $_GET[$url_param . '-' . $ancestor_type] != 0 
				) {
					$element['field']['#default_value'] = $_GET[$url_param . '-' . $ancestor_type];
				}
			}
			// Security check: this must always be a string!
			if ( is_array( $element['field']['#default_value'] ) ) {
				$element['field']['#default_value'] = reset( $element['field']['#default_value'] );
			}
			// Loop through the posts and add them as options like post_title => ID
			foreach ( $pa_results as $pa_item ) {
				
				$options[$pa_item->post_title] = array(
					'#title' => $pa_item->post_title,
					'#value' => $pa_item->ID,
					'#inline' => true,
					'#after' => '<br />'
				);
                $options[$pa_item->post_title]['#labelclass'] = $label_class;
                $options[$pa_item->post_title]['#labelstyle'] = $label_style;
				// Dependant stuf
				if ( $this_tree_ground == $ancestor_type ) {
					if ( $format ) {
						$display_value_formatted_name = str_replace( '%%NAME%%', $options[$pa_item->post_title]['#title'], $format );
						$options[$pa_item->post_title]['#title'] = $display_value_formatted_name;
					}
					if ( $dependant || $counters ) {
						$val = $pa_item->ID;
						$this_query = $WP_Views->get_query();
						if ( isset( $_GET[$url_param] ) && !empty( $_GET[$url_param] ) && $val == esc_attr( $_GET[$url_param] ) && is_object( $this_query ) && !$counters ) {
							$this_checker = $this_query->found_posts;
						} else {
							$meta_criteria_to_filter = array( '_wpcf_belongs_' . $ancestor_type . '_id' => array( $val ) );
							$data = array();
							$data['list'] = $wpv_data_cache['post_meta'];
							$data['args'] = $meta_criteria_to_filter;
							$data['kind'] = '';
							$data['comparator'] = 'equal';
							if ( $counters ) {
								$data['count_matches'] = true;
							}
							$data['filter_full_list'] = $filter_full_list;
							$this_checker = wpv_list_filter_checker( $data );
						}
						if ( $counters ) {
							$display_value_formatted_counter = $options[$pa_item->post_title]['#title'];
							$display_value_formatted_counter = str_replace( '%%COUNT%%', $this_checker, $display_value_formatted_counter );
							$options[$pa_item->post_title]['#title'] = $display_value_formatted_counter;
						}
						if ( !$this_checker && $pa_item->ID != $element['field']['#default_value'] && $dependant ) {
							$options[$pa_item->post_title]['#disable'] = 'true';
							$options[$pa_item->post_title]['#labelclass'] .= ' wpv-parametric-disabled';
							if ( isset( $empty_action['radios'] ) && $empty_action['radios'] == 'hide' ) {
								unset( $options[$pa_item->post_title] );
							}
						}
					}
				}
			}
			$element['field']['#options'] = $options;
			// Add classnames js-wpv-{slug}-watch for each post type slug in any tree that is ancestor of the current one, to be able to act on their changes
			if ( count( $this_type_parent_classes ) ) {
				$element['field']['#attributes']['class'] .= ' '. implode( ' ', $this_type_parent_classes );
			}
			// If there is only one option, disable this form control
			//This is not really needed,asin this case we are breaking above TODO review this
			if ( count( $options ) == 0 ) {
				$element['field']['#attributes']['disabled'] = 'disabled';
			}
			// Calculate the control
			$return .= wpv_form_control( $element );
			break;
		default:
			break;
	}
	return $return;
}
コード例 #4
0
    function show_hidden_custom_fields($options)
    {
        if (isset($options['wpv_show_hidden_fields']) && $options['wpv_show_hidden_fields'] != '') {
            $defaults = explode(',', $options['wpv_show_hidden_fields']);
        } else {
            $defaults = array();
        }
        ?>

        <div class="wpv-setting-container wpv-settings-hidden-cf">

            <div class="wpv-settings-header">
                <h3><?php 
        _e('Hidden custom fields', 'wpv-views');
        ?>
</h3>
            </div>

            <div class="wpv-setting">

                <div class="js-cf-summary">
                    <?php 
        $cf_exists = false;
        if (sizeof($defaults) > 0) {
            $cf_exists = true;
        }
        ?>
                    <p class="js-cf-exists-message <?php 
        echo $cf_exists ? '' : 'hidden';
        ?>
">
                        <?php 
        _e('The following private custom fields are showing in the Views GUI:', 'wpv-views');
        ?>
                    </p>
                    <p class="js-no-cf-message <?php 
        echo $cf_exists ? 'hidden' : '';
        ?>
">
                        <?php 
        _e('No private custom fields are showing in the Views GUI.', 'wpv-views');
        ?>
                    </p>
                    <ul class="js-selected-cf-list <?php 
        echo $cf_exists ? '' : 'hidden';
        ?>
">
                    <?php 
        foreach ($defaults as $cf) {
            ?>
                        <li><?php 
            echo $cf;
            ?>
</li>
                    <?php 
        }
        ?>
                    </ul>

                    <p>
                        <button class="button-secondary js-show-cf-list" type="button"><?php 
        _e('Edit', 'wpv-views');
        ?>
</button>
                        <span class="toolset-alert toolset-alert-success hidden js-cf-update-message">
                            <?php 
        _e('Settings saved', 'wpv-views');
        ?>
                        </span>
                    </p>

                </div>

                <div class="js-cf-toggle hidden">

    				<?php 
        $meta_keys = $this->get_meta_keys(true);
        ?>
                    <ul class="js-all-cf-list cf-list">
    				<?php 
        foreach ($meta_keys as $field) {
            ?>
    					<?php 
            if (strpos($field, '_') === 0) {
                ?>
                            <?php 
                $options[$field]['#default_value'] = in_array($field, $defaults);
                $element = wpv_form_control(array('field' => array('#type' => 'checkbox', '#name' => 'wpv_show_hidden_fields[]', '#attributes' => array('style' => ''), '#inline' => true, '#title' => $field, '#value' => $field, '#before' => '', '#after' => '', '#default_value' => in_array($field, $defaults))));
                ?>
                            <li><?php 
                echo $element;
                ?>
</li>
                        <?php 
            }
            ?>
    				<?php 
        }
        ?>
				<?php 
        wp_nonce_field('wpv_show_hidden_custom_fields_nonce', 'wpv_show_hidden_custom_fields_nonce');
        ?>
                    </ul>

    				<p class="update-button-wrap">
                        <span class="js-cf-spinner spinner hidden"></span>
                        <button class="button-secondary js-hide-cf-list"><?php 
        _e('Cancel', 'wpv-views');
        ?>
</button>
                        <button class="button-primary js-save-cf-list"><?php 
        _e('Save', 'wpv-views');
        ?>
</button>
                    </p>

                </div>
            </div>
        </div>

		<?php 
    }
コード例 #5
0
function wpv_pagination_admin($view_settings)
{
    global $post;
    $rollover_effects = array('fade' => __('Fade', 'wpv-views'), 'fadefast' => __('Fade fast', 'wpv-views'), 'fadeslow' => __('Fade slow', 'wpv-views'), 'slideleft' => __('Slide Left', 'wpv-views'), 'slideright' => __('Slide Right', 'wpv-views'), 'slideup' => __('Slide Up', 'wpv-views'), 'slidedown' => __('Slide Down', 'wpv-views'));
    wp_nonce_field('wpv_pagination_nonce', 'wpv_pagination_nonce');
    ?>
        <?php 
    if (!isset($view_settings['ajax'])) {
        ?>
        <div id="wpv_pagination_admin">
        <?php 
    }
    ?>
            <div id="wpv_pagination_admin_show">
                <p>
                <?php 
    if ($view_settings['pagination']['mode'] == 'paged') {
        ?>
                <?php 
        if ($view_settings['pagination'][0] == 'disable') {
            echo __('Show <strong>all</strong> items. Pagination is disabled.', 'wpv-views');
        } else {
            echo sprintf(__('Show <strong>%s</strong> items per page.', 'wpv-views'), $view_settings['posts_per_page']);
            $controls = '';
            if (isset($view_settings['include_page_selector_control']) && $view_settings['include_page_selector_control']) {
                switch ($view_settings['pagination']['page_selector_control_type']) {
                    case 'drop_down':
                        $controls .= __('Show <strong>page selector</strong> drop down ', 'wpv-views');
                        break;
                    case 'link':
                        $controls .= __('Show <strong>page selector</strong> links ', 'wpv-views');
                        break;
                }
            }
            if (isset($view_settings['include_prev_next_page_controls']) && $view_settings['include_prev_next_page_controls']) {
                if ($controls == '') {
                    $controls .= __('Show <strong>previous</strong> and <strong>next</strong> page controls.', 'wpv-views');
                } else {
                    $controls .= __('and <strong>previous</strong> and <strong>next</strong> page controls.', 'wpv-views');
                }
            }
            if ($view_settings['ajax_pagination'][0] == 'enable') {
                if (isset($view_settings['ajax_pagination']['style'])) {
                    $effect = array('fade' => __('Fade', 'wpv-views'), 'fadefast' => __('Fade fast', 'wpv-views'), 'fadeslow' => __('Fade slow', 'wpv-views'), 'slideh' => __('Slide horizontally', 'wpv-views'), 'slidev' => __('Slide vertically', 'wpv-views'));
                    $effect = isset($effect[$view_settings['ajax_pagination']['style']]) ? $effect[$view_settings['ajax_pagination']['style']] : $effect['fade'];
                    $controls .= sprintf(__(' Use <strong>AJAX</strong> to update page content using <strong>%s</strong> transition effect.', 'wpv-views'), $effect);
                } else {
                    $controls .= __(' Use <strong>AJAX</strong> to update page content.', 'wpv-views');
                }
            }
            echo ' ' . $controls;
        }
    } else {
        if ($view_settings['pagination']['mode'] == 'rollover') {
            echo sprintf(__('<strong>Auto transition:</strong> Display <strong>%s</strong> items per page for <strong>%s</strong> seconds and then <strong>%s</strong> to the next items.', 'wpv-views'), strval($view_settings['rollover']['posts_per_page']), strval($view_settings['rollover']['speed']), $rollover_effects[strval($view_settings['rollover']['effect'])]);
        }
    }
    ?>
                <input class="button-secondary" type="button" value="<?php 
    echo __('Edit', 'wpv-views');
    ?>
" name="<?php 
    echo __('Edit', 'wpv-views');
    ?>
" onclick="wpv_pagination_edit()"/>
                </p>
            </div>
            <div id="wpv_pagination_admin_edit" style="background:<?php 
    echo WPV_EDIT_BACKGROUND;
    ?>
;display:none">
                <div style="margin:20px;">
            
                    <br />
                    <p>
                        <?php 
    $pagination_default_mode = $view_settings['pagination']['mode'];
    if ($view_settings['pagination'][0] == 'disable' && $view_settings['pagination']['mode'] !== 'rollover') {
        $pagination_default_mode = 'none';
    }
    $pagination_form = array();
    $pagination_form['select_radios'] = array('#type' => 'radios', '#name' => '_wpv_settings_dummy_mode', '#default_value' => $pagination_default_mode, '#options' => array('none' => array('#title' => __('No pagination', 'wpv-views'), '#description' => __('All query results will display.', 'wpv-views'), '#value' => 'none', '#attributes' => array('onclick' => "jQuery('.wpv_pagination_mode_toggle').hide();  jQuery('.wpv_pagination_enabled').slideUp(); jQuery('#_wpv_settings_dummy_pagination').val('disable'); jQuery('#_wpv_settings_dummy_mode').val('paged');"), '#after' => '<br />'), 'paged' => array('#title' => __('Pagination enabled with manual transition', 'wpv-views'), '#description' => __('The query results will display in pages, which visitors will switch.', 'wpv-views'), '#value' => 'paged', '#attributes' => array('onclick' => "jQuery('.wpv_pagination_mode_toggle').hide();jQuery('#wpv_pagination_mode_'+jQuery(this).val()).show(); jQuery('.wpv_pagination_enabled').slideDown(); jQuery('#_wpv_settings_dummy_pagination').val('enable'); jQuery('#_wpv_settings_dummy_mode').val('paged'); if (jQuery('input[name=_wpv_settings\\\\[ajax_pagination\\\\]\\\\[\\\\]]:checked').val() == 'disable') { jQuery('.wpv_pagination_ajax_toggle').slideUp(); }"), '#after' => '<br />'), 'rollover' => array('#title' => __('Pagination enabled with automatic transition', 'wpv-views'), '#description' => __('The query results will display in pages, which will switch automatically (good for sliders).', 'wpv-views'), '#value' => 'rollover', '#attributes' => array('onclick' => "jQuery('.wpv_pagination_mode_toggle').hide();jQuery('#wpv_pagination_mode_'+jQuery(this).val()).show(); jQuery('.wpv_pagination_enabled').slideDown(); jQuery('#_wpv_settings_dummy_pagination').val('enable'); jQuery('#_wpv_settings_dummy_mode').val('rollover');"), '#after' => '<br /><input id="_wpv_settings_dummy_pagination" type="hidden" name="_wpv_settings[pagination][]" value="' . $view_settings['pagination'][0] . '" /><input id="_wpv_settings_dummy_mode" type="hidden" name="_wpv_settings[pagination][mode]" value="' . $view_settings['pagination']['mode'] . '" />')));
    echo wpv_form_control($pagination_form);
    ?>
                    </p>
                    <div id="wpv_pagination_mode_paged" class="wpv_pagination_mode_toggle"<?php 
    if ($view_settings['pagination']['mode'] != 'paged') {
        echo ' style="display: none;"';
    }
    ?>
>
                            <div class="wpv_pagination_enabled"<?php 
    echo $view_settings['pagination'][0] == 'disable' && $view_settings['pagination']['mode'] != 'rollover' ? ' style="display:none;"' : '';
    ?>
>
                                <div style="margin-left:20px;">
                            <?php 
    _e('Number of items per page:', 'wpv-views');
    ?>
                            <select name="_wpv_settings[posts_per_page]">
                                <?php 
    for ($i = 1; $i < 50; $i++) {
        $selected = $view_settings['posts_per_page'] == (string) $i ? ' selected="selected"' : '';
        echo '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
    }
    ?>
                            </select>

                            <p>
                            <?php 
    $checked = isset($view_settings['include_page_selector_control']) && $view_settings['include_page_selector_control'] ? ' checked="checked"' : '';
    ?>
                            <label><input id="_wpv_settings_include_page_selector_control" type="checkbox" name="_wpv_settings[include_page_selector_control]"<?php 
    echo $checked;
    ?>
 />&nbsp;<?php 
    _e('Include a page selector', 'wpv-views');
    ?>
</label>
                            <select id="_wpv_settings_page_selector_control_type" name="_wpv_settings[pagination][page_selector_control_type]">
                                <option value="drop_down"<?php 
    if ($view_settings['pagination']['page_selector_control_type'] == 'drop_down') {
        echo ' selected="selected"';
    }
    ?>
><?php 
    _e('Drop down', 'wpv-views');
    ?>
</option>
                                <option value="link"<?php 
    if ($view_settings['pagination']['page_selector_control_type'] == 'link') {
        echo ' selected="selected"';
    }
    ?>
><?php 
    _e('Links', 'wpv-views');
    ?>
</option>
                            </select>
                            <br />
                            <?php 
    $checked = isset($view_settings['include_prev_next_page_controls']) && $view_settings['include_prev_next_page_controls'] ? ' checked="checked"' : '';
    ?>
                            <label><input id="_wpv_settings_include_prev_next_page_controls" type="checkbox" name="_wpv_settings[include_prev_next_page_controls]"<?php 
    echo $checked;
    ?>
 />&nbsp;<?php 
    _e('Include next page and previous page controls', 'wpv-views');
    ?>
</label>
                            </p>
                        </div>
                        <p>
                        <legend style="margin-bottom:5px"><strong><?php 
    _e('AJAX:', 'wpv-views');
    ?>
</strong></legend>
                        </p>
                        <div style="margin-left:20px;">
                            <ul>
                                <?php 
    $checked = $view_settings['ajax_pagination'][0] == 'disable' ? ' checked="checked"' : '';
    ?>
                                <li><label><input type="radio"  value="disable" name="_wpv_settings[ajax_pagination][]" onclick="jQuery('.wpv_pagination_ajax_toggle').slideUp();"<?php 
    echo $checked;
    ?>
 />&nbsp;<?php 
    _e('Pagination updates the entire page', 'wpv-views');
    ?>
</label></li>
                                <?php 
    $checked = $view_settings['ajax_pagination'][0] == 'enable' ? ' checked="checked"' : '';
    ?>
                                <li><label><input type="radio"  value="enable" name="_wpv_settings[ajax_pagination][]" onclick="jQuery('.wpv_pagination_ajax_toggle').slideDown();"<?php 
    echo $checked;
    ?>
 />&nbsp;<?php 
    _e('Pagination updates only the view (use AJAX)', 'wpv-views');
    ?>
</label></li>
                                <li class="wpv_pagination_ajax_toggle"<?php 
    if ($view_settings['ajax_pagination'][0] == 'disable') {
        echo ' style="display:none;"';
    }
    ?>
><label><select name="_wpv_settings[ajax_pagination][style]">
                                                <option value="fade"<?php 
    if ($view_settings['ajax_pagination']['style'] == 'fade') {
        echo ' selected="selected"';
    }
    ?>
><?php 
    _e('Fade', 'wpv-views');
    ?>
</option>
                                                <option value="fadefast"<?php 
    if ($view_settings['ajax_pagination']['style'] == 'fadefast') {
        echo ' selected="selected"';
    }
    ?>
><?php 
    _e('Fade fast', 'wpv-views');
    ?>
</option>
                                                <option value="fadeslow"<?php 
    if ($view_settings['ajax_pagination']['style'] == 'fadeslow') {
        echo ' selected="selected"';
    }
    ?>
><?php 
    _e('Fade slow', 'wpv-views');
    ?>
</option>
                                                <option value="slideh"<?php 
    if ($view_settings['ajax_pagination']['style'] == 'slideh') {
        echo ' selected="selected"';
    }
    ?>
><?php 
    _e('Slide horizontally', 'wpv-views');
    ?>
</option>
                                                <option value="slidev"<?php 
    if ($view_settings['ajax_pagination']['style'] == 'slidev') {
        echo ' selected="selected"';
    }
    ?>
><?php 
    _e('Slide vertically', 'wpv-views');
    ?>
</option>
                                            </select><?php 
    _e('Transition effect', 'wpv-views');
    ?>
</label></li>
                                            <li class="wpv_pagination_ajax_toggle"<?php 
    if ($view_settings['ajax_pagination'][0] == 'disable') {
        echo ' style="display:none;"';
    }
    ?>
>
                                                <label><input type="checkbox" name="_wpv_settings[pagination][preload_images]" value="1"<?php 
    if ($view_settings['pagination']['preload_images']) {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('Preload images before transition', 'wpv-views');
    ?>
</label>
                                            </li>
                                                
                            </ul>
                        </div>
                    </div><!-- .wpv_pagination_enabled -->
                        </div>
                    <div id="wpv_pagination_mode_rollover" class="wpv_pagination_mode_toggle" style="margin-left:20px;<?php 
    if ($view_settings['pagination']['mode'] != 'rollover') {
        echo ' display: none;';
    }
    ?>
">
                        <?php 
    _e('Number of items per page:', 'wpv-views');
    ?>
                            <select name="_wpv_settings[rollover][posts_per_page]">
                                <?php 
    for ($i = 1; $i < 50; $i++) {
        $selected = $view_settings['rollover']['posts_per_page'] == (string) $i ? ' selected="selected"' : '';
        echo '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
    }
    ?>
                            </select>
                        <br /><br />
                        <?php 
    _e('Show each page for:', 'wpv-views');
    ?>
                            <select name="_wpv_settings[rollover][speed]">
                                <?php 
    for ($i = 1; $i < 20; $i++) {
        $selected = $view_settings['rollover']['speed'] == (string) $i ? ' selected="selected"' : '';
        echo '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
    }
    ?>
                            </select>&nbsp;<?php 
    _e('seconds', 'wpv-views');
    ?>
                        <br /><br />
                        <?php 
    _e('Transition effect:', 'wpv-views');
    ?>
                            <select name="_wpv_settings[rollover][effect]">
                                <?php 
    foreach ($rollover_effects as $i => $title) {
        $selected = $view_settings['rollover']['effect'] == (string) $i ? ' selected="selected"' : '';
        echo '<option value="' . $i . '"' . $selected . '>' . $title . '</option>';
    }
    ?>
                            </select>
                        <br /><br />
                        <label><input type="checkbox" name="_wpv_settings[rollover][include_page_selector]" value="1"<?php 
    if ($view_settings['rollover']['include_page_selector']) {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('Include page selector links', 'wpv-views');
    ?>
</label>
                        <br />
                        <label><input type="checkbox" name="_wpv_settings[rollover][include_prev_next_page_controls]" value="1"<?php 
    if ($view_settings['rollover']['include_prev_next_page_controls']) {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('Include next page and previous page controls', 'wpv-views');
    ?>
</label>
                        <br />
                        <label><input type="checkbox" name="_wpv_settings[rollover][preload_images]" value="1"<?php 
    if ($view_settings['rollover']['preload_images']) {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('Preload images before transition', 'wpv-views');
    ?>
</label>
                        <br /><br />
                    </div>
                    <div style="margin:0 0 20px 20px;<?php 
    echo ($view_settings['pagination'][0] == 'disable' || $view_settings['ajax_pagination'][0] == 'disable') && $view_settings['pagination']['mode'] != 'rollover' ? 'display:none;' : '';
    ?>
" class="wpv_pagination_enabled wpv_pagination_ajax_toggle">
                        <label><input type="checkbox" name="_wpv_settings[pagination][cache_pages]" value="1"<?php 
    if ($view_settings['pagination']['cache_pages']) {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('Cache pages', 'wpv-views');
    ?>
</label><br />
                        <label><input type="checkbox" name="_wpv_settings[pagination][preload_pages]" value="1"<?php 
    if ($view_settings['pagination']['preload_pages']) {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('Pre-load the next and previous pages - avoids loading delays when users move between pages', 'wpv-views');
    ?>
</label>
                        <br /><br />
                        <label><input type="radio" onclick="jQuery('.wpv-spinner-selection').hide();jQuery('#wpv-spinner-default').show();" name="_wpv_settings[pagination][spinner]" value="default"<?php 
    if ($view_settings['pagination']['spinner'] == 'default') {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('Spinner graphics from Views', 'wpv-views');
    ?>
</label>
                        <div id="wpv-spinner-default" class="wpv-spinner-selection" style="margin-left: 20px;<?php 
    if ($view_settings['pagination']['spinner'] != 'default') {
        echo ' display:none;"';
    }
    ?>
">
                        <?php 
    foreach (glob(WPV_PATH_EMBEDDED . "/res/img/ajax-loader*") as $file) {
        $filename = WPV_URL_EMBEDDED . '/res/img/' . basename($file);
        $filename2 = WPV_URL . '/res/img/' . basename($file);
        ?>
                            <label><input type="radio" name="_wpv_settings[pagination][spinner_image]" value="<?php 
        echo $filename;
        ?>
"<?php 
        if ($view_settings['pagination']['spinner_image'] == $filename || $view_settings['pagination']['spinner_image'] == $filename2) {
            echo ' checked="checked"';
        }
        ?>
 />&nbsp;<img style="background-color: #FFFFFF;" src="<?php 
        echo $filename;
        ?>
" title="<?php 
        echo $filename;
        ?>
" /></label>&nbsp;&nbsp;
                        <?php 
    }
    ?>
                        </div>
                        <br />
                        <label><input type="radio" onclick="jQuery('.wpv-spinner-selection').hide();jQuery('#wpv-spinner-uploaded').show();" name="_wpv_settings[pagination][spinner]" value="uploaded"<?php 
    if ($view_settings['pagination']['spinner'] == 'uploaded') {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('My custom spinner graphics', 'wpv-views');
    ?>
</label>
                        <div id="wpv-spinner-uploaded" class="wpv-spinner-selection" style="margin-left: 20px;<?php 
    if ($view_settings['pagination']['spinner'] != 'uploaded') {
        echo ' display:none;';
    }
    ?>
">
                            <input id="wpv-pagination-spinner-image" type="textfield" name="_wpv_settings[pagination][spinner_image_uploaded]" value="<?php 
    echo $view_settings['pagination']['spinner_image_uploaded'];
    ?>
" />&nbsp;<a href="" class="button-secondary" onclick="tb_show('<?php 
    _e('Upload image');
    ?>
', 'media-upload.php?post_id=<?php 
    echo isset($post) && isset($post->ID) ? $post->ID : '';
    ?>
&type=image&wpv-pagination-spinner-media-insert=1&TB_iframe=true');return false;"><?php 
    _e('Upload Image');
    ?>
</a>
                            <br /><img id="wpv-pagination-spinner-image-preview" style="margin-top: 5px;" src="<?php 
    echo $view_settings['pagination']['spinner_image_uploaded'];
    ?>
" height="16" />
                        </div>
                        <br />
                        <label><input type="radio" onclick="jQuery('.wpv-spinner-selection').hide();"  name="_wpv_settings[pagination][spinner]" value="no"<?php 
    if ($view_settings['pagination']['spinner'] == 'no') {
        echo ' checked="checked"';
    }
    ?>
 />&nbsp;<?php 
    _e('No spinner graphics', 'wpv-views');
    ?>
</label>
                    </div>
<!--                    <div style="margin:0 0 20px 20px;<?php 
    echo ($view_settings['pagination'][0] == 'disable' || $view_settings['ajax_pagination'][0] == 'disable') && $view_settings['pagination']['mode'] != 'rollover' ? 'display:none;' : '';
    ?>
" class="wpv_pagination_enabled wpv_pagination_ajax_toggle">
                        <label><?php 
    _e('Javascript callback function on next slide', 'wpv-views');
    ?>
<br />
                        <input type="text" name="_wpv_settings[pagination][callback_next]" value="<?php 
    if (!empty($view_settings['pagination']['callback_next'])) {
        echo $view_settings['pagination']['callback_next'];
    }
    ?>
" />
                        </label>
                    </div>-->
                    <input class="button-primary" type="button" value="<?php 
    echo __('OK', 'wpv-views');
    ?>
" name="<?php 
    echo __('OK', 'wpv-views');
    ?>
" onclick="jQuery('html,body').animate({scrollTop:jQuery('#wpv_settings').offset().top-25}, 1500); wpv_pagination_edit_ok();"/>
                    <input class="button-secondary" type="button" value="<?php 
    echo __('Cancel', 'wpv-views');
    ?>
" name="<?php 
    echo __('Cancel', 'wpv-views');
    ?>
" onclick="jQuery('html,body').animate({scrollTop:jQuery('#wpv_settings').offset().top-25}, 1500); wpv_pagination_edit_cancel()"/>
                    <br />
                </div>
            </div>

        <?php 
    if (!isset($view_settings['ajax'])) {
        ?>
        </div>
            
        
            <script type="text/javascript">
                <?php 
        /* NOTE: we don't use _e() or __() to translate these.
              We use [wpml-string] shortcodes instead
           */
        ?>
                var page_x_of_n = "[wpml-string context=\"wpv-views\"]Showing page 1 of 9[/wpml-string]";
                var page_next = "[wpml-string context=\"wpv-views\"]Next[/wpml-string]";
                var page_previous = "[wpml-string context=\"wpv-views\"]Previous[/wpml-string]";
            </script>
        <?php 
    }
    ?>

    <?php 
}
コード例 #6
0
/**
 * 
 * Views-Shortcode: wpv-control
 *
 * Description: Add filters for View
 *
 * Parameters:
 * type: type of retrieved field layout (radio, checkbox, select, textfield, checkboxes, datepicker)
 * url_param: the URL parameter passed as an argument
 * values: Optional. a list of supplied values
 * display_values: Optional. A list of values to display for the corresponding values
 * auto_fill: Optional. When set to a "field-slug" the control will be populated with custom field values from the database.
 * auto_fill_default: Optional. Used to set the default, unselected, value of the control. eg Ignore or Don't care
 * auto_fill_sort: Optional. 'asc', 'desc', 'ascnum', 'descnum', 'none'. Defaults to ascending.
 * field: Optional. a Types field to retrieve values from
 * title: Optional. Use for the checkbox title
 * taxonomy: Optional. Use when a taxonomy control should be displayed.
 * default_label: Optional. Use when a taxonomy control should be displayed using select input type.
 * date_format: Optional. Used for a datepicker control
 *
 * Example usage:
 *
 * Link:
 * More details about this shortcode here: <a href="http://wp-types.com/documentation/wpv-control-fields-in-front-end-filters/" title="wpv-control – Displaying fields in front-end filters">http://wp-types.com/documentation/wpv-control-fields-in-front-end-filters/</a>
 *
 * Note:
 *
 */
function wpv_shortcode_wpv_control($atts)
{
    global $WP_Views;
    $aux_array = $WP_Views->view_used_ids;
    $view_name = get_post_field('post_name', end($aux_array));
    if (!isset($atts['url_param'])) {
        return __('The url_param is missing from the wpv-control shortcode argument.', 'wpv-views');
    }
    if ((!isset($atts['type']) || $atts == '') && !isset($atts['field'])) {
        return __('The "type" or "field" needs to be set in the wpv-control shortcode argument.', 'wpv-views');
    }
    extract(shortcode_atts(array('type' => '', 'values' => array(), 'display_values' => array(), 'field' => '', 'url_param' => '', 'title' => '', 'taxonomy' => '', 'taxonomy_orderby' => 'name', 'taxonomy_order' => 'ASC', 'format' => false, 'default_label' => '', 'hide_empty' => 'false', 'auto_fill' => '', 'auto_fill_default' => '', 'auto_fill_sort' => '', 'date_format' => '', 'default_date' => ''), $atts));
    if ($taxonomy != '') {
        // pass the new shortcode attribute $default_label
        $default_label = wpv_translate($url_param . '_default_label', $default_label, false, 'View ' . $view_name);
        return _wpv_render_taxonomy_control($taxonomy, $type, $url_param, $default_label, $taxonomy_orderby, $taxonomy_order, $format, $hide_empty);
    }
    $multi = '';
    $display_values_trans = false;
    if ($type == 'multi-select') {
        $type = 'select';
        $multi = 'multiple';
    }
    if ($auto_fill != '') {
        // See if we should handle types checkboxes
        $types_checkboxes_field = false;
        $auto_fill_default_trans = false;
        $display_values_traans = false;
        if (_wpv_is_field_of_type($auto_fill, 'checkboxes')) {
            if (!function_exists('wpcf_admin_fields_get_fields')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                }
            }
            if (function_exists('wpcf_admin_fields_get_fields')) {
                $fields = wpcf_admin_fields_get_fields();
                $field_name = substr($auto_fill, 5);
                if (isset($fields[$field_name])) {
                    $types_checkboxes_field = true;
                    $db_values = array();
                    $options = $fields[$field_name]['data']['options'];
                    foreach ($options as $field_key => $option) {
                        $db_values[] = $option['title'];
                        $display_text[$option['title']] = wpv_translate('field ' . $fields[$field_name]['id'] . ' option ' . $field_key . ' title', $option['title'], false, 'plugin Types');
                    }
                    switch (strtolower($auto_fill_sort)) {
                        case 'desc':
                            sort($db_values);
                            $db_values = array_reverse($db_values);
                            break;
                        case 'descnum':
                            sort($db_values, SORT_NUMERIC);
                            $db_values = array_reverse($db_values);
                            break;
                        case 'none':
                            break;
                        case 'ascnum':
                            sort($db_values, SORT_NUMERIC);
                            break;
                        default:
                            sort($db_values);
                            break;
                    }
                }
            }
        }
        if (!$types_checkboxes_field) {
            if (!function_exists('wpcf_admin_fields_get_fields')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                }
            }
            if (function_exists('wpcf_admin_fields_get_fields')) {
                $fields = wpcf_admin_fields_get_fields();
            }
            $field_name = substr($auto_fill, 5);
            if (isset($fields) && isset($fields[$field_name]) && isset($fields[$field_name]['data']['options'])) {
                $display_text = array();
                $options = $fields[$field_name]['data']['options'];
                if (isset($options['default'])) {
                    unset($options['default']);
                }
                // remove the default option from the array
                if (isset($fields[$field_name]['data']['display'])) {
                    $display_option = $fields[$field_name]['data']['display'];
                }
                foreach ($options as $field_key => $option) {
                    if (isset($option['value'])) {
                        $db_values[] = $option['value'];
                    }
                    if (isset($display_option) && 'value' == $display_option && isset($option['display_value'])) {
                        // $display_text[$option['value']] = $option['display_value']; // fill an array with the actual display values
                        $display_text[$option['value']] = wpv_translate('field ' . $fields[$field_name]['id'] . ' option ' . $field_key . ' title', $option['display_value'], false, 'plugin Types');
                    } else {
                        //$display_text[$option['value']] = $option['title'];
                        $display_text[$option['value']] = wpv_translate('field ' . $fields[$field_name]['id'] . ' option ' . $field_key . ' title', $option['title'], false, 'plugin Types');
                    }
                    if ($auto_fill_default != '') {
                        // translate the auto_fill_default option if needed, just when it's one of the existing options
                        $auto_fill_default = str_replace('\\,', ',', $auto_fill_default);
                        if ($auto_fill_default == $option['title']) {
                            $auto_fill_default = wpv_translate('field ' . $fields[$field_name]['id'] . ' option ' . $field_key . ' title', $option['title'], false, 'plugin Types');
                            $auto_fill_default_trans = true;
                        }
                        $auto_fill_default = str_replace(',', '\\,', $auto_fill_default);
                    }
                }
                switch (strtolower($auto_fill_sort)) {
                    case 'desc':
                        sort($db_values);
                        $db_values = array_reverse($db_values);
                        break;
                    case 'descnum':
                        sort($db_values, SORT_NUMERIC);
                        $db_values = array_reverse($db_values);
                        break;
                    case 'none':
                        break;
                    case 'ascnum':
                        sort($db_values, SORT_NUMERIC);
                        break;
                    default:
                        sort($db_values);
                        break;
                }
            } else {
                global $wpdb;
                switch (strtolower($auto_fill_sort)) {
                    case 'desc':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value DESC");
                        break;
                    case 'descnum':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value + 0 DESC");
                        break;
                    case 'none':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}'");
                        break;
                    case 'ascnum':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value + 0 ASC");
                        break;
                    default:
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value ASC");
                        break;
                }
            }
        }
        if ($auto_fill_default != '') {
            if (!$auto_fill_default_trans) {
                // translate the auto_fill_default option when it's not one of the existing options
                $auto_fill_default = str_replace('\\,', ',', $auto_fill_default);
                $auto_fill_default = wpv_translate($url_param . '_auto_fill_default', stripslashes($auto_fill_default), false, 'View ' . $view_name);
                $auto_fill_default = str_replace(',', '\\,', $auto_fill_default);
            }
            $values = '';
            $display_values = str_replace('\\,', '%comma%', $auto_fill_default);
            $first = false;
        } else {
            $values = '';
            $display_values = '';
            $first = true;
        }
        foreach ($db_values as $value) {
            if ($value) {
                if (!$first) {
                    $values .= ',';
                    $display_values .= ',';
                }
                $values .= str_replace(',', '%comma%', $value);
                if (isset($display_text[$value])) {
                    $display_values .= str_replace(',', '%comma%', $display_text[$value]);
                } else {
                    $display_values .= str_replace(',', '%comma%', $value);
                }
                $first = false;
            }
        }
    } else {
        if (!empty($display_values)) {
            $display_values_trans = true;
        }
    }
    $out = '';
    // Use when values attributes are defined (predefined values to list)
    if (!empty($values)) {
        $values_fix = str_replace('\\,', '%comma%', $values);
        //print_r($values_fix);
        $values_arr = explode(',', $values_fix);
        $values_arr = str_replace('%comma%', ',', $values_arr);
        if (!empty($display_values)) {
            $display_values = str_replace('\\,', '%comma%', $display_values);
            $display_values = explode(',', $display_values);
            $display_values = str_replace('%comma%', ',', $display_values);
            if ($display_values_trans) {
                $translated_values = array();
                foreach ($display_values as $index => $valuetrans) {
                    $translated_values[$index] = wpv_translate($url_param . '_display_values_' . ($index + 1), stripslashes($valuetrans), false, 'View ' . $view_name);
                }
                $display_values = $translated_values;
            }
        }
        $options = array();
        if (!in_array($type, array('radio', 'radios', 'select', 'checkboxes'))) {
            $type = 'select';
        }
        if ($type == 'radio') {
            $type = 'radios';
        }
        switch ($type) {
            case 'checkboxes':
                $defaults = array();
                $original_get = null;
                if (isset($auto_fill_default)) {
                    // check if the defaul value already exists and set the appropriate arrays and values
                    $num_auto_fill_default_display = array_count_values($display_values);
                    $auto_fill_default_trans = str_replace('\\,', ',', $auto_fill_default);
                    if (isset($num_auto_fill_default_display[$auto_fill_default_trans]) && $num_auto_fill_default_display[$auto_fill_default_trans] > 1 || in_array($auto_fill_default_trans, $values_arr)) {
                        // if the default value is an existing display value or stored value
                        $values_arr_def = array_shift($values_arr);
                        $display_values_def = array_shift($display_values);
                    }
                    $defaults = str_replace('\\,', '%comma%', $auto_fill_default);
                    $defaults = explode(',', $defaults);
                    $defaults = str_replace('%comma%', ',', $defaults);
                    $defaults = array_map('trim', $defaults);
                }
                if (isset($_GET[$url_param])) {
                    $original_get = $_GET[$url_param];
                    $defaults = $_GET[$url_param];
                    if (is_string($defaults)) {
                        $defaults = explode(',', $defaults);
                    }
                    unset($_GET[$url_param]);
                }
                for ($i = 0; $i < count($values_arr); $i++) {
                    $value = $values_arr[$i];
                    $value = trim($value);
                    // Check for a display value.
                    if (isset($display_values[$i])) {
                        $display_value = $display_values[$i];
                    } else {
                        $display_value = $value;
                    }
                    $options[$value]['#name'] = $url_param . '[]';
                    $options[$value]['#title'] = $display_value;
                    $options[$value]['#value'] = $value;
                    $options[$value]['#default_value'] = in_array($value, $defaults) || in_array($options[$value]['#title'], $defaults);
                    // set default using option titles too
                    //                    $options[$value]['#inline'] = true;
                    //                    $options[$value]['#after'] = '&nbsp;&nbsp;';
                }
                $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#before' => '<div class="wpcf-checboxes-group">', '#after' => '</div>')));
                if ($original_get) {
                    $_GET[$url_param] = $original_get;
                }
                break;
            default:
                for ($i = 0; $i < count($values_arr); $i++) {
                    $value = $values_arr[$i];
                    $value = trim($value);
                    // Check for a display value.
                    if (isset($display_values[$i])) {
                        $display_value = $display_values[$i];
                    } else {
                        $display_value = $value;
                    }
                    $options[$display_value] = $value;
                }
                if (count($values_arr) != count($options)) {
                    // if the $values_arr has one more item than $options, there is a repeating value reset on creation: the existing default
                    $default_value = reset($options);
                } else {
                    // so the default value in this case is the first element in $values_arr
                    $default_value = $values_arr[0];
                }
                if ($type == 'radios') {
                    if (isset($_GET[$url_param]) && in_array($_GET[$url_param], $options)) {
                        $default_value = $_GET[$url_param];
                    }
                    $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value, '#multiple' => $multi)));
                } else {
                    if (isset($_GET[$url_param])) {
                        if (is_array($_GET[$url_param])) {
                            if (count(array_intersect($_GET[$url_param], $options)) > 0) {
                                $default_value = $_GET[$url_param];
                            }
                        } else {
                            if (in_array($_GET[$url_param], $options)) {
                                $default_value = $_GET[$url_param];
                            }
                        }
                    }
                    $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value, '#multiple' => $multi)));
                }
                break;
        }
        return $element;
    } else {
        if (!empty($field)) {
            // check if Types is active
            if (!function_exists('wpcf_admin_fields_get_field')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                } else {
                    return __('Types plugin is required.', 'wpv-views');
                }
            }
            if (!function_exists('wpv_form_control')) {
                include '../common/functions.php';
            }
            //This is important cause wpcf_admin_fields_get_field works with id: $field - 'wpcf-' and search with 'wpcf-'.$field
            /*if( strpos($field, 'wpcf-') !== false )
            		{
            			$tmp = explode('wpcf-', $field);
            			$field = $tmp[1];
            		}*/
            // get field options
            $field_options = wpcf_admin_fields_get_field($field);
            if (empty($field_options)) {
                return __('Empty field values or incorrect field defined. ', 'wpv-views');
            }
            $field_options['name'] = wpv_translate('field ' . $field_options['id'] . ' name', $field_options['name'], false, 'plugin Types');
            // get the type of custom field (radio, checkbox, other)
            $field_type = $field_options['type'];
            // override with type
            if (!empty($type)) {
                $field_type = $type;
            }
            if (!in_array($field_type, array('radio', 'checkbox', 'checkboxes', 'select', 'textfield', 'date', 'datepicker'))) {
                $field_type = 'textfield';
            }
            // Radio field
            if ($field_type == 'radio') {
                //	print_r( $field_options );
                $field_radio_options = $field_options['data']['options'];
                $options = array();
                foreach ($field_radio_options as $key => $opts) {
                    if (is_array($opts)) {
                        if (isset($field_options['data']['display']) && 'value' == $field_options['data']['display'] && isset($opts['display_value'])) {
                            $options[$opts['display_value']] = $opts['value'];
                            // if we have an actual display value and is set to be used, use it
                        } else {
                            // else, use the field value title and watch out because checkboxes fields need their titles as values
                            if (_wpv_is_field_of_type('wpcf-' . $field, 'checkboxes')) {
                                $options[wpv_translate('field ' . $field_options['id'] . ' option ' . $key . ' title', $opts['title'], false, 'plugin Types')] = $opts['title'];
                            } else {
                                $options[wpv_translate('field ' . $field_options['id'] . ' option ' . $key . ' title', $opts['title'], false, 'plugin Types')] = $opts['value'];
                            }
                        }
                    }
                }
                // get the form content
                $element = wpv_form_control(array('field' => array('#type' => 'radios', '#id' => 'wpv_control_radio_' . $field, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => isset($_GET[$url_param]) ? $_GET[$url_param] : null)));
                return $element;
            } else {
                if ($field_type == 'checkbox') {
                    if (isset($atts['title'])) {
                        $checkbox_name = wpv_translate($url_param . '_title', $title, false, 'View ' . $view_name);
                    } else {
                        $checkbox_name = wpv_translate('field ' . $field_options['name'] . ' name', $field_options['name'], false, 'plugin Types');
                    }
                    $element = wpv_form_control(array('field' => array('#type' => 'checkbox', '#id' => 'wpv_control_checkbox_' . $field, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#title' => $checkbox_name, '#value' => $field_options['data']['set_value'], '#default_value' => 0)));
                    return $element;
                } else {
                    if ($field_type == 'checkboxes') {
                        $defaults = array();
                        $original_get = null;
                        if (isset($_GET[$url_param])) {
                            $original_get = $_GET[$url_param];
                            $defaults = $_GET[$url_param];
                            if (is_string($defaults)) {
                                $defaults = explode(',', $defaults);
                            }
                            unset($_GET[$url_param]);
                        }
                        if (isset($field_options['data']['options']['default'])) {
                            unset($field_options['data']['options']['default']);
                        }
                        // remove the default option from the array
                        foreach ($field_options['data']['options'] as $key => $value) {
                            $display_value = wpv_translate('field ' . $field_options['id'] . ' option ' . $key . ' title', trim($value['title']), false, 'plugin Types');
                            if (_wpv_is_field_of_type('wpcf-' . $field, 'checkboxes')) {
                                $value = trim($value['title']);
                            } else {
                                $value = trim($value['value']);
                            }
                            $options[$value]['#name'] = $url_param . '[]';
                            $options[$value]['#title'] = $display_value;
                            $options[$value]['#value'] = $value;
                            $options[$value]['#default_value'] = in_array($value, $defaults);
                            //                $options[$value]['#inline'] = true;
                            //                $options[$value]['#after'] = '&nbsp;&nbsp;';
                        }
                        $element = wpv_form_control(array('field' => array('#type' => 'checkboxes', '#id' => 'wpv_control_checkbox_' . $field, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options)));
                        if ($original_get) {
                            $_GET[$url_param] = $original_get;
                        }
                        return $element;
                    } else {
                        if ($field_type == 'select') {
                            $field_select_options = $field_options['data']['options'];
                            $options = array();
                            foreach ($field_select_options as $key => $opts) {
                                if (is_array($opts)) {
                                    if (_wpv_is_field_of_type('wpcf-' . $field, 'checkboxes')) {
                                        $options[wpv_translate('field ' . $field_options['id'] . ' option ' . $key . ' title', $opts['title'], false, 'plugin Types')] = $opts['title'];
                                    } else {
                                        $options[wpv_translate('field ' . $field_options['id'] . ' option ' . $key . ' title', $opts['title'], false, 'plugin Types')] = $opts['value'];
                                    }
                                }
                            }
                            $default_value = false;
                            if (isset($_GET[$url_param]) && in_array($_GET[$url_param], $options)) {
                                $default_value = $_GET[$url_param];
                            }
                            $element = wpv_form_control(array('field' => array('#type' => 'select', '#id' => 'wpv_control_select_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value)));
                            return $element;
                        } else {
                            if ($field_type == 'textfield') {
                                $default_value = '';
                                if (isset($_GET[$url_param])) {
                                    $default_value = stripslashes(urldecode(sanitize_text_field($_GET[$url_param])));
                                }
                                $element = wpv_form_control(array('field' => array('#type' => 'textfield', '#id' => 'wpv_control_textfield_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value)));
                                return $element;
                            } else {
                                if ($field_type == 'date' || $field_type == 'datepicker') {
                                    $out = wpv_render_datepicker($url_param, $date_format, $default_date);
                                    return $out;
                                }
                            }
                        }
                    }
                }
            }
            return '';
        } else {
            // type parameter without values
            $default_value = '';
            if (isset($_GET[$url_param])) {
                $default_value = $_GET[$url_param];
            }
            switch ($type) {
                case 'checkbox':
                    $element = array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value));
                    $element['field']['#title'] = wpv_translate($url_param . '_title', $title, false, 'View ' . $view_name);
                    $element = wpv_form_control($element);
                    break;
                case 'datepicker':
                    $element = wpv_render_datepicker($url_param, $date_format, $default_date);
                    break;
                default:
                    $element = array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value));
                    $element = wpv_form_control($element);
                    break;
            }
            return $element;
        }
    }
}
コード例 #7
0
ファイル: wpv-filter-embedded.php プロジェクト: juslee/e27
/**
* 
*Views-Shortcode: wpv-control
*
* Description: Add filters for View
*
* Parameters:
* type: type of retrieved field layout (radio, checkbox, select, textfield, checkboxes, datepicker)
* url_param: the URL parameter passed as an argument
* values: Optional. a list of supplied values
* display_values: Optional. A list of values to display for the corresponding values
* auto_fill: Optional. When set to a "field-slug" the control will be populated with custom field values from the database.
* auto_fill_default: Optional. Used to set the default, unselected, value of the control. eg Ignore or Don't care
* auto_fill_sort: Optional. 'asc', 'desc', 'none'. Defaults to ascending.
* field: Optional. a Types field to retrieve values from
* title: Optional. Use for the checkbox title
* taxonomy: Optional. Use when a taxonomy control should be displayed.
* date_format: Optional. Used for a datepicker control
*
* @param array $atts An associative array of arributes to be used.
*/
function wpv_shortcode_wpv_control($atts)
{
    if (!isset($atts['url_param'])) {
        return __('The url_param is missing from the wpv-control shortcode argument.', 'wpv-views');
    }
    if ((!isset($atts['type']) || $atts == '') && !isset($atts['field'])) {
        return __('The "type" or "field" needs to be set in the wpv-control shortcode argument.', 'wpv-views');
    }
    extract(shortcode_atts(array('type' => '', 'values' => array(), 'display_values' => array(), 'field' => '', 'url_param' => '', 'title' => '', 'taxonomy' => '', 'auto_fill' => '', 'auto_fill_default' => '', 'auto_fill_sort' => '', 'date_format' => ''), $atts));
    if ($taxonomy != '') {
        return _wpv_render_taxonomy_control($taxonomy, $type, $url_param);
    }
    if ($auto_fill != '') {
        global $wpdb;
        switch (strtolower($auto_fill_sort)) {
            case 'desc':
                $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value DESC");
                break;
            case 'none':
                $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}'");
                break;
            default:
                $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value ASC");
                break;
        }
        if ($auto_fill_default != '') {
            $values = '';
            $display_values = $auto_fill_default;
            $first = false;
        } else {
            $values = '';
            $display_values = '';
            $first = true;
        }
        foreach ($db_values as $value) {
            if ($value) {
                if (!$first) {
                    $values .= ',';
                    $display_values .= ',';
                }
                $values .= $value;
                $display_values .= $value;
                $first = false;
            }
        }
    }
    $out = '';
    // Use when values attributes are defined (predefined values to list)
    if (!empty($values)) {
        $values_arr = explode(',', $values);
        if (!empty($display_values)) {
            $display_values = explode(',', $display_values);
        }
        $options = array();
        if (!in_array($type, array('radio', 'radios', 'select', 'checkboxes'))) {
            $type = 'select';
        }
        if ($type == 'radio') {
            $type = 'radios';
        }
        switch ($type) {
            case 'checkboxes':
                $defaults = array();
                $original_get = null;
                if (isset($_GET[$url_param])) {
                    $original_get = $_GET[$url_param];
                    $defaults = $_GET[$url_param];
                    unset($_GET[$url_param]);
                }
                for ($i = 0; $i < count($values_arr); $i++) {
                    $value = $values_arr[$i];
                    $value = trim($value);
                    // Check for a display value.
                    if (isset($display_values[$i])) {
                        $display_value = $display_values[$i];
                    } else {
                        $display_value = $value;
                    }
                    $options[$value]['#name'] = $url_param . '[]';
                    $options[$value]['#title'] = $display_value;
                    $options[$value]['#value'] = $value;
                    $options[$value]['#default_value'] = in_array($value, $defaults);
                    //                    $options[$value]['#inline'] = true;
                    //                    $options[$value]['#after'] = '&nbsp;&nbsp;';
                }
                $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options)));
                if ($original_get) {
                    $_GET[$url_param] = $original_get;
                }
                break;
            default:
                for ($i = 0; $i < count($values_arr); $i++) {
                    $value = $values_arr[$i];
                    $value = trim($value);
                    // Check for a display value.
                    if (isset($display_values[$i])) {
                        $display_value = $display_values[$i];
                    } else {
                        $display_value = $value;
                    }
                    $options[$display_value] = $value;
                }
                $default_value = $values_arr[0];
                if (isset($_GET[$url_param]) && in_array($_GET[$url_param], $options)) {
                    $default_value = $_GET[$url_param];
                }
                $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value)));
                break;
        }
        return $element;
    } else {
        if (!empty($field)) {
            // check if Types is active
            if (!function_exists('wpcf_admin_fields_get_field')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                } else {
                    return __('Types plugin is required.', 'wpv-views');
                }
            }
            if (!function_exists('wpv_form_control')) {
                include '../common/functions.php';
            }
            // get field options
            $field_options = wpcf_admin_fields_get_field($field);
            if (empty($field_options)) {
                return __('Empty field values or incorrect field defined. ', 'wpv-views');
            }
            // get the type of custom field (radio, checkbox, other)
            $field_type = $field_options['type'];
            // override with type
            if (!empty($type)) {
                $field_type = $type;
            }
            if (!in_array($field_type, array('radio', 'checkbox', 'checkboxes', 'select', 'textfield', 'date', 'datepicker'))) {
                $field_type = 'textfield';
            }
            // Radio field
            if ($field_type == 'radio') {
                $field_radio_options = $field_options['data']['options'];
                $options = array();
                foreach ($field_radio_options as $key => $opts) {
                    if (is_array($opts)) {
                        $options[$opts['title']] = $opts['value'];
                    }
                }
                // get the form content
                $element = wpv_form_control(array('field' => array('#type' => 'radios', '#id' => 'wpv_control_radio_' . $field, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => isset($_GET[$url_param]) ? $_GET[$url_param] : null)));
                return $element;
            } else {
                if ($field_type == 'checkbox') {
                    if (isset($atts['title'])) {
                        $checkbox_name = $title;
                    } else {
                        $checkbox_name = $field_options['name'];
                    }
                    $element = wpv_form_control(array('field' => array('#type' => 'checkbox', '#id' => 'wpv_control_checkbox_' . $field, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#title' => $checkbox_name, '#value' => $field_options['data']['set_value'], '#default_value' => 0)));
                    return $element;
                } else {
                    if ($field_type == 'checkboxes') {
                        $defaults = array();
                        $original_get = null;
                        if (isset($_GET[$url_param])) {
                            $original_get = $_GET[$url_param];
                            $defaults = $_GET[$url_param];
                            unset($_GET[$url_param]);
                        }
                        foreach ($field_options['data']['options'] as $value) {
                            $value = trim($value['title']);
                            $display_value = $value;
                            $options[$value]['#name'] = $url_param . '[]';
                            $options[$value]['#title'] = $display_value;
                            $options[$value]['#value'] = $value;
                            $options[$value]['#default_value'] = in_array($value, $defaults);
                            //                $options[$value]['#inline'] = true;
                            //                $options[$value]['#after'] = '&nbsp;&nbsp;';
                        }
                        $element = wpv_form_control(array('field' => array('#type' => 'checkboxes', '#id' => 'wpv_control_checkbox_' . $field, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options)));
                        if ($original_get) {
                            $_GET[$url_param] = $original_get;
                        }
                        return $element;
                    } else {
                        if ($field_type == 'select') {
                            $field_select_options = $field_options['data']['options'];
                            $options = array();
                            foreach ($field_select_options as $key => $opts) {
                                if (is_array($opts)) {
                                    $options[$opts['title']] = $opts['value'];
                                }
                            }
                            $default_value = false;
                            if (isset($_GET[$url_param]) && in_array($_GET[$url_param], $options)) {
                                $default_value = $_GET[$url_param];
                            }
                            $element = wpv_form_control(array('field' => array('#type' => 'select', '#id' => 'wpv_control_select_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value)));
                            return $element;
                        } else {
                            if ($field_type == 'textfield') {
                                $default_value = '';
                                if (isset($_GET[$url_param])) {
                                    $default_value = $_GET[$url_param];
                                }
                                $element = wpv_form_control(array('field' => array('#type' => 'textfield', '#id' => 'wpv_control_textfield_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value)));
                                return $element;
                            } else {
                                if ($field_type == 'date' || $field_type == 'datepicker') {
                                    $out = wpv_render_datepicker($url_param, $date_format);
                                    return $out;
                                }
                            }
                        }
                    }
                }
            }
            return '';
        } else {
            // type parameter without values
            $default_value = '';
            if (isset($_GET[$url_param])) {
                $default_value = $_GET[$url_param];
            }
            switch ($type) {
                case 'checkbox':
                    $element = array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value));
                    $element['field']['#title'] = $title;
                    $element = wpv_form_control($element);
                    break;
                case 'datepicker':
                    $element = wpv_render_datepicker($url_param, $date_format);
                    break;
                default:
                    $element = array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value));
                    $element = wpv_form_control($element);
                    break;
            }
            return $element;
        }
    }
}
コード例 #8
0
    function show_hidden_custom_fields($options)
    {
        if (isset($options['wpv_show_hidden_fields']) && $options['wpv_show_hidden_fields'] != '') {
            $defaults = explode(',', $options['wpv_show_hidden_fields']);
        } else {
            $defaults = array();
        }
        $this->admin_section_start(__('Show the following hidden custom fields in the Views GUI', 'wpv-views'));
        ?>

			<div id="wpv_show_hidden_custom_fields_summary" style="margin-left:20px">
				<?php 
        if (sizeof($defaults) > 0) {
            echo sprintf(__('The following private custom fields are showing in the Views GUI: %s', 'wpv-views'), implode(', ', $defaults));
        } else {
            _e('No private custom fields are showing in the Views GUI.', 'wpv-views');
        }
        ?>
				<br />
		        <input class="button-secondary" type="button" value="<?php 
        echo __('Edit', 'wpv-views');
        ?>
" onclick="wpv_show_hidden_custom_fields_edit();"/>
				
			</div>
			<div id="wpv_show_hidden_custom_fields_admin" style="margin-left:20px;display:none">

				<?php 
        $meta_keys = $this->get_meta_keys(true);
        echo '<table><tr>';
        $count = 0;
        foreach ($meta_keys as $field) {
            if (strpos($field, '_') === 0) {
                $options[$field]['#default_value'] = in_array($field, $defaults);
                $element = wpv_form_control(array('field' => array('#type' => 'checkbox', '#name' => 'wpv_show_hidden_fields[]', '#attributes' => array('style' => ''), '#inline' => true, '#title' => $field, '#value' => $field, '#before' => '<td>', '#after' => '</td>', '#default_value' => in_array($field, $defaults))));
                echo $element;
                $count++;
                if (!($count % 3)) {
                    echo '</tr><tr>';
                }
            }
        }
        // close the table correctly.
        if (!($count % 3)) {
            echo '<td></td><td></td><td></td>';
        }
        while (true) {
            if (!($count % 3)) {
                echo '</tr>';
                break;
            } else {
                echo '<td></td>';
            }
            $count++;
        }
        echo '</table>';
        ?>
			
				<input class="button-primary" type="button" value="<?php 
        echo __('Save', 'wpv-views');
        ?>
" onclick="wpv_show_hidden_custom_fields_save();"/>
				<img id="wpv_show_custom_fields_spinner" src="<?php 
        echo WPV_URL;
        ?>
/res/img/ajax-loader.gif" width="16" height="16" style="display:none" alt="loading" />
		
				<input class="button-secondary" type="button" value="<?php 
        echo __('Cancel', 'wpv-views');
        ?>
" onclick="wpv_show_hidden_custom_fields_cancel();"/>
				
			
			</div>
		<?php 
        $this->admin_section_end();
    }
コード例 #9
0
    function wpv_render_custom_field_options($args, $view_settings = null)
    {
        $compare = array('=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN');
        $types = array('CHAR', 'NUMERIC', 'BINARY', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED');
        if ($view_settings === null) {
            $value = '';
            $compare_selected = '';
            $type_selected = '';
            $name = 'custom-field-' . str_replace(' ', '_', $args['name']) . '%s';
            $parts = array($value);
        } else {
            $value = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_value'];
            $value = _wpv_encode_date($value);
            $compare_selected = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_compare'];
            $compare_count = 1;
            $parts = array($value);
            switch ($compare_selected) {
                case 'BETWEEN':
                case 'NOT BETWEEN':
                    $compare_count = 2;
                    $parts = explode(',', $value);
                    // Make sure we have only 2 items.
                    while (count($parts) < 2) {
                        $parts[] = '';
                    }
                    while (count($parts) > 2) {
                        array_pop($parts);
                    }
                    break;
                case 'IN':
                case 'NOT IN':
                    $parts = explode(',', $value);
                    $compare_count = count($parts);
                    if ($compare_count < 1) {
                        $compare_count = 1;
                        $parts = array($value);
                    }
                    break;
            }
            $value = _wpv_unencode_date($value);
            $type_selected = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_type'];
            $name = 'custom-field-' . str_replace(' ', '_', $args['name']) . '%s';
        }
        ?>
			<?php 
        _e('Comparison function:', 'wpv-views');
        ?>
			<p>
				<select name="<?php 
        echo sprintf($name, '_compare');
        ?>
" class="wpv_custom_field_compare_select js-wpv-custom-field-compare-select">
					<?php 
        foreach ($compare as $com) {
            $selected = $compare_selected == $com ? ' selected="selected"' : '';
            echo '<option value="' . $com . '" ' . $selected . '>' . $com . '&nbsp;</option>';
        }
        ?>
				</select>
				<select name="<?php 
        echo sprintf($name, '_type');
        ?>
" class="js-wpv-custom-field-type-select">
					<?php 
        foreach ($types as $type) {
            $selected = $type_selected == $type ? ' selected="selected"' : '';
            echo '<option value="' . $type . '" ' . $selected . '>' . $type . '&nbsp;</option>';
        }
        ?>
				</select>
			</p>

			<div class="js-wpv-custom-field-values">

				<?php 
        // This is where we store the actual value derived from the follow controls
        ?>
				<input type="hidden" class="js-wpv-custom-field-values-real" name="<?php 
        echo sprintf($name, '_value');
        ?>
" value="<?php 
        echo $value;
        ?>
" />

				<?php 
        for ($i = 0; $i < count($parts); $i++) {
            echo '<div class="wpv_custom_field_value_div js-wpv-custom-field-value-div">';
            $options = array();
            $options[__('Constant', 'wpv-views') . '&nbsp'] = 'constant';
            $options[__('URL parameter', 'wpv-views') . '&nbsp'] = 'url';
            $options[__('Shortcode attribute', 'wpv-views') . '&nbsp'] = 'attribute';
            $options['NOW&nbsp'] = 'now';
            $options['TODAY&nbsp;'] = 'today';
            $options['FUTURE_DAY&nbsp;'] = 'future_day';
            $options['PAST_DAY&nbsp;'] = 'past_day';
            $options['THIS_MONTH&nbsp;'] = 'this_month';
            $options['FUTURE_MONTH&nbsp;'] = 'future_month';
            $options['PAST_MONTH&nbsp;'] = 'past_month';
            $options['THIS_YEAR&nbsp;'] = 'this_year';
            $options['FUTURE_YEAR&nbsp;'] = 'future_year';
            $options['PAST_YEAR&nbsp;'] = 'past_year';
            $options['SECONDS_FROM_NOW&nbsp;'] = 'seconds_from_now';
            $options['MONTHS_FROM_NOW&nbsp;'] = 'months_from_now';
            $options['YEARS_FROM_NOW&nbsp;'] = 'years_from_now';
            $options['DATE&nbsp;'] = 'date';
            $function_value = _wpv_get_custom_filter_function_and_value($parts[$i]);
            echo wpv_form_control(array('field' => array('#name' => 'wpv_custom_field_compare_mode-' . $args['name'] . $i, '#type' => 'select', '#attributes' => array('style' => '', 'class' => 'wpv_custom_field_compare_mode js-wpv-custom-field-compare-mode'), '#inline' => true, '#options' => $options, '#default_value' => $function_value['function'])));
            echo '<input type="text" class="js-wpv-custom-field-value-text js-wpv-custom-field-' . $args['name'] . '-value-text" value="' . $function_value['value'] . '" data-class="js-wpv-custom-field-' . $args['name'] . '-value-text" data-type="none" name="js-wpv-custom-field-' . $args['name'] . '-value-text" />';
            // Add controls for entering the date.
            _wpv_custom_field_date_controls($function_value['function'], $function_value['value']);
            ?>
<input type="button" class="button-secondary js-wpv-custom-field-remove-value" value="<?php 
            echo __('Remove', 'wpv-views');
            ?>
">
						<?php 
            echo '</div>';
        }
        ?>
				<p>
					<input type="button" class="button-secondary js-wpv-custom-field-add-value" value="<?php 
        echo __('Add another value', 'wpv-views');
        ?>
"/>
				</p>

			</div>

	<?php 
    }
コード例 #10
0
function wpv_add_meta_key($args, $view_settings = null)
{
    $compare = array('=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN');
    $types = array('CHAR', 'NUMERIC', 'BINARY', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED');
    if ($view_settings === null) {
        $value = '';
        $compare_selected = '';
        $type_selected = '';
        $name = 'custom-field-' . str_replace(' ', '_', $args['name']) . '%s';
        $parts = array($value);
    } else {
        $value = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_value'];
        $value = _wpv_encode_date($value);
        $compare_selected = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_compare'];
        $compare_count = 1;
        $parts = array($value);
        switch ($compare_selected) {
            case 'BETWEEN':
            case 'NOT BETWEEN':
                $compare_count = 2;
                $parts = explode(',', $value);
                // Make sure we have only 2 items.
                while (count($parts) < 2) {
                    $parts[] = '';
                }
                while (count($parts) > 2) {
                    array_pop($parts);
                }
                break;
            case 'IN':
            case 'NOT IN':
                $parts = explode(',', $value);
                $compare_count = count($parts);
                if ($compare_count < 1) {
                    $compare_count = 1;
                    $parts = array($value);
                }
                break;
        }
        $value = _wpv_unencode_date($value);
        $type_selected = $view_settings['custom-field-' . str_replace(' ', '_', $args['name']) . '_type'];
        $name = '_wpv_settings[custom-field-' . str_replace(' ', '_', $args['name']) . '%s]';
    }
    ?>


	<div class="meta_key_div" style="margin-left: 20px;">
		<br />
		<?php 
    _e('Comparison function:', 'wpv-views');
    ?>
		<select name="<?php 
    echo sprintf($name, '_compare');
    ?>
" class="wpv_custom_field_compare_select">
			<?php 
    foreach ($compare as $com) {
        $selected = $compare_selected == $com ? ' selected="selected"' : '';
        echo '<option value="' . $com . '" ' . $selected . '>' . $com . '&nbsp;</option>';
    }
    ?>
		</select>
		<select name="<?php 
    echo sprintf($name, '_type');
    ?>
">
			<?php 
    foreach ($types as $type) {
        $selected = $type_selected == $type ? ' selected="selected"' : '';
        echo '<option value="' . $type . '" ' . $selected . '>' . $type . '&nbsp;</option>';
    }
    ?>
		</select>
		<br />
		
		<div class="wpv_custom_field_values">

			<?php 
    // This is where we store the actual value derived from the follow controls
    ?>
			<input type="hidden" name="<?php 
    echo sprintf($name, '_value');
    ?>
" value="<?php 
    echo $value;
    ?>
" />

			<?php 
    for ($i = 0; $i < count($parts); $i++) {
        echo '<div class="wpv_custom_field_value_div">';
        $options = array();
        $options[__('Constant', 'wpv-views') . '&nbsp'] = 'constant';
        $options[__('URL parameter', 'wpv-views') . '&nbsp'] = 'url';
        $options[__('Shortcode attribute', 'wpv-views') . '&nbsp'] = 'attribute';
        $options['NOW&nbsp'] = 'now';
        $options['TODAY&nbsp;'] = 'today';
        $options['FUTURE_DAY&nbsp;'] = 'future_day';
        $options['PAST_DAY&nbsp;'] = 'past_day';
        $options['THIS_MONTH&nbsp;'] = 'this_month';
        $options['FUTURE_MONTH&nbsp;'] = 'future_month';
        $options['PAST_MONTH&nbsp;'] = 'past_month';
        $options['THIS_YEAR&nbsp;'] = 'this_year';
        $options['FUTURE_YEAR&nbsp;'] = 'future_year';
        $options['PAST_YEAR&nbsp;'] = 'past_year';
        $options['SECONDS_FROM_NOW&nbsp;'] = 'seconds_from_now';
        $options['MONTHS_FROM_NOW&nbsp;'] = 'months_from_now';
        $options['YEARS_FROM_NOW&nbsp;'] = 'years_from_now';
        $options['DATE&nbsp;'] = 'date';
        $function_value = _wpv_get_custom_filter_function_and_value($parts[$i]);
        echo wpv_form_control(array('field' => array('#name' => 'wpv_custom_field_compare_mode-' . $args['name'] . $i, '#type' => 'select', '#attributes' => array('style' => '', 'class' => 'wpv_custom_field_compare_mode'), '#inline' => true, '#options' => $options, '#default_value' => $function_value['function'])));
        echo '<input type="text" class="wpv_custom_filter_value_text" value="' . $function_value['value'];
        if ($function_value['text_boxes'] == 1) {
            echo '" />';
        } else {
            echo '" style="display:none;" />';
        }
        ?>
					<span class="wpv_custom_field_param_missing"><?php 
        echo __('<- Please enter a value here', 'wpv-views');
        ?>
</span>
					<?php 
        // Add controls for entering the date.
        _wpv_add_date_controls($function_value['function'], $function_value['value']);
        // Add a "Remove" button
        echo '<input type="button" class="button-secondary wpv_custom_field_remove_value" value="' . __('Remove', 'wpv-views') . '" ';
        if ($i > 0 && ($compare_selected == 'IN' || $compare_selected == 'NOT IN')) {
            echo ' />';
        } else {
            echo 'style="display:none" />';
        }
        echo '</div>';
    }
    ?>
			<?php 
    $show = $compare_selected == 'IN' || $compare_selected == 'NOT IN' ? ' ' : 'style="display:none" ';
    ?>
			<input type="button" class="button-secondary wpv_custom_field_add_value" value="<?php 
    echo __('Add another value', 'wpv-views');
    ?>
" <?php 
    echo $show;
    ?>
/>
																								  
																								  
		</div>
		

	<?php 
    if ($view_settings == null) {
        ?>
		
		<br />
		<span class="wpv-custom-fields-help"><i>
			<?php 
        echo sprintf(__('%sLearn about filtering by custom fields%s', 'wpv-views'), '<a href="' . WPV_FILTER_BY_CUSTOM_FIELD_LINK . '" target="_blank">', ' &raquo;</a>');
        ?>
		</i></span>
	<?php 
    }
    ?>
	
	</div>
	

	<?php 
}