/**
* wpv_get_usermeta_field_summary
*
* Returns each usermeta field filter summary for a View
*
* @paran $type (string) usermeta-field-{$field-name}
* @param $view_settings
*
* @returns (string) $summary
*
* @since unknown
*/

function wpv_get_usermeta_field_summary( $type, $view_settings = array() ) {
	global $WP_Views_fapi;
	$field_name = substr( $type, strlen( 'usermeta-field-' ) );
	$field_nicename = wpv_types_get_field_name( $field_name );
	$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'
	);
	if ( isset( $compare[$view_settings[$type . '_compare']] ) ) {
		$compare_selected = esc_html( $compare[$view_settings[$type . '_compare']] );
	} else {
		$compare_selected = __( 'related', 'wpv-views' );
	}
	if ( isset( $types[$view_settings[$type . '_type']] ) ) {
		$type_selected = esc_html( $types[$view_settings[$type . '_type']] );
	} else {
		$type_selected = __( 'value', 'wpv-views' );
	}
	$value_selected = esc_html( str_replace( ',', ', ', $view_settings[$type . '_value'] ) );
	ob_start();
	?>
	<span class="wpv-filter-multiple-summary-item">
	<?php
	if (
		! $WP_Views_fapi->framework_valid
		&& strpos( $value_selected, 'FRAME_KEY' ) !== false
	) {
		$WP_Views_fapi->framework_missing_message_for_filters( $field_nicename );
	} else {
		echo sprintf( __( '<strong>%s</strong> is a %s <strong>%s</strong> <strong>%s</strong>', 'wpv-views' ), $field_nicename, $type_selected, $compare_selected, $value_selected );
	}
	?>
	</span>
	<?php
	$buffer = ob_get_clean();
	return $buffer;
}
	static function wpv_get_list_item_ui_post_custom_field( $type, $view_settings = array() ) {
		$field_name = substr( $type, strlen( 'custom-field-' ) );
		$args = array( 'name' => $field_name );
		if ( ! isset( $view_settings[$type . '_compare'] ) ) {
			$view_settings[$type . '_compare'] = '=';
		}
		if ( ! isset( $view_settings[$type . '_type'] ) ) {
			$view_settings[$type . '_type'] = 'CHAR';
		}
		if ( ! isset( $view_settings[$type . '_value'] ) ) {
			$view_settings[$type . '_value'] = '';
		}
		$field_nicename = wpv_types_get_field_name( $field_name );
		$args['nicename'] = $field_nicename;
		ob_start();
		?>
		<div class="wpv-filter-multiple-element js-wpv-filter-multiple-element js-wpv-filter-custom-field-multiple-element js-filter-row-custom-field-<?php echo esc_attr( $field_name ); ?>" data-field="<?php echo esc_attr( $field_name ); ?>">
			<h4><?php echo __('Custom field', 'wpv_views') . ' - ' . $field_nicename; ?></h4>
			<span class="wpv-filter-multiple-element-delete">
				<button class="button button-secondary button-small js-filter-remove" data-field="<?php echo esc_attr( $field_name ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_filter_custom_field_delete_nonce' );?>">
					<i class="icon-trash"></i>&nbsp;<?php _e( 'Delete', 'wpv-views' ); ?>
				</button>
			</span>
			<div class="wpv-filter-multiple-element-options">
			<?php WPV_Custom_Field_Filter::wpv_render_custom_field_options( $args, $view_settings ); ?>
			</div>
			<div class="js-wpv-filter-toolset-messages"></div>
		</div>
		<?php
		$buffer = ob_get_clean();
		return $buffer;
	}
Example #3
0
/**
 * Content of wpv-conditional modal window.
 *
 * Content of wpv-conditional modal window used when we editing a entryn and
 * setup a wpv-conditional shortcode using Views Shortcode GUI API
 *
 * @since 1.9.0
 *
 * @param string $id Shortcode id
 * @param array $ shortcode data
 * @param array $ css classes
 * @param array $post_type post type
 *
 * @return string Content of modal window for wpv-shortcode.
 */
