/**
  * init function.
  *
  * @access public
  * @return void
  */
 public function init()
 {
     global $pagenow;
     //do your stuff only in the views edit page
     if ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'views-editor') {
         $this->initStatics();
         //append the button
         add_filter('wpv_meta_html_add_form_button_new', array($this, 'add_form_button'));
         //this is useless for me I added it only to try to debug Cred bug
         add_short_codes_to_js(array('post'), $this);
     }
 }
 /**
  * Add a view toolbar button to the editor of the view template
  *
  */
 function post_edit_tinymce()
 {
     global $post;
     if ($post->post_type == 'view-template') {
         $this->editor_addon = new Editor_addon('wpv-views', __('Insert Views Shortcode', 'wpv-views'), WPV_URL . '/res/js/views_editor_plugin.js', WPV_URL . '/res/img/bw_icon16.png');
         add_short_codes_to_js(array('post', 'view', 'view-form'), $this->editor_addon);
     }
 }
 /**
  * init function.
  *
  * @access public
  * @return void
  */
 public function init()
 {
     global $pagenow;
     // do your stuff only in the views edit page
     if ($pagenow == 'admin.php' && isset($_GET['page']) && $_GET['page'] == 'views-editor') {
         $this->initStatics();
         //append the button
         add_action('wpv_parametric_search_buttons', array($this, 'add_parametric_search_buttons'));
         // this is useless for me; I added it only to try to debug Cred bug
         // TODO should it be removed then?
         add_short_codes_to_js(array('post'), $this);
     }
 }
