Пример #1
0
function wpv_shortcodes_gui_load_post_field_section_on_demand() {
	global $WP_Views;
	$dialog_content = '';
	$cf_keys = $WP_Views->get_meta_keys();
	foreach ( $cf_keys as $cf_key ) {
		if ( ! wpv_is_types_custom_field( $cf_key ) ) {
			$dialog_content .= '<li class="item button button-small js-wpv-shortcode-gui-post-field-section-item" data-fieldkey="' . esc_attr( $cf_key ) . '">' . $cf_key . "</li>";
		}
	}
	$data = array(
		'section' => $dialog_content
	);
	wp_send_json_success( $data );
}
/**
*
* Add the short codes to javascript so they can be added to the post visual editor toolbar.
*
* $types contains the type of items to add to the toolbar
*
* 	'post' means all wpv-post shortcodes but wpv-post-field in the Basic section.
*	'post-fields-grouped' means non-Types custom fields in the Post field section.
*	'post-extended' means wpv-post-field and wpv-for-each shortcodes in the Basic section.
* 
* 	@important To be used only on native post edit screens:
*		'types-post' means Types custom fields and usermeta fields in their own groups.
*		'types-post-usermeta' means Types usermeta in their own groups.
* 	@important Note that for generic Types items, you can use the wpcf_filter_force_include_types_fields_on_views_dialog filter.
*
* 	'user' means all wpv-user shortcodes with a UserID selector
* 
* 	'body-view-templates' means a CT section listing all available CT.
*
* 	'view' means all available Views. DEPRECATED, use the other ones.
* 	'user-view' means Views listing users.
* 	'taxonomy-view' means Views listing terms.
* 	'post-view' means Views listing posts.
*
* 	'archives' means all WPAs - where is this being used? Nowhere!!
*
* 	'wpml' means some WPML-related shortcodes.
*/
function add_short_codes_to_js($types, $editor)
{
    global $wpv_shortcodes, $wpdb, $WP_Views, $sitepress;
    $views_shortcodes_with_api_obj = apply_filters('wpv_filter_wpv_shortcodes_gui_data', array());
    $views_shortcodes_with_api = array_keys($views_shortcodes_with_api_obj);
    $index = 0;
    $nonce = wp_create_nonce('wpv_editor_callback');
    foreach ($wpv_shortcodes as $shortcode) {
        if (in_array($shortcode[0], $views_shortcodes_with_api)) {
            $shortcode[3] = "WPViews.shortcodes_gui.wpv_insert_popup('" . $shortcode[0] . "', '" . $shortcode[1] . "', {}, '" . $nonce . "', this )";
        }
        if (in_array('post', $types) && strpos($shortcode[0], 'wpv-post-') === 0 && $shortcode[0] != 'wpv-post-field' && function_exists($shortcode[2])) {
            // All wpv-post-*** shortcodes but wpv-post-field
            if (isset($shortcode[3])) {
                $editor->add_insert_shortcode_menu($shortcode[1], $shortcode[0], __('Basic', 'wpv-views'), $shortcode[3]);
            } else {
                $editor->add_insert_shortcode_menu($shortcode[1], $shortcode[0], __('Basic', 'wpv-views'));
            }
            $index += 1;
        }
    }
    if (in_array('post-fields-placeholder', $types)) {
        $menu = __('Post field', 'wpv-views');
        $editor->add_insert_shortcode_menu('<i class="icon-plus-sign"></i> ' . __('Load non-Types custom fields', 'wpv-views'), '', $menu, "WPViews.shortcodes_gui.load_post_field_section_on_demand( event, this )");
        $index += 1;
    }
    if (in_array('post-fields-grouped', $types)) {
        $cf_keys = $WP_Views->get_meta_keys();
        foreach ($cf_keys as $cf_key) {
            if (!wpv_is_types_custom_field($cf_key)) {
                // add to the javascript array (text, function, sub-menu)
                $function_name = 'wpv_field_' . $index;
                $menu = __('Post field', 'wpv-views');
                $editor->add_insert_shortcode_menu($cf_key, 'wpv-post-field name="' . $cf_key . '"', $menu);
                $index += 1;
            }
        }
    }
    if (in_array('post-extended', $types)) {
        // Add the wpv-post-field just in case
        $editor->add_insert_shortcode_menu(__('Post field', 'wpv-views'), 'wpv-post-field', __('Basic', 'wpv-views'), "WPViews.shortcodes_gui.wpv_insert_popup('wpv-post-field', '" . __('Post field', 'wpv-views') . "', {}, '" . $nonce . "', this )");
        $index += 1;
        // Add the wpv-for-each iterator
        $editor->add_insert_shortcode_menu(__('Post field iterator', 'wpv-views'), 'wpv-for-each', __('Basic', 'wpv-views'), "WPViews.shortcodes_gui.wpv_insert_popup('wpv-for-each', '" . __('Post field iterator', 'wpv-views') . "', {}, '" . $nonce . "', this )");
        $index += 1;
    }
    /*
     * Note that the following two actions only have callbacks from Types on post.php and post-new.php
     * On Views and WPA edit screens, postmeta and usermeta items are added automatically by Types without needing to call them
     */
    if (in_array('types-post', $types)) {
        do_action('wpv_action_wpv_add_types_postmeta_to_editor', $editor);
    }
    if (in_array('types-post-usermeta', $types)) {
        do_action('wpv_action_wpv_add_types_post_usermeta_to_editor', $editor);
    }
    if (in_array('user', $types)) {
        $user_shortcodes = array('ID' => array('label' => __('User ID', 'wpv-views'), 'code' => 'wpv-user field="ID"'), 'user_email' => array('label' => __('User Email', 'wpv-views'), 'code' => 'wpv-user field="user_email"'), 'user_login' => array('label' => __('User Login', 'wpv-views'), 'code' => 'wpv-user field="user_login"'), 'user_firstname' => array('label' => __('First Name', 'wpv-views'), 'code' => 'wpv-user field="user_firstname"'), 'user_lastname' => array('label' => __('Last Name', 'wpv-views'), 'code' => 'wpv-user field="user_lastname"'), 'nickname' => array('label' => __('Nickname', 'wpv-views'), 'code' => 'wpv-user field="nickname"'), 'display_name' => array('label' => __('Display Name', 'wpv-views'), 'code' => 'wpv-user field="display_name"'), 'description' => array('label' => __('Description', 'wpv-views'), 'code' => 'wpv-user field="description"'), 'yim' => array('label' => __('Yahoo IM', 'wpv-views'), 'code' => 'wpv-user field="yim"'), 'jabber' => array('label' => __('Jabber', 'wpv-views'), 'code' => 'wpv-user field="jabber"'), 'aim' => array('label' => __('AIM', 'wpv-views'), 'code' => 'wpv-user field="aim"'), 'user_url' => array('label' => __('User URL', 'wpv-views'), 'code' => 'wpv-user field="user_url"'), 'user_registered' => array('label' => __('Registration Date', 'wpv-views'), 'code' => 'wpv-user field="user_registered"'), 'user_status' => array('label' => __('User Status', 'wpv-views'), 'code' => 'wpv-user field="user_status"'), 'spam' => array('label' => __('User Spam Status', 'wpv-views'), 'code' => 'wpv-user field="spam"'));
        foreach ($user_shortcodes as $u_shortcode_slug => $u_shortcode_data) {
            $editor->add_insert_shortcode_menu($u_shortcode_data['label'], $u_shortcode_data['code'], __('User basic data', 'wpv-views'), "WPViews.shortcodes_gui.wpv_insert_popup('wpv-user', '" . esc_js($u_shortcode_data['label']) . "', {field:{value:'" . $u_shortcode_slug . "',label:'" . esc_js($u_shortcode_data['label']) . "'}}, '" . $nonce . "', this )");
            $index += 1;
        }
    }
    // Content Templates
    if (in_array('body-view-templates', $types)) {
        $ct_objects = get_transient('wpv_transient_ct_published');
        if ($ct_objects === false) {
            global $pagenow;
            $values_to_prepare = array();
            $values_to_prepare[] = 'view-template';
            $values_to_exclude = array();
            $values_to_exclude_string = '';
            if (in_array($pagenow, array('post.php')) && isset($_GET["post"]) && is_numeric($_GET["post"])) {
                $values_to_exclude[] = (int) $_GET["post"];
            }
            if (isset($_GET["page"]) && 'ct-editor' == $_GET["page"] && isset($_GET["ct_id"]) && is_numeric($_GET["ct_id"])) {
                $values_to_exclude[] = (int) $_GET["ct_id"];
            }
            $exclude_loop_templates_ids = wpv_get_loop_content_template_ids();
            if (count($exclude_loop_templates_ids) > 0) {
                $exclude_loop_templates_ids_sanitized = array_map('esc_attr', $exclude_loop_templates_ids);
                $exclude_loop_templates_ids_sanitized = array_map('trim', $exclude_loop_templates_ids_sanitized);
                // is_numeric + intval does sanitization
                $exclude_loop_templates_ids_sanitized = array_filter($exclude_loop_templates_ids_sanitized, 'is_numeric');
                $exclude_loop_templates_ids_sanitized = array_map('intval', $exclude_loop_templates_ids_sanitized);
                if (count($exclude_loop_templates_ids_sanitized) > 0) {
                    $values_to_exclude = array_merge($values_to_exclude, $exclude_loop_templates_ids_sanitized);
                }
            }
            if (count($values_to_exclude) > 0) {
                $values_to_exclude_string = " AND ID NOT IN ('" . implode("','", $values_to_exclude) . "') ";
            }
            $view_template_available = $wpdb->get_results($wpdb->prepare("SELECT ID, post_title FROM {$wpdb->posts}\r\n\t\t\t\t\tWHERE post_type = %s\r\n\t\t\t\t\tAND post_status in ('publish')\r\n\t\t\t\t\t{$values_to_exclude_string}", $values_to_prepare));
            set_transient('wpv_transient_ct_published', $view_template_available, WEEK_IN_SECONDS);
        } else {
            $view_template_available = $ct_objects;
        }
        if (is_array($view_template_available)) {
            foreach ($view_template_available as $view_template) {
                $editor->add_insert_shortcode_menu(esc_html($view_template->post_title), 'wpv-post-body view_template="' . esc_html($view_template->post_title) . '"', __('Content Template', 'wpv-views'));
                $index += 1;
            }
        }
    }
    if (in_array('view', $types) || in_array('archives', $types) || in_array('user-view', $types) || in_array('taxonomy-view', $types) || in_array('post-view', $types)) {
        $views_objects = get_transient('wpv_transient_view_published');
        $views_objects_transient_to_update = array('archive' => array(), 'posts' => array(), 'taxonomy' => array(), 'users' => array());
        global $pagenow;
        $current_id = 0;
        if (in_array($pagenow, array('post.php')) && isset($_GET["post"])) {
            $current_id = (int) $_GET["post"];
        } else {
            if (in_array($pagenow, array('post-new.php'))) {
                global $post;
                $current_id = $post->ID;
            }
        }
        if ($views_objects === false) {
            $view_available = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->posts}\r\n\t\t\t\tWHERE post_type='view'\r\n\t\t\t\tAND post_status in ('publish')");
            foreach ($view_available as $view) {
                if ($WP_Views->is_archive_view($view->ID)) {
                    // Archive Views - add only if in_array( 'archives', $types )
                    if (in_array('archives', $types)) {
                        $editor->add_insert_shortcode_menu(esc_html($view->post_title), 'wpv-view name="' . esc_html($view->post_title) . '"', __('Archive', 'wpv-views'));
                        $index += 1;
                    }
                    $views_objects_transient_to_update['archive'][] = $view;
                } else {
                    $view_settings = get_post_meta($view->ID, '_wpv_settings', true);
                    $view_type = 'posts';
                    if (isset($view_settings['query_type'][0])) {
                        $view_type = $view_settings['query_type'][0];
                    }
                    if (in_array('user-view', $types) && $view_type == 'users') {
                        // Add Views listing users
                        $editor->add_insert_shortcode_menu(esc_html($view->post_title), 'wpv-view name="' . esc_html($view->post_title) . '"', __('User View', 'wpv-views'), 'WPViews.shortcodes_gui.wpv_insert_view_shortcode_dialog(\'' . $view->ID . '\', \'' . esc_js($view->post_title) . '\', \'' . $current_id . '\', \'' . $nonce . '\')');
                        $index += 1;
                    }
                    if (in_array('taxonomy-view', $types) && $view_type == 'taxonomy') {
                        // Add Views listing taxonomies
                        $editor->add_insert_shortcode_menu(esc_html($view->post_title), 'wpv-view name="' . esc_html($view->post_title) . '"', __('Taxonomy View', 'wpv-views'), 'WPViews.shortcodes_gui.wpv_insert_view_shortcode_dialog(\'' . $view->ID . '\', \'' . esc_js($view->post_title) . '\', \'' . $current_id . '\', \'' . $nonce . '\')');
                        $index += 1;
                    }
                    if (in_array('post-view', $types) && $view_type == 'posts') {
                        // Add Views listing posts
                        $editor->add_insert_shortcode_menu(esc_html($view->post_title), 'wpv-view name="' . esc_html($view->post_title) . '"', __('Post View', 'wpv-views'), 'WPViews.shortcodes_gui.wpv_insert_view_shortcode_dialog(\'' . $view->ID . '\', \'' . esc_js($view->post_title) . '\', \'' . $current_id . '\', \'' . $nonce . '\')');
                    }
                    $views_objects_transient_to_update[$view_type][] = $view;
                }
            }
            set_transient('wpv_transient_view_published', $views_objects_transient_to_update, WEEK_IN_SECONDS);
        } else {
            if (in_array('archives', $types) && isset($views_objects['archive']) && is_array($views_objects['archive'])) {
                foreach ($views_objects['archive'] as $view) {
                    $editor->add_insert_shortcode_menu(esc_html($view->post_title), 'wpv-view name="' . esc_html($view->post_title) . '"', __('Archive', 'wpv-views'));
                    $index += 1;
                }
            }
            if (in_array('post-view', $types) && isset($views_objects['posts']) && is_array($views_objects['posts'])) {
                foreach ($views_objects['posts'] as $view) {
                    $editor->add_insert_shortcode_menu(esc_html($view->post_title), 'wpv-view name="' . esc_html($view->post_title) . '"', __('Post View', 'wpv-views'), 'WPViews.shortcodes_gui.wpv_insert_view_shortcode_dialog(\'' . $view->ID . '\', \'' . esc_js($view->post_title) . '\', \'' . $current_id . '\', \'' . $nonce . '\')');
                }
            }
            if (in_array('taxonomy-view', $types) && isset($views_objects['taxonomy']) && is_array($views_objects['taxonomy'])) {
                foreach ($views_objects['taxonomy'] as $view) {
                    $editor->add_insert_shortcode_menu(esc_html($view->post_title), 'wpv-view name="' . esc_html($view->post_title) . '"', __('Taxonomy View', 'wpv-views'), 'WPViews.shortcodes_gui.wpv_insert_view_shortcode_dialog(\'' . $view->ID . '\', \'' . esc_js($view->post_title) . '\', \'' . $current_id . '\', \'' . $nonce . '\')');
                    $index += 1;
                }
            }
            if (in_array('user-view', $types) && isset($views_objects['users']) && is_array($views_objects['users'])) {
                foreach ($views_objects['users'] as $view) {
                    $editor->add_insert_shortcode_menu(esc_html($view->post_title), 'wpv-view name="' . esc_html($view->post_title) . '"', __('User View', 'wpv-views'), 'WPViews.shortcodes_gui.wpv_insert_view_shortcode_dialog(\'' . $view->ID . '\', \'' . esc_js($view->post_title) . '\', \'' . $current_id . '\', \'' . $nonce . '\')');
                    $index += 1;
                }
            }
        }
    }
    // @todo move this to the WPML file with dependency-free hooks
    if (in_array('wpml', $types)) {
        global $sitepress;
        if (isset($sitepress)) {
            $editor->add_insert_shortcode_menu(__('WPML lang switcher', 'wpv-views'), 'wpml-lang-switcher', 'WPML');
            $index += 1;
            global $icl_language_switcher;
            if (isset($icl_language_switcher)) {
                $editor->add_insert_shortcode_menu(__('WPML lang footer', 'wpv-views'), 'wpml-lang-footer', 'WPML');
                $index += 1;
            }
            global $iclCMSNavigation;
            if (isset($iclCMSNavigation)) {
                //$editor->add_insert_shortcode_menu('WPML breadcrumbs', 'wpml-breadcrumbs', 'WPML');
                //$index += 1;
                $editor->add_insert_shortcode_menu(__('WPML sidebar', 'wpv-views'), 'wpml-sidebar', 'WPML');
                $index += 1;
            }
        }
    }
    if (defined('WPSEO_VERSION')) {
        $editor->add_insert_shortcode_menu(__('Yoast SEO breadcrumbs', 'wpv-views'), 'yoast-breadcrumbs', 'Yoast SEO');
        $index += 1;
    }
    if (in_array('loop-wizard-for-posts', $types)) {
        do_action('wpv_action_wpv_add_field_on_loop_wizard_for_posts', $editor, $nonce);
    }
    if (in_array('loop-wizard-for-taxonomy', $types)) {
        do_action('wpv_action_wpv_add_field_on_loop_wizard_for_taxonomy', $editor, $nonce);
    }
    if (in_array('loop-wizard-for-users', $types)) {
        do_action('wpv_action_wpv_add_field_on_loop_wizard_for_users', $editor, $nonce);
    }
    return $index;
}
function wpv_filter_get_order_arg( $query, $view_settings ) {
	global $WP_Views;
    $orderby = $view_settings['orderby'];
	$order = $view_settings['order'];
	// Override with attributes
	$override_allowed = array(
		'orderby'	=> array(),
		'order'		=> array( 'asc', 'ASC', 'desc', 'DESC' )
	);
	$override_values = wpv_override_view_orderby_order( $override_allowed );
	if ( isset( $override_values['orderby'] ) ) {
		$orderby = $override_values['orderby'];
	}
	if ( isset( $override_values['order'] ) ) {
		$order = strtoupper( $override_values['order'] );
	}
	
	// Override with URL parameters
	
	/*
	* -------------
	* Order
	* -------------
	*/
	
	// Legacy order URL override
    if ( 
		isset( $_GET['wpv_order'] ) 
		&& isset( $_GET['wpv_view_count'] )
		&& isset( $_GET['wpv_order'][0] )
		&& in_array( $_GET['wpv_order'][0], array( 'ASC', 'DESC' ) )
	) {
        $order = esc_attr( $_GET['wpv_order'][0] );
    }
	// Modern order URL override
	if (
		isset( $_GET['wpv_column_sort_dir'] ) 
		&& isset( $_GET['wpv_view_count'] )
		&& esc_attr( $_GET['wpv_view_count'] ) == $WP_Views->get_view_count()
		&& in_array( strtoupper( esc_attr( $_GET['wpv_column_sort_dir'] ) ), array( 'ASC', 'DESC' ) )
	) {
        $order = strtoupper( esc_attr( $_GET['wpv_column_sort_dir'] ) );
    }
	
	/*
	* -------------
	* Orderby
	* -------------
	*/
	
    if (
		isset( $_GET['wpv_column_sort_id'] ) 
		&& isset( $_GET['wpv_view_count'] )
		&& esc_attr( $_GET['wpv_column_sort_id'] ) != 'undefined' 
		&& esc_attr( $_GET['wpv_column_sort_id'] ) != '' 
		&& esc_attr( $_GET['wpv_view_count'] ) == $WP_Views->get_view_count() 
	) {
        $orderby = esc_attr( $_GET['wpv_column_sort_id'] );
    }
    
	// Adjust values for custom field sorting
    
    if ( strpos( $orderby, 'field-' ) === 0 ) {
        // Natural Views sorting by custom field
        $query['meta_key'] = substr( $orderby, 6 );
        $orderby = 'meta_value';
    } else if ( strpos( $orderby, 'post-field' ) === 0 ) {
		// Table sorting for custom field
		$query['meta_key'] = substr( $orderby, 11 );
		$orderby = 'meta_value';
	} else if ( strpos( $orderby, 'types-field' ) === 0 ) {
		// Table sorting for Types custom field
		$query['meta_key'] = strtolower( substr( $orderby, 12 ) );
		$orderby = 'meta_value';
	} else {
		$orderby = str_replace( '-', '_', $orderby );
	}
	
	if ( 
		'meta_value' == $orderby 
		&& isset( $query['meta_key'] )
	) {
		$is_types_field_data = wpv_is_types_custom_field ( $query['meta_key'] );
		if ( 
			$is_types_field_data 
			&& isset( $is_types_field_data['meta_key'] ) 
			&& isset( $is_types_field_data['type'] )
		) {
			$query['meta_key'] = $is_types_field_data['meta_key'];
			if ( in_array( $is_types_field_data['type'], array( 'numeric', 'date' ) ) ) {
				$orderby = 'meta_value_num';
			}
		}		
	}
    
    // Correct orderby options
	switch ( $orderby ) {
		case 'post_link':
			$orderby = 'post_title';
			break;
		case 'post_body':
			$orderby = 'post_content';
			break;
		case 'post_slug':
			$orderby = 'name';
			break;
		case 'post_id':
		case 'id':
			$orderby = 'ID';
			break;
		default:
			if ( strpos( $orderby, 'post_' ) === 0 ) {
				$orderby = substr( $orderby, 5 );
			}
			break;
	}
	
	$query['orderby'] = $orderby;
	$query['order'] = $order;
	
    // See if filtering by custom fields and sorting by custom field too
    if (
		isset( $query['meta_key'] ) 
		&& isset( $query['meta_query'] )
	) {
		// We only need to do something if the relation is OR
		// When the relation is AND it does not matter if we sort by one of the filtering fields, because the filter will add an existence clause anyway
		// When the relation is OR, the natural query will generate an OR clause on the sorting field existence:
		// - if it is one of the filtering fields, it will make its clause useless because just existence will make it pass
		// - if it is not one of the filtering fields it will add an OR clause on this field existence that might pass for results that do not match any of the other requirements
		// See also: https://core.trac.wordpress.org/ticket/25538
		// Since WordPress 4.1 this is indeed not needed, thanks to nested meta_query entries
		if ( 
			isset( $query['meta_query']['relation'] ) 
			&& $query['meta_query']['relation'] == 'OR' 
		) {
			global $wp_version;
			if ( version_compare( $wp_version, '4.1', '<' ) ) {
				$refinedquery = $query;
				unset( $refinedquery['orderby'] );
				unset( $refinedquery['meta_key'] );
				$refinedquery['posts_per_page'] = -1; // remove the limit in the main query to get all the relevant IDs
				$refinedquery['fields'] = 'ids';
				// first query only for filtering
				$filtered_query = new WP_Query( $refinedquery );
				$filtered_ids = array();
				if ( 
					is_array( $filtered_query->posts ) 
					&& !empty( $filtered_query->posts ) 
				) {
					$filtered_ids = $filtered_query->posts;
				}
				// remove the fields filter from the original query and add the filtered IDs
				unset( $query['meta_query'] );
				// we can replace the $query['post__in'] argument because it was applied on the auxiliar query before
				if ( count( $filtered_ids ) ) {
					$query['post__in'] = $filtered_ids;
				} else {
					$query['post__in'] = array('0');
				}
			}
        }
        
    }
	
    return $query;
}
Пример #4
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;
}