function wpv_shortcode_wpv_conditional_callback( $id, $data = array(), $classes = array(), $post_type = '' ) {
	global $WP_Views;
    /*if ( empty($post_type) ) {
        return __('Wrong post type', 'wpv-views');
    }*/
	/*
	if ( empty( $post_type ) ) {
		$post_type_slug = '';
	} else {
		if ( isset( $post_type->slug ) ) {
			$post_type_slug = $post_type->slug;
		} elseif ( isset( $post_type->name ) ) {
			$post_type_slug = $post_type->name;
		} else {
			$post_type_slug = '';
		}
	}
	*/
    
    $content = '';
    $fields = array(
        'types' => array(
            'label' => __('Types Fields', 'wpv-views'),
        ),
        'custom-fields' => array(
            'label' => __('Custom Fields', 'wpv-views'),
        ),
        'views-shortcodes' => array(
            'label' => __('Views Shortcodes', 'wpv-views'),
        ),
        'custom-shortcodes' => array(
            'label' => __('Custom Shortcodes', 'wpv-views'),
        ),
        'custom-functions' => array(
            'label' => __('Custom Functions', 'wpv-views'),
        ),
    );
    foreach( array_keys($fields) as $key ) {
        $fields[$key]['fields'] = array();
        $fields[$key]['slug'] = $key;
    }

    /**
     * get types custom fields
     */
	 /*
    $groups = apply_filters('wpcf_get_groups_by_post_type', array(), $post_type);
    if ( !empty($groups) ) {
        foreach( $groups as $group_id => $group_data ) {
            $fields_from_group = apply_filters('wpcf_fields_by_group', array(), $group_id);
            foreach ( $fields_from_group as $field_slug => $field_data ) {
                $fields['types']['fields'][$field_slug] = array(
                    'label' => $field_data['name'],
                    'slug' => sprintf('$(%s)', $field_data['slug']),
                    'type' => $field_data['type'],
                );
            }
        }
    }
	*/

	$post_meta_keys = $WP_Views->get_meta_keys();
	//$post_meta_keys = array_diff( $post_meta_keys, apply_filters( 'wpcf_get_all_fields_slugs', array() ) );
    if ( !empty( $post_meta_keys ) ) {
        foreach( $post_meta_keys as $key ) {
            if ( empty($key) ) {
                continue;
            }
			if ( wpv_is_types_custom_field( $key ) ) {
				$fields['types']['fields'][$key] = array(
					'label' => wpv_types_get_field_name( $key ),
					'slug' => sprintf('$(%s)', $key),
					'type' => 'text',
				);

			} else {
				$fields['custom-fields']['fields'][$key] = array(
					'label' => $key,
					'slug' => sprintf('$(%s)', $key),
					'type' => 'text',
				);
			}
        }
    }

    /**
     * get Views options
     */
    $options = get_option('wpv_options');

    /**
     * Views hidden CF's - already done in get_meta_keys() above!!
     */
	/*
    if ( isset($options['wpv_show_hidden_fields']) && !empty($options['wpv_show_hidden_fields'] ) ) {
        foreach( explode(',', $options['wpv_show_hidden_fields']) as $key) {
            if ( empty($key) ) {
                continue;
            }
            $fields['custom-fields']['fields'][$key] = array(
                'label' => $key,
                'slug' => sprintf('$(%s)', $key),
                'type' => 'text',
            );
        }
    }
	*/

    /**
     * Views Shortcodes
     */

    global $shortcode_tags;
    if ( is_array($shortcode_tags) ) {
        foreach (array_keys($shortcode_tags) as $key) {
            $views_shortcodes_regex = wpv_inner_shortcodes_list_regex();
            $include_expression = "/(". $views_shortcodes_regex .").*?/i";
           
            $check_shortcode = preg_match_all($include_expression, $key, $inner_matches);
            if ( $check_shortcode == 0 ){
                continue;
            }
            /**
             * do not add non-Views shortcodes
             */
            if ( !preg_match('/^wpv/', $key ) ) {
                continue;
            }
            /**
             * add shortode to list
             */
            $fields['views-shortcodes']['fields'][$key] = array(
                'label' => $key,
                'slug' => sprintf('\'[%s]\'', $key),
                'type' => 'text',
            );
        }
        ksort($fields['views-shortcodes']['fields']);
    }

    /**
     * Custom Functions
     */
    if ( isset($options['wpv_custom_conditional_functions']) && !empty($options['wpv_custom_conditional_functions'] ) ) {
        foreach( $options['wpv_custom_conditional_functions'] as $key) {
            if ( empty($key) ) {
                continue;
            }
            $fields['custom-functions']['fields'][$key] = array(
                'label' => $key,
                'slug' => sprintf('%s()', $key),
                'type' => 'text',
            );
        }
    }

    /**
     * Custom Shortcodes
     */
    if ( isset($options['wpv_custom_inner_shortcodes']) && !empty($options['wpv_custom_inner_shortcodes'] ) ) {

        foreach( $options['wpv_custom_inner_shortcodes'] as $key) {
            if ( empty($key) ) {
                continue;
            }
            $fields['custom-shortcodes']['fields'][$key] = array(
                'label' => $key,
                'slug' => sprintf('\'[%s]\'', $key),
                'type' => 'text',
            );
        }
    }

    /**
     * remove empty sections
     */
    foreach( $fields as $key => $field ) {
        if ( empty($field['fields']) ) {
            unset($fields[$key]);
        }
    }

    /**
     * fields json
     */
    $fields = array(
        'labels' => array(
            'select_choose' => esc_html( __('-- Select origin --', 'wpv-views') ),
            'button_delete' => esc_html( __('Delete', 'wpv-views') ),
        ),
        'fields' => $fields,
    );

    foreach ( $fields['fields'] as $key => $data ) {
        if (empty($data) ) {
            unset($fields['fields'][$key]);
        }
    }

    $content .= '<script type="text/javascript">';
    $content .= sprintf('wpv_conditional_data = %s;',json_encode($fields));
    $content .= '</script>';
	$content .= '<span class="js-wpv-shortcode-gui-content"></span>';
    $content .= '<table id="js-wpv-conditionals" class="wpv-conditionals" data-field-name="wpv-conditional"><thead><tr>';
    $content .= sprintf('<th style="width:310px">%s</th>', __('Data origin', 'wpv-views'));
    $content .= sprintf('<th>%s</th>', __('Comparison', 'wpv-views'));
    $content .= sprintf('<th>%s</th>', __('Value', 'wpv-views'));
    $content .= sprintf('<th>%s</th>', __('Relationship', 'wpv-views'));
    $content .= '<th style="width:50px;text-align:right;">&nbsp</th></tr></thead>';
    $content .= sprintf('<tfoot><td colspan="5"><button class="button js-wpv-views-conditional-add-term" >%s</button></td></tr></tfoot>', __('Add another condition', 'wpv-views'));
    $content .= '<tbody class="js-wpv-views-conditional-body"></tbody>';
    $content .= '</table>';
    return $content;
}