Exemple #4
0
function view_layout_fields($post, $view_layout_settings)
{
    global $WP_Views;
    $view_settings = $WP_Views->get_view_settings($post->ID);
    if (isset($view_layout_settings['fields'])) {
        $view_layout_settings['fields'] = view_layout_fields_to_classes($view_layout_settings['fields']);
    } else {
        $view_layout_settings['fields'] = array();
    }
    view_layout_javascript();
    global $WPV_templates;
    $template_selected = 0;
    foreach ($view_layout_settings['fields'] as $field) {
        $posible_template = $field->get_body_template();
        if ($posible_template >= 0) {
            $template_selected = $posible_template;
            break;
        }
    }
    // Add a select control so that we can chose the view template for the body.
    $view_template_select_box = $WPV_templates->get_view_template_select_box('', '');
    $view_template_select_box = '<div id="views_template_body" style="display:none;"><i> - ' . __('Using View template:', 'wpv-views') . '</i>' . $view_template_select_box . '</div>';
    // Add a select control so that we can chose the Taxonomy View.
    $taxonomy_view_select_box = $WP_Views->get_add_field_view_select_box('', '', 'taxonomy');
    $taxonomy_view_select_box = '<div id="taxonomy_view_select" style="display:none;"">' . $taxonomy_view_select_box . '</div>';
    // Add a select control so that we can chose the Post View.
    $post_view_select_box = $WP_Views->get_add_field_view_select_box('', '', 'post');
    $post_view_select_box = '<div id="post_view_select" style="display:none;"">' . $post_view_select_box . '</div>';
    ?>
    
    <div id="view_layout_fields" class="view_layout_fields">
        
        <p id="view_layout_fields_to_include"><strong><?php 
    echo __('Fields to include:', 'wpv-views');
    ?>
</strong></p>
        
        <?php 
    echo $view_template_select_box;
    ?>
        <?php 
    echo $taxonomy_view_select_box;
    ?>
        <?php 
    echo $post_view_select_box;
    ?>
        
        <p id="view_layout_add_field_message_1"><?php 
    echo __("Click on <strong>Add field</strong> to insert additional fields. Drag them to reorder, or delete fields that you don't need.", 'wpv-views');
    ?>
</p>
        <p id="view_layout_add_field_message_2" style="display:none"><?php 
    echo __("Click on <strong>Add field</strong> to insert fields to this View.", 'wpv-views');
    ?>
</p>
        
        <table id="view_layout_fields_table" class="widefat fixed">
            <thead>
                <tr>
                    <th width="20px"></th><th width="120px"><?php 
    echo __('Prefix', 'wpv-views');
    ?>
</th><th width="220px"><?php 
    echo __('Field', 'wpv-views');
    ?>
</th><th class="row-title hidden" width="120px"><?php 
    echo __('Row Title', 'wpv-views');
    ?>
</th><th width="120px"><?php 
    echo __('Suffix', 'wpv-views');
    ?>
</th><th width="16px"></th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th></th><th></th><th></th><th class="row-title hidden"></th><th></th><th></th>
                </tr>
            </tfoot>
            
            <tbody>
                <?php 
    $count = sizeof($view_layout_settings['fields']);
    foreach ($view_layout_settings['fields'] as $index => $field) {
        ?>
                    <tr id="wpv_field_row_<?php 
        echo $index;
        ?>
" <?php 
        echo $field->render_table_row_attributes($view_settings);
        ?>
>
                    
                        <td width="20px"><img src="<?php 
        echo WPV_URL . '/res/img/delete.png';
        ?>
" onclick="on_delete_wpv(<?php 
        echo $index;
        ?>
)" style="cursor: pointer" /></td><?php 
        $field->render_to_table($index);
        ?>
<td width="16px"><img src="<?php 
        echo WPV_URL;
        ?>
/res/img/move.png" class="move" style="cursor: move;" /></td>
                    
                    </tr>
                    <?php 
    }
    ?>
            </tbody>
        
        </table>
        <br />
    </div>
    
    <?php 
    $show = $view_settings['query_type'][0] == 'posts';
    ?>
    <input class="button-secondary wpv_add_fields_button" type="button" value="<?php 
    echo __('Add field', 'wpv-views');
    ?>
" name="wpv-layout-add-field" <?php 
    if ($show) {
        echo '';
    } else {
        echo ' style="display:none"';
    }
    ?>
 />
    <div id="add_field_popup" style="display:none; overflow: auto;">

        <?php 
    global $link_layout_number;
    $link_layout_number = 0;
    $WP_Views->editor_addon->add_form_button('', 'wpv_layout_meta_html_content', false);
    ?>

    </div>  

	<?php 
    // echo $WP_Views->editor_addon->add_form_button('', '#wpv_layout_meta_html_content', false);
    ?>
    <?php 
    // Add a popup for taxonomy fields
    ?>
    
    <div id="add_taxonomy_field_popup" style="display:none">

        <table id="wpv_taxonomy_field_popup_table" width="100%">
        <tr>
        <?php 
    global $link_layout_number;
    $link_layout_number = 0;
    add_short_codes_to_js(array('taxonomy', 'taxonomy-view', 'post-view'), null, 'short_code_taxonomy_menu_callback');
    ?>
        </tr>
        </table>

    </div>  

    <script type="text/javascript">
        var wpv_shortcodes = new Array();
        <?php 
    $current_index = add_short_codes_to_js(array('post', 'taxonomy', 'taxonomy-view', 'post-view'), null, 'short_code_variable_callback');
    ?>
        wpv_shortcodes[<?php 
    echo $current_index++;
    ?>
] = new Array('Taxonomy View', '<?php 
    echo WPV_TAXONOMY_VIEW;
    ?>
');
        wpv_shortcodes[<?php 
    echo $current_index++;
    ?>
] = new Array('Post View', '<?php 
    echo WPV_POST_VIEW;
    ?>
');
        <?php 
    if (defined('WPV_WOOCOMERCE_VIEWS_SHORTCODE')) {
        ?>
        wpv_shortcodes[<?php 
        echo $current_index;
        ?>
] = new Array('Add to cart button', '<?php 
        echo WPV_WOOCOMERCE_VIEWS_SHORTCODE;
        ?>
');
        <?php 
    }
    ?>
        var wpv_view_template_text = "<?php 
    echo __('View template', 'wpv-views');
    ?>
";
        var wpv_taxonomy_view_text = "<?php 
    echo __('Taxonomy View', 'wpv-views');
    ?>
";
        var wpv_post_view_text = "<?php 
    echo __('Post View', 'wpv-views');
    ?>
";
        var wpv_add_field_text = "<?php 
    echo __('Field', 'wpv-views');
    ?>
";
        var wpv_add_taxonomy_text = "<?php 
    echo __('Taxonomy', 'wpv-views');
    ?>
";
    </script>
    <?php 
    $show = $view_settings['query_type'][0] == 'taxonomy';
    ?>
    <input alt="#TB_inline?inlineId=add_taxonomy_field_popup" class="thickbox button-secondary wpv_add_taxonomy_fields_button" type="button" value="<?php 
    echo __('Add field', 'wpv-views');
    ?>
" name="Add a taxonomy field" <?php 
    if ($show) {
        echo '';
    } else {
        echo ' style="display:none"';
    }
    ?>
 />
    
    <?php 
    $show = $view_settings['query_type'][0] == 'posts' ? '' : 'style="display:none"';
    ?>
    <span id="wpv-layout-help-posts" <?php 
    echo $show;
    ?>
><i><?php 
    echo __('Want to add complex fields?', 'wpv-views') . '&nbsp;' . '<a class="wpv-help-link" href="http://wp-types.com/user-guides/using-a-view-template-in-a-view-layout/" target="_blank">' . __('Learn about using View Templates to customize fields.', 'wpv-views') . ' &raquo;</a>';
    ?>
</i></span>
    <?php 
    $show = $view_settings['query_type'][0] == 'taxonomy' ? '' : 'style="display:none"';
    ?>
    <span id="wpv-layout-help-taxonomy" <?php 
    echo $show;
    ?>
><i><?php 
    echo sprintf(__('Want to display posts that belong to this taxonomy? Learn about %sinserting child Views to Taxonomy Views%s.', 'wpv-views'), '<a href="http://wp-types.com/user-guides/using-a-child-view-in-a-taxonomy-view-layout/" target="_blank">', ' &raquo;</a>');
    ?>
</i></span>

    <?php 
    // Warn if Types is less than 1.0.2
    // We need at least 1.0.2 for the Types popups to work when adding fields.
    if (defined('WPCF_VERSION') && version_compare(WPCF_VERSION, '1.0.2', '<')) {
        echo '<br /><p style="color:red;"><strong>';
        _e('* Views requires Types 1.0.2 or greater for best results when adding fields.', 'wpv-views');
        echo '</strong></p>';
    }
    ?>

    
    <?php 
}
 /**
  * Add the view button to the toolbar of required edit pages.
  *
  * Also force the view editor to be in HTML mode.
  *
  */
 function post_edit_tinymce()
 {
     global $post;
     if ($post->post_type != 'view-template') {
         $this->editor_addon = new Editor_addon('wpv-views', __('Insert Views Shortcode', 'wpv-views'), WPV_URL . '/res/js/views_editor_plugin.js', WPV_URL . '/res/img/bw_icon16.png');
     }
     if ($post->post_type == 'view') {
         add_short_codes_to_js(array('post'), $this->editor_addon);
     }
     if ($post->post_type != 'view' && $post->post_type != 'view-template') {
         // add tool bar to other edit pages so they can insert the view shortcodes.
         add_short_codes_to_js(array('view', 'view-form', 'wpml'), $this->editor_addon, 'add-basics');
     }
 }
 /**
  * add_dialog_to_editors
  *
  * Add the Fields and Views button to the edit pages
  *
  * @since unknown
  */
 function add_dialog_to_editors()
 {
     global $post;
     if (is_object($post) === false) {
         return;
     }
     $this->editor_addon = new WPV_Editor_addon('wpv-views', __('Insert Views Shortcodes', 'wpv-views'), WPV_URL . '/res/js/views_editor_plugin.js', '', true, 'icon-views-logo ont-icon-18 ont-color-gray');
     add_short_codes_to_js(array('post', 'post-extended', 'post-fields-placeholder', 'types-post', 'types-post-usermeta', 'user', 'post-view', 'taxonomy-view', 'user-view', 'body-view-templates', 'wpml'), $this->editor_addon);
 }
function wpv_loop_wizard_get_available_field_menus( $view_id ) {
	global $WP_Views;
	$view_settings = $WP_Views->get_view_settings( $view_id );
	
	static $menus_for_what = array();
	
	$menus_for = 'posts';
	if ( 
		isset( $view_settings['query_type'][0] ) 
		&& $view_settings['query_type'][0] == 'taxonomy' 
	) {
		$menus_for = 'taxonomy';
	} else if (
		isset( $view_settings['query_type'][0] ) 
		&& $view_settings['query_type'][0] == 'users' 
	) {
		$menus_for = 'users';
	}
	
	if ( isset( $menus_for_what[$menus_for] ) ) {
		return $menus_for_what[$menus_for];
	}
	
	$menus = array();
	$menus_entries = array();
	
	switch ( $menus_for ) {
		case 'taxonomy':
		case 'users':
			$menus_entries = array(
				'post-view', 
				'taxonomy-view', 
				'user-view'
			);
			break;
		default:
			$menus_entries = array(
				'post',
				'post-fields-grouped',
				'post-view', 
				'user', 
				'taxonomy-view', 
				'user-view',
				'body-view-templates'
			);
			break;
	}
	
	$menus_entries[] = 'loop-wizard-for-' . $menus_for;

	$WP_Views->editor_addon = new WPV_Editor_addon(
		'wpv-views',
		__('Insert Views Shortcodes', 'wpv-views'),
		WPV_URL . '/res/js/views_editor_plugin.js',
		WPV_URL_EMBEDDED . '/res/img/views-icon-black_16X16.png'
	);

	add_short_codes_to_js( 
		$menus_entries, 
		$WP_Views->editor_addon 
	);

	$fields_list = $WP_Views->editor_addon->get_fields_list();
	
	if ( $fields_list ) {
		foreach ( $fields_list as $item ) {
			if ( ! isset( $menus[$item[2]] ) ) {
				$menus[$item[2]] = array();
			}
			$menus[$item[2]][$item[0]] = $item;
		}
	}

	if ( $menus_for == 'posts' ) {
		do_action( 'wpv_action_wpv_add_types_postmeta_usermeta_to_editor_menus' );
		// Backwards compatibility - this is available as of now, before a Types update
		// @todo remove this once Types gets an update
		do_action( 'views_ct_inline_editor' );
	} else if ( $menus_for == 'taxonomy' ) {
		remove_filter( 'editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11 );
		add_filter( 'editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V', 30 );
	} else if ( $menus_for == 'users' ) {
		remove_filter( 'editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11 );
		add_filter( 'editor_addon_menus_wpv-views', 'wpv_layout_users_V', 30 );
	}
	
	// Apply filters
	$menus = apply_filters( 'editor_addon_menus_wpv-views', $menus );
	// Sort menus
	if ( is_array( $menus ) ) {
		$menus = $WP_Views->editor_addon->sort_menus( $menus );
	}
	
	if ( $menus_for == 'taxonomy' ) {
		remove_filter( 'editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V', 30 );
		add_filter( 'editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11 );
	} else if ( $menus_for == 'users' ) {
		remove_filter( 'editor_addon_menus_wpv-views', 'wpv_layout_users_V', 30 );
		add_filter( 'editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11 );
	}
	
	$menus_for_what[$menus_for] = $menus;
	
	return $menus_for_what[$menus_for];
}
Exemple #8
0
	/**
	* add_dialog_to_editors
	*
	* Add the Fields and Views button to the edit pages
	*
	* @since unknown
	*/
	function add_dialog_to_editors() {
		global $post;

		if ( is_object( $post ) === false ) {
			return;
		}

		$this->editor_addon = new WPV_Editor_addon(
			'wpv-views',
			__( 'Insert Views Shortcodes', 'wpv-views' ),
			WPV_URL . '/res/js/views_editor_plugin.js',
			'',
			true,
			'icon-views-logo ont-icon-18 ont-color-gray' 
		);

		add_short_codes_to_js( 
			array( 
				'post', 					// wpv-post-** shortcodes plus non-Types custom fields
				'post-extended',			// generic shortcodes extended in the Basic section
				'post-fields-placeholder',	// non-Types fields on demand
				'types-post',				// Types custom fields
				'types-post-usermeta',		// Types usermeta fields
				'user',						// basic user data
				'post-view',				// all available Views listing posts
				'taxonomy-view',			// all available Views listing terms
				'user-view',				// all available Views listing users
				'body-view-templates',		// all available CT
				'wpml'						// WPML-related shortcodes
			), 
			$this->editor_addon 
		);
			
	}
function wpv_layout_wizard_add_field()
{
    // TODO this might need localization TODO this is seriously broken
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'layout_wizard_nonce')) {
        die("Undefined Nonce.");
    }
    global $WP_Views, $wpdb;
    $settings = $WP_Views->get_view_settings($_POST["view_id"]);
    $WP_Views->editor_addon = new Editor_addon('wpv-views', __('Insert Views Shortcodes', 'wpv-views'), WPV_URL . '/res/js/views_editor_plugin.js', WPV_URL . '/res/img/bw_icon16.png');
    if ((string) $settings["query_type"][0] == 'posts') {
        add_short_codes_to_js(array('body-view-templates', 'post', 'taxonomy', 'post-view', 'taxonomy-view', 'user-view'), $WP_Views->editor_addon);
    } else {
        if ((string) $settings["query_type"][0] == 'taxonomy') {
            add_short_codes_to_js(array('post-view', 'taxonomy-view', 'user-view'), $WP_Views->editor_addon);
        } else {
            if ((string) $settings["query_type"][0] == 'users') {
            }
        }
    }
    $fields_list = $WP_Views->editor_addon->get_fields_list();
    if (empty($fields_list)) {
        $fields_list = array();
    }
    $fields_accos = array();
    // Show taxonomy fields only if we are in Taxonomy mode
    if ((string) $settings["query_type"][0] == 'taxonomy') {
        $tax_fields = array();
        $tax_fields[__('Taxonomy title', 'wpv-views')] = 'wpv-taxonomy-title';
        $tax_fields[__('Taxonomy title with a link', 'wpv-views')] = 'wpv-taxonomy-link';
        $tax_fields[__('Taxonomy URL', 'wpv-views')] = 'wpv-taxonomy-url';
        $tax_fields[__('Taxonomy slug', 'wpv-views')] = 'wpv-taxonomy-slug';
        $tax_fields[__('Taxonomy description', 'wpv-views')] = 'wpv-taxonomy-description';
        $tax_fields[__('Taxonomy post count', 'wpv-views')] = 'wpv-taxonomy-post-count';
        foreach ($tax_fields as $name => $value) {
            $fields_accos[__('Taxonomy fields', 'wpv-views')][] = array($name, $value);
        }
    }
    if ((string) $settings["query_type"][0] == 'users') {
        $user_fields = array();
        $user_fields[__('User ID', 'wpv-views')] = 'wpv-user field="ID"';
        $user_fields[__('User Email', 'wpv-views')] = 'wpv-user field="user_email"';
        $user_fields[__('User Login', 'wpv-views')] = 'wpv-user field="user_login"';
        $user_fields[__('First Name', 'wpv-views')] = 'wpv-user field="user_firstname"';
        $user_fields[__('Last Name', 'wpv-views')] = 'wpv-user field="user_lastname"';
        $user_fields[__('Nickname', 'wpv-views')] = 'wpv-user field="nickname"';
        $user_fields[__('Display Name', 'wpv-views')] = 'wpv-user field="display_name"';
        $user_fields[__('Description', 'wpv-views')] = 'wpv-user field="description"';
        $user_fields[__('Yahoo IM', 'wpv-views')] = 'wpv-user field="yim"';
        $user_fields[__('Jabber', 'wpv-views')] = 'wpv-user field="jabber"';
        $user_fields[__('AIM', 'wpv-views')] = 'wpv-user field="aim"';
        $user_fields[__('User Url', 'wpv-views')] = 'wpv-user field="user_url"';
        $user_fields[__('Registration Date', 'wpv-views')] = 'wpv-user field="user_registered"';
        $user_fields[__('User Status', 'wpv-views')] = 'wpv-user field="user_status"';
        $user_fields[__('User Spam Status', 'wpv-views')] = 'wpv-user field="spam"';
        foreach ($user_fields as $name => $value) {
            $fields_accos[__('Basic', 'wpv-views')][] = array($name, $value);
        }
        $unused_field = array('comment_shortcuts', 'managenav-menuscolumnshidden', 'dismissed_wp_pointers', 'meta-box-order_dashboard', 'nav_menu_recently_edited', 'primary_blog', 'rich_editing', 'source_domain', 'use_ssl', 'user_level', 'user-settings-time', 'user-settings', 'dashboard_quick_press_last_post_id', 'capabilities', 'new_date', 'show_admin_bar_front', 'show_welcome_panel', 'show_highlight', 'admin_color', 'language_pairs', 'first_name', 'last_name', 'name', 'nickname', 'description', 'yim', 'jabber', 'aim');
        $exclude_these_hidden_var = '/(' . implode('|', $unused_field) . ')/';
        $meta_keys = get_user_meta_keys();
        $all_types_fields = get_option('wpcf-fields', array());
        foreach ($meta_keys as $key) {
            $key_nicename = '';
            if (function_exists('wpcf_init')) {
                if (stripos($key, 'wpcf-') === 0) {
                    //
                } else {
                    if (preg_match($exclude_these_hidden_var, $key)) {
                        continue;
                    }
                    $fields_accos[__('Users fields', 'wpv-views')][] = array($key, 'wpv-user field="' . $key . '"');
                }
            } else {
                if (preg_match($exclude_these_hidden_var, $key)) {
                    continue;
                }
                $fields_accos[__('Users fields', 'wpv-views')][] = array($key, 'wpv-user field="' . $key . '"');
            }
        }
        if (function_exists('wpcf_init')) {
            // TODO do the same for wpcf-fields for posts
            //Get types groups and fields
            $groups = wpcf_admin_fields_get_groups('wp-types-user-group');
            $user_id = wpcf_usermeta_get_user();
            $add = array();
            if (!empty($groups)) {
                foreach ($groups as $group_id => $group) {
                    if (empty($group['is_active'])) {
                        continue;
                    }
                    $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, 'wp-types-user-group', 'wpcf-usermeta');
                    if (!empty($fields)) {
                        foreach ($fields as $field_id => $field) {
                            $add[] = $field['meta_key'];
                            $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', -1)';
                            /*$this->items[] = array($field['name'], 
                              'types usermeta="'.$field['meta_key'].'"][/types',
                              $group['name'],$callback);  */
                            $fields_accos[$group['name']][] = array($field['name'], 'types usermeta="' . $field['slug'] . '"][/types');
                        }
                    }
                }
            }
            //Get unused types fields
            $cf_types = wpcf_admin_fields_get_fields(true, true, false, 'wpcf-usermeta');
            foreach ($cf_types as $cf_id => $cf) {
                if (!in_array($cf['meta_key'], $add)) {
                    $callback = 'wpcfFieldsEditorCallback(\'' . $cf['id'] . '\', \'views-usermeta\', -1)';
                    /* $this->items[] = array($cf['name'], 
                       'types usermeta="'.$cf['meta_key'].'"][/types',
                       'Types fields',$callback); */
                    $fields_accos[__('Types fields', 'wpv-views')][] = array($cf['name'], 'types usermeta="' . $cf['slug'] . '"][/types');
                }
            }
        }
        $view_available = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type='view' AND post_status in ('publish')");
        $fields_accos[__('Types fields', 'wpv-views')] = array();
        foreach ($view_available as $view) {
            $view_settings = get_post_meta($view->ID, '_wpv_settings', true);
            if (isset($view_settings['query_type'][0]) && $view_settings['query_type'][0] == 'posts' && !$WP_Views->is_archive_view($view->ID)) {
                $fields_accos[__('Post View', 'wpv-views')][] = array($view->post_title, 'wpv-view name="' . $view->post_title . '"');
            }
        }
    }
    $content_templates = array('Content template' => array(array('None', 'wpv-post-body view_template="None"')));
    if (function_exists('types_get_fields')) {
        $tmp = types_get_fields();
    } else {
        $tmp = array();
    }
    if (isset($tmp['fields'])) {
        $tmp = $tmp['fields'];
    }
    foreach ($fields_list as $items) {
        if (function_exists('wpcf_admin_fields_get_groups_by_field') && (preg_match('/-!-wpcf/', $items[2]) || preg_match('/-!-views/', $items[2]) || preg_match('/wpcf-/', $items[0]) || preg_match('/\\[types.*?field=\\"(.*?)\\"/', $items[0]))) {
            if (preg_match('/\\[types.*?field=\\"(.*?)\\"/', $items[0], $outp)) {
                $split = $outp[1];
            } else {
                $split = preg_replace('/wpcf-/', '', $items[0]);
            }
            //Field name, not a slug
            if (isset($tmp[$split]['name'])) {
                // if: fix PHP Notice in the AJAX response when showing hidden fields
                $items[0] = $tmp[$split]['name'];
                $group = wpcf_admin_fields_get_groups_by_field($tmp[$split]['id']);
                foreach ($group as $id => $params) {
                    $group = $params['name'];
                }
            }
        } else {
            if ($items[2] == 'Field' || strpos($items[2], 'Field') === 0) {
                $items[2] = 'Custom fields';
            }
            $group = $items[2];
        }
        if ($items[2] == __('Content template', 'wpv-views')) {
            //    global $wpdb;
            //  $items[0] = $wpdb->get_var("SELECT post_title  FROM {$wpdb->posts} WHERE post_title = '{$items[0]}'");
            $content_templates['Content template'][] = array($items[0], $items[1]);
        }
        if ($items[1] == 'wpml-string') {
            // Take out of the Layout Wizard the new wpml-string Translatable string shortcode added to V popups
            $group = '';
        }
        if (!empty($group)) {
            $fields_accos[$group][] = array($items[0], $items[1]);
        }
    }
    if ((string) $settings["query_type"][0] == 'posts') {
        // add taxonomies
        $assoc = array();
        $taxonomies = get_taxonomies(array(), 'objects');
        $exclude_tax_slugs = array();
        $exclude_tax_slugs = apply_filters('wpv_admin_exclude_tax_slugs', $exclude_tax_slugs);
        foreach ($taxonomies as $tname => $tax) {
            if (!in_array($tname, $exclude_tax_slugs) && $tax->show_ui) {
                $assoc['Taxonomies'][] = array($tax->label, 'wpv-post-taxonomy type="' . $tname . '" separator=", " format="link" show="name"');
            }
        }
        // add user meta fields
        if (function_exists('wpcf_admin_post_add_usermeta_to_editor_js')) {
            $usermeta_fields_list = wpcf_admin_post_add_usermeta_to_editor_js(array());
            foreach ($usermeta_fields_list as $group => $items) {
                foreach ($items as $field) {
                    $assoc[$group][] = array($field[0], $field[1]);
                }
            }
        }
        // Add after the Basic fields.
        $fields_accos = array_slice($fields_accos, 0, 1, true) + $assoc + array_slice($fields_accos, 1, count($fields_accos) - 1, true);
    }
    ob_start();
    ?>
<li id="layout-wizard-style_<?php 
    echo isset($_POST['id']) ? $_POST['id'] : $count;
    ?>
">
    <i class="icon-move js-layout-wizard-move-field"></i>
    <select name="layout-wizard-style" class="js-select2 js-layout-wizard-item">
        <?php 
    $selected_value = '';
    $typename = '';
    $selected_body = '';
    $selected_body_template = '';
    $selected_found = false;
    $user_fields_with_head = array('user_email', 'display_name', 'user_login', 'user_url', 'user_registered', 'user_status', 'spam');
    if (!isset($_POST['selected'])) {
        $_POST['selected'] = '';
    }
    foreach ($fields_accos as $group_title => $group_items) {
        ?>
            <optgroup label="<?php 
        echo $group_title;
        ?>
">
                <?php 
        foreach ($group_items as $items) {
            $value = $items[1];
            $istype = false;
            $typename2 = '';
            $selected = mysql_real_escape_string($_POST['selected']) == '[' . mysql_real_escape_string($items[1]) . ']' ? "selected" : "";
            $selected_striped = substr(stripslashes($_POST['selected']), 1, -1);
            if ($selected_striped == stripslashes($value)) {
                // Dirty hack: sometimes the selected item was not being set for user shortcodes
                $selected = "selected";
                if (preg_match('/\\[types.*usermeta=\\"(.*?)\\"/', $_POST['selected'], $outp)) {
                    $typename = $outp[1];
                }
            }
            $_POST['selected'] = stripslashes($_POST['selected']);
            if (!$selected && preg_match('/wpv-post-taxonomy/', $items[1]) && trim($_POST['selected'], '[]') == $items[1]) {
                $selected = 'selected';
            }
            if (!$selected && preg_match('/wpv-view/', $items[1]) && trim($_POST['selected'], '[]') == $items[1]) {
                $selected = 'selected';
            }
            if (!$selected && preg_match('/\\[types.*?field=\\"(.*?)\\"/', $_POST['selected']) && preg_match('/"wpcf\\-.*?"/', $items[1])) {
                preg_match('/\\[types.*?field=\\"(.*?)\\"/', $_POST['selected'], $outp);
                $sel = $outp[1];
                preg_match('/"wpcf\\-(.*?)"/', $items[1], $outp);
                $cur = $outp[1];
                $items[1] = trim($_POST['selected'], '[]');
                $selected = $cur == $sel ? 'selected' : '';
                $typename = $sel;
            }
            if (!$selected && preg_match('/\\[types.*usermeta=\\"(.*?)\\"/', $_POST['selected']) && preg_match('/types.*usermeta=\\"(.*?)\\"/', $items[1])) {
                preg_match('/\\[types.*usermeta=\\"(.*?)\\"/', $_POST['selected'], $outp);
                $sel = $outp[1];
                preg_match('/types.*usermeta=\\"(.*?)\\"/', $items[1], $outp);
                $cur = $outp[1];
                $usermeta_field = $sel;
                $items[1] = trim($_POST['selected'], '[]');
                $selected = $cur == $sel ? 'selected' : '';
                if ($selected) {
                    $value = $items[1];
                }
                $typename = $sel;
                $typename2 = $cur;
                $istype = true;
            }
            if (!$selected && preg_match('/wpv-post-body/', $_POST['selected']) && preg_match('/Body/', $items[0])) {
                $selected_body = $items[0];
                preg_match('/view_template\\="(.*?)"/', $_POST['selected'], $out);
                $selected_body_template = $out[1];
                global $wpdb;
                $selected_body_template = $wpdb->get_var("SELECT post_title FROM {$wpdb->posts} WHERE post_name = '{$selected_body_template}'");
                //     $value = trim($_POST['selected'], '[]');
                //     if (!$selected_body_template) {
                //     $value = $items[1];
                //     }
                $selected = 'selected';
            }
            if ($selected == 'selected') {
                $selected_value = $items[1];
                $selected_found = true;
            }
            $s = preg_match('/"wpcf\\-(.*?)"/', $value, $outp);
            if ($s) {
                $saved_fields = array();
                $sets = get_post_meta($_POST["view_id"], '_wpv_layout_settings', true);
                if (isset($sets["real_fields"])) {
                    $saved_fields = $sets["real_fields"];
                }
                $typename2 = $outp[1];
                $value = isset($saved_fields[$_POST["id"]]) && preg_match('/types.*?field=\\"' . $outp[1] . '\\"/', $saved_fields[$_POST["id"]]) ? trim($saved_fields[$_POST["id"]], '[]') : 'types field="' . $outp[1] . '" id=""][/types';
                $istype = true;
                if (!function_exists('wpcf_init')) {
                    $istype = false;
                    if (strpos($items[1], 'wpv-user') === 0) {
                        $value = $items[1];
                    } else {
                        $value = 'wpv-post-field name="wpcf-' . $outp[1] . '"';
                    }
                }
            }
            $head = '';
            if (substr($value, 0, 17) === "wpv-post-taxonomy") {
                $head = 'wpv-post-taxonomy';
            } else {
                if (substr($value, 0, 14) === "wpv-post-field") {
                    $head = 'post-field-' . $items[0];
                    // if it is a new WooCommerce Views field
                    if (preg_match('/\\wpv-post-field.*?name=\\"views_woo(.*?)\\"/', $value, $woo_match)) {
                        $head = 'post-field-views_woo' . $woo_match[1];
                    }
                } else {
                    if (substr($value, 0, 8) === "wpv-post") {
                        $head = substr(current(explode(' ', $value)), 4);
                        if (substr($value, 0, 15) === "wpv-post-status" || substr($value, 0, 14) === "wpv-post-class") {
                            $head = '';
                        }
                    } else {
                        if (substr($value, 0, 8) === "wpv-view") {
                            $head = 'post-view';
                        } else {
                            if (substr($value, 0, 5) === "types") {
                                if (!isset($outp[1]) && isset($usermeta_field)) {
                                    $outp[1] = $usermeta_field;
                                } else {
                                    if (!isset($outp[1])) {
                                        $outp[1] = '';
                                    }
                                }
                                if (empty($typename2)) {
                                    $typename2 = $outp[1];
                                }
                                $head = 'types-field-' . $outp[1];
                                // Add a table column header only if it's a field for posts
                                if (empty($typename2) || empty($outp[1])) {
                                    preg_match("/(usermeta|field)=\"([^\"]+)\"/", $value, $new_match);
                                    $typename2 = $outp[1] = $new_match[2];
                                    $head = '';
                                    // If it's a usermeta field, do not add the table column header
                                }
                                if (!empty($typename2)) {
                                    $istype = true;
                                }
                            } else {
                                if (substr($value, 0, 12) === "wpv-taxonomy") {
                                    // heading table solumns for wpv-taxonomy-* shortcodes
                                    if (in_array($value, array('wpv-taxonomy-link', 'wpv-taxonomy-title'))) {
                                        $head = substr($value, 4);
                                    }
                                    if ($value == 'wpv-taxonomy-post-count') {
                                        $head = 'taxonomy-post_count';
                                    }
                                } else {
                                    if (substr($value, 0, 8) === "wpv-user") {
                                        // heaading table columns for wpv-user shortcodes
                                        preg_match('/\\wpv-user.*?field=\\"(.*?)\\"/', $value, $new_match);
                                        if (isset($new_match[1]) && in_array($new_match[1], $user_fields_with_head)) {
                                            $head = $new_match[1];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ?>
                    <option value="<?php 
            echo base64_encode('[' . $value . ']');
            ?>
"
                            data-fieldname="<?php 
            echo $items[0];
            ?>
"
                            data-headename="<?php 
            echo $head;
            ?>
"
                            <?php 
            if ($istype) {
                ?>
                            
                            data-istype="1"
                            data-typename="<?php 
                echo $typename2;
                ?>
"
                            <?php 
            }
            ?>
                            data-rowtitle="<?php 
            echo $items[0];
            ?>
" <?php 
            echo $selected;
            ?>
>
                        <?php 
            echo $items[0];
            ?>
                    </option>

                <?php 
        }
        ?>
            </optgroup>
        <?php 
    }
    ?>
    </select>
    <?php 
    //aditional combo for body-templates
    ?>

    <p class="layout-wizard-body-template-text js-layout-wizard-body-template-text <?php 
    if (!preg_match('/wpv-post-body/', $_POST['selected']) || !empty($selected_body_template)) {
        ?>
hidden<?php 
    }
    ?>
"><?php 
    echo __('Using Content Template', 'wpv-views');
    ?>
</p>
    <select name="layout-wizard-body-template" class="layout-wizard-body-template <?php 
    if (!preg_match('/wpv-post-body/', $_POST['selected']) || !empty($selected_body_template)) {
        ?>
hidden<?php 
    }
    ?>
">
        <?php 
    foreach ($content_templates['Content template'] as $items) {
        ?>
        	<option value="<?php 
        echo base64_encode('[' . $items[1] . ']');
        ?>
" data-rowtitle="<?php 
        echo $items[0];
        ?>
" <?php 
        if (trim($items[0]) == trim($selected_body_template)) {
            echo 'selected';
        }
        ?>
 > <?php 
        echo $items[0];
        ?>
</option>
        <?php 
    }
    ?>
    </select>
    <?php 
    if ((string) $settings["query_type"][0] == 'users') {
        $type_usermeta_addon = ' data-type="views-usermeta"';
    }
    ?>
    <button class="button-secondary js-custom-types-fields" 
    <?php 
    if (!preg_match('/types.*?field=|types.*?usermeta=/', $selected_value) || !function_exists('types_get_fields')) {
        ?>
 style="display: none" <?php 
    } else {
        ?>
  rel="<?php 
        echo $typename;
        ?>
" <?php 
    }
    ?>
        <?php 
    if (isset($type_usermeta_addon)) {
        echo $type_usermeta_addon;
    }
    ?>
>
    	<?php 
    echo __('Edit', 'wpv-views');
    ?>
    </button>
    <i class="icon-remove-sign js-layout-wizard-remove-field"></i>
</li>
<?php 
    $result = array('html' => ob_get_clean(), 'selected_found' => $selected_found);
    echo json_encode($result);
    die;
}
/**
 * Add View button and dialog
 *
 * @param int $editor_id ID for the relevant textarea, to be set as active editor
 * @param bool $inline TODO document this
 *
 * Echoes strings without the unwanted sections
 *
 * @since unknown
 */
function wpv_add_v_icon_to_codemirror( $editor_id, $menus = array() ) {

    global $WP_Views;
	$is_view = false;
    $view_id = '';
	$post_hidden = '';
    $tax_hidden = ' hidden';
	$users_hidden = ' hidden';
	
    if ( 
		isset( $_GET['page'] )
		&& 'views-editor' == $_GET['page']
		&& isset( $_GET['view_id'] ) 
		&& is_numeric( $_GET['view_id'] )
	) {
		$is_view = true;
        $view_id = intval( $_GET['view_id'] );
		$view_settings = get_post_meta( $view_id, '_wpv_settings', true);
		if ( isset($view_settings['query_type']) && $view_settings['query_type'][0] == 'taxonomy'){
			   $post_hidden = ' hidden';
			   $tax_hidden = '';
			   $users_hidden = ' hidden';
		}
		if ( isset($view_settings['query_type']) && $view_settings['query_type'][0] == 'users'){
			   $post_hidden = ' hidden';
			   $tax_hidden = ' hidden';
			   $users_hidden = '';
		}
    }
    
    $WP_Views->editor_addon = new WPV_Editor_addon(
		'wpv-views',
        __('Insert Views Shortcodes', 'wpv-views'),
        WPV_URL . '/res/js/views_editor_plugin.js',
        WPV_URL_EMBEDDED . '/res/img/views-icon-black_16X16.png'
	);

    echo '<div class="wpv-vicon-for-posts'. $post_hidden .'">';
	
	if ( empty( $menus ) ) {
		$menus_to_add = array(
			'post',						// wpv-post shortcodes plus non-Types fields under their own section
			'post-extended',			// generic shortcodes extended in the Basic section
			'post-fields-placeholder',	// non-Types fields on demand
			'user',						// basic user data
			'post-view',				// Views listing posts
			'taxonomy-view',			// all available Views listing terms
			'user-view'					// all available Views listing users
		);
	} else {
		$menus_to_add = $menus;
	}

	add_short_codes_to_js( 
		$menus_to_add, 
		$WP_Views->editor_addon 
	);
	$WP_Views->editor_addon->add_fields_views_button('', $editor_id , true);

    echo '</div>';

	if ( $is_view ) {
		echo '<div class="wpv-vicon-for-taxonomy'. $tax_hidden .'">';
		remove_filter( 'editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11 );
		add_filter( 'editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V', 30 );
		$WP_Views->editor_addon->add_fields_views_button('', $editor_id, true);
		remove_filter( 'editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V', 30 );
		add_filter( 'editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11 );
		echo '</div>';

		echo '<div class="wpv-vicon-for-users'. $users_hidden .'">';
		remove_filter( 'editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11 );
		add_filter( 'editor_addon_menus_wpv-views', 'wpv_layout_users_V', 30 );
		$WP_Views->editor_addon->add_fields_views_button('', $editor_id, true);
		remove_filter( 'editor_addon_menus_wpv-views', 'wpv_layout_users_V', 30 );
		add_filter( 'editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11 );
		echo '</div>';
	}
}
 /**
  * Add the view button to the toolbar of required edit pages.
  *
  * Also force the view editor to be in HTML mode.
  */
 function post_edit_tinymce()
 {
     global $post;
     if (is_object($post) === false) {
         return;
     }
     if ($post->post_type != 'view-template') {
         $this->editor_addon = new Editor_addon('wpv-views', __('Insert Views Shortcodes', 'wpv-views'), WPV_URL . '/res/js/views_editor_plugin.js', '', true, 'icon-views-logo ont-icon-18 ont-color-gray');
         // add tool bar to other edit pages so they can insert the view shortcodes.
         add_short_codes_to_js(array('view', 'wpml', 'body-view-templates-posts'), $this->editor_addon, 'add-basics');
     }
 }
 /**
  * Add a view toolbar button to the editor of the content template
  *
  */
 function post_edit_tinymce()
 {
     global $post;
     if ($post->post_type == 'view-template') {
         $this->editor_addon = new Editor_addon('wpv-views', __('Insert Views Shortcode', 'wpv-views'), WPV_URL . '/res/js/views_editor_plugin.js', '', true, 'icon-views-logo ont-icon-18');
         add_short_codes_to_js(array('post', 'view', 'body-view-templates'), $this->editor_addon);
     }
 }
/**
* Add View button and dialog
*
* @param $editor_id ID for the relevant textarea, to be set as active editor
* @param $inline TODO document this
*
* @return $strings without the unwanted sections
*/
function wpv_add_v_icon_to_codemirror($editor_id, $inline = false)
{
    global $WP_Views;
    $view = '';
    if (isset($_GET['view_id'])) {
        $view = $_GET['view_id'];
    }
    $is_taxonomy = false;
    $is_users = false;
    $post_hidden = '';
    $tax_hidden = ' hidden';
    $users_hidden = ' hidden';
    $meta = get_post_meta($view, '_wpv_settings', true);
    if (isset($meta['query_type']) && $meta['query_type'][0] == 'taxonomy') {
        $is_taxonomy = true;
        $post_hidden = ' hidden';
        $tax_hidden = '';
        $users_hidden = ' hidden';
    }
    if (isset($meta['query_type']) && $meta['query_type'][0] == 'users') {
        $is_users = true;
        $post_hidden = ' hidden';
        $tax_hidden = ' hidden';
        $users_hidden = '';
    }
    $WP_Views->editor_addon = new Editor_addon('wpv-views', __('Insert Views Shortcodes', 'wpv-views'), WPV_URL . '/res/js/views_editor_plugin.js', WPV_URL_EMBEDDED . '/res/img/views-icon-black_16X16.png');
    if (!$inline) {
        echo '<div class="wpv-vicon-for-posts' . $post_hidden . '">';
    }
    if (!$inline) {
        add_short_codes_to_js(array('post', 'taxonomy', 'post-view'), $WP_Views->editor_addon);
        $WP_Views->editor_addon->add_form_button('', $editor_id, true, true, true);
    } else {
        if (empty($view) && isset($_POST['view_id'])) {
            $view = $_POST['view_id'];
            $meta = get_post_meta($view, '_wpv_settings', true);
        }
        if (!isset($meta['query_type'][0]) || isset($meta['query_type'][0]) && $meta['query_type'][0] == 'posts') {
            add_short_codes_to_js(array('post', 'taxonomy', 'post-view', 'body-view-templates-posts'), $WP_Views->editor_addon);
            $WP_Views->editor_addon->add_form_button('', $editor_id, true, true, true);
        } elseif (isset($meta['query_type'][0]) && $meta['query_type'][0] == 'users') {
            $WP_Views->editor_addon->add_users_form_button('', $editor_id, true);
        } elseif (isset($meta['query_type'][0]) && $meta['query_type'][0] == 'taxonomy') {
            remove_filter('editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11);
            add_filter('editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V');
            $WP_Views->editor_addon->add_form_button('', $editor_id, true, true, true);
            remove_filter('editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V');
            add_filter('editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11);
        }
    }
    if (!$inline) {
        echo '</div>';
    }
    if (!$inline) {
        echo '<div class="wpv-vicon-for-taxonomy' . $tax_hidden . '">';
        remove_filter('editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11);
        add_filter('editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V');
        $WP_Views->editor_addon->add_form_button('', $editor_id, true, true, true);
        remove_filter('editor_addon_menus_wpv-views', 'wpv_layout_taxonomy_V');
        add_filter('editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11);
        echo '</div>';
    }
    if (!$inline) {
        echo '<div class="wpv-vicon-for-users' . $users_hidden . '">';
        //add_filter('editor_addon_menus_wpv-views', 'wpv_layout_users_V');
        $WP_Views->editor_addon->add_users_form_button('', $editor_id, true);
        //remove_filter('editor_addon_menus_wpv-views', 'wpv_layout_users_V');
        //add_filter('editor_addon_menus_wpv-views', 'wpv_post_taxonomies_editor_addon_menus_wpv_views_filter', 11);
        echo '</div>';
    }
}