function add_view_loop_selection( $view_settings, $view_id ) {
	$hide = '';
	if ( isset( $view_settings['sections-show-hide'] )
		&& isset( $view_settings['sections-show-hide']['archive-loop'] )
		&& 'off' == $view_settings['sections-show-hide']['archive-loop'] )
	{
		$hide = ' hidden';
	}
	if ( 'layouts-loop' ==  $view_settings['view-query-mode'] ) {
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'loops_selection_layouts' );
	?>
	<div class="wpv-setting-container wpv-settings-archive-loops js-wpv-settings-archive-loop<?php echo $hide; ?>">
		<div class="wpv-settings-header">
			<h3>
				<?php _e('Loops Selection', 'wpv-views' ) ?>
			</h3>
			<i class="icon-question-sign js-display-tooltip" 
				data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
				data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
			</i>
		</div>
		<div class="wpv-setting js-wpv-setting">
			<p>
				<?php _e( 'This WordPress Archive is part of a Layout, so it will display the archive(s) to which the Layout is assigned.', 'wpv-views' ); ?>
			</p>
		</div>
	</div>
	<?php
	} else {
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'loops_selection' );
	?>
	<div class="wpv-setting-container wpv-settings-archive-loops js-wpv-settings-archive-loop<?php echo $hide; ?>">
		<div class="wpv-settings-header">
			<h3>
				<?php _e('Loops Selection', 'wpv-views' ) ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
					data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
				</i>
			</h3>
		</div>
		<div class="wpv-setting js-wpv-setting">
			<form class="js-loop-selection-form">
				<?php render_view_loop_selection_form( $view_id ); ?>
			</form>
		</div>
		<span class="update-action-wrap auto-update js-wpv-update-action-wrap">
			<span class="js-wpv-message-container"></span>
			<span type="hidden" data-success="<?php echo esc_attr( __( 'Updated', 'wpv-views') ); ?>" data-unsaved="<?php echo esc_attr( __('Not saved', 'wpv-views') ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_loop_selection_nonce' ); ?>" class="js-wpv-loop-selection-update" />
		</span>
	</div>
	<?php
	}
}
function add_view_filters( $view_settings, $view_id ) {
	$hide = '';
	if (
		isset( $view_settings['sections-show-hide'] ) 
		&& isset( $view_settings['sections-show-hide']['content-filter'] ) 
		&& 'off' == $view_settings['sections-show-hide']['content-filter']
	) {
		$hide = ' hidden';
	}
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'filter_the_results' );
	?>
	<div class="wpv-setting-container wpv-settings-content-filter js-wpv-settings-content-filter<?php echo $hide; ?>">
		<div class="wpv-settings-header">
			<h3>
				<?php _e( 'Query Filter', 'wpv-views' ) ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
					data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
				</i>
			</h3>
		</div>
		<div class="wpv-setting">
			<p class="js-no-filters hidden"><?php _e( 'No filters set', 'wpv-views' ) ?></p>
			<ul class="filter-list js-filter-list hidden">
				<?php
				if (
					isset( $view_settings['query_type'] ) 
					&& isset( $view_settings['query_type'][0] )
				) {
					wpv_display_filters_list( $view_settings['query_type'][0], $view_settings );
				}
				?>
			</ul>
			<input type="hidden" class="js-wpv-filter-update-filters-list-nonce" value="<?php echo wp_create_nonce( 'wpv_view_filter_update_filters_list_nonce' ); ?>" />
			<p>
				<button class="button-secondary js-wpv-filter-add-filter" type="button" data-empty="<?php echo esc_attr( __('Add a filter', 'wpv-views') ); ?>" data-nonempty="<?php echo esc_attr( __('Add another filter', 'wpv-views') ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_filter_add_filter' ); ?>">
					<i class="icon-plus"></i> <?php echo esc_attr( __('Add a filter', 'wpv-views') ); ?>
				</button>
			</p>
		</div>
	</div>
<?php }
function add_view_layout_extra_js( $view_settings, $view_layout_settings, $view_id ) {
	$hide = '';
	$js = isset( $view_layout_settings['additional_js'] ) ? strval( $view_layout_settings['additional_js'] ) : '';
	if (
		isset( $view_settings['sections-show-hide'] ) 
		&& isset( $view_settings['sections-show-hide']['layout-settings-extra-js'] ) 
	) {
		if ( 'off' == $view_settings['sections-show-hide']['layout-settings-extra-js'] ) {
			$hide = ' hidden';
		}
	} elseif ( ''== $js ) {
		$hide = ' hidden';
	}
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'layout_extra_js' );
	?>
	<div class="wpv-setting-container wpv-settings-output-extra-js js-wpv-settings-layout-settings-extra-js<?php echo $hide; ?>">
		<div class="wpv-settings-header">
			<h3>
				<?php _e( 'Additional Javascript files','wpv-views' ) ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
					data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
				</i>
			</h3>
		</div>
		<div class="wpv-setting">
			<p>
				<label for="wpv-layout-settings-extra-js"><?php _e( 'Additional Javascript files to be loaded with this View (comma separated): ', 'wpv-views' ) ?></label>
				<input type="text" id="wpv-layout-settings-extra-js" autocomplete="off" class="js-wpv-layout-settings-extra-js" name="_wpv_layout_settings[additional_js]" value="<?php echo esc_attr( $js ); ?>" style="width:100%;" />
			</p>
			<p class="update-button-wrap js-wpv-update-button-wrap">
				<span class="js-wpv-message-container"></span>
				<button data-success="<?php echo esc_attr( __('Data saved', 'wpv-views') ); ?>" data-unsaved="<?php echo esc_attr( __('Data not saved', 'wpv-views') ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_layout_settings_extra_js_nonce' ); ?>" class="js-wpv-layout-settings-extra-js-update button-secondary" disabled="disabled"><?php _e('Update', 'wpv-views'); ?></button>
			</p>
		</div>
	</div>
<?php }
    function add_view_module_manager_section($view_settings, $view_id)
    {
        $section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer('module_manager');
        ?>
		<div class="wpv-setting-container wpv-setting-container-module-manager js-wpv-settings-content">

			<div class="wpv-settings-header">
				<h3>
					<?php 
        _e('Module Manager', 'wpv-views');
        ?>
					<i class="icon-question-sign js-display-tooltip" 
						data-header="<?php 
        echo esc_attr($section_help_pointer['title']);
        ?>
" 
						data-content="<?php 
        echo esc_attr($section_help_pointer['content']);
        ?>
" >
					</i>
				</h3>
			</div>

			<div class="wpv-setting wpv-setting-module-manager">
				<?php 
        $element = array('id' => _VIEWS_MODULE_MANAGER_KEY_ . $view_id, 'title' => get_the_title($view_id), 'section' => _VIEWS_MODULE_MANAGER_KEY_);
        do_action('wpmodules_inline_element_gui', $element);
        ?>
			</div>

		</div>
	   <?php 
    }
function add_view_layout_template($view_settings, $view_layout_settings, $view_id, $user_id)
{
    $dismissed_pointers = get_user_meta($user_id, '_wpv_dismissed_pointers', true);
    if (!is_array($dismissed_pointers) || empty($dismissed_pointers)) {
        $dismissed_pointers = array();
    }
    $dismissed_dialogs = get_user_meta($user_id, '_wpv_dismissed_dialogs', true);
    if (!is_array($dismissed_dialogs) || empty($dismissed_dialogs)) {
        $dismissed_dialogs = array();
    }
    wp_nonce_field('wpv-ct-inline-edit', 'wpv-ct-inline-edit');
    wp_nonce_field('wpv_inline_content_template', 'wpv_inline_content_template');
    $templates = array();
    $valid_templates = array();
    $first_time = get_post_meta($view_id, '_wpv_first_time_load', true);
    if (isset($view_layout_settings['included_ct_ids'])) {
        $templates = explode(',', $view_layout_settings['included_ct_ids']);
        $valid_templates = $templates;
    }
    if (count($templates) > 0) {
        $attached_templates = count($templates);
        foreach ($templates as $key => $template_id) {
            if (is_numeric($template_id)) {
                $template_post = get_post($template_id);
                if (is_object($template_post) && $template_post->post_status == 'publish' && $template_post->post_type == 'view-template') {
                } else {
                    unset($valid_templates[$key]);
                    // remove Templates that might have been deleted or are missing
                }
            } else {
                unset($valid_templates[$key]);
                // remove Templates that might have been deleted or are missing
            }
        }
        if (count($templates) != count($valid_templates)) {
            $view_layout_settings['included_ct_ids'] = implode(',', $valid_templates);
            update_post_meta($view_id, '_wpv_layout_settings', $view_layout_settings);
            do_action('wpv_action_wpv_save_item', $view_id);
        }
    }
    $section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer('templates_for_view');
    ?>
	<div id="attached-content-templates" class="wpv-settings-templates wpv-setting-container wpv-setting-container-horizontal wpv-settings-layout-markup js-wpv-settings-inline-templates"<?php 
    echo count($valid_templates) < 1 ? ' style="display:none;"' : '';
    ?>
>
		<div class="wpv-settings-header">
			<h3><?php 
    _e('Templates for this View', 'wpv-views');
    ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php 
    echo esc_attr($section_help_pointer['title']);
    ?>
" 
					data-content="<?php 
    echo esc_attr($section_help_pointer['content']);
    ?>
">
				</i>
			</h3>
		</div>
		<?php 
    if ($first_time == 'on') {
        $purpose = $view_settings['view_purpose'];
        if ($purpose == 'slider') {
            wpv_get_view_ct_slider_introduction_data();
        }
    }
    ?>
		<div class="js-wpv-content-template-view-list wpv-content-template-view-list wpv-setting">
			<ul class="wpv-inline-content-template-listing js-wpv-inline-content-template-listing">
				<?php 
    if (count($valid_templates) > 0) {
        $opened = false;
        if (count($valid_templates) == 1) {
            $opened = true;
        }
        foreach ($valid_templates as $valid_ct_id) {
            // This is cached so it is OK to do that again
            $valid_ct_post = get_post($valid_ct_id);
            wpv_list_view_ct_item($valid_ct_post, $valid_ct_id, $view_id, $opened);
        }
    }
    ?>
			</ul>
			<div class="js-wpv-message-container js-wpv-content-template-section-errors"></div>
		</div>		
	</div>
	
	<!-- @todo: move this to the view-editor-section-hidden action -->
	<div id="js-wpv-inline-content-templates-dialogs" class="popup-window-container">
	
		<!-- Colorbox dialogs -->
		
		<?php 
    $dismissed_classname = '';
    if (isset($dismissed_dialogs['remove-content-template-from-view'])) {
        $dismissed_classname = ' js-wpv-dialog-dismissed';
    }
    ?>
		
		<div class="wpv-dialog js-wpv-dialog-remove-content-template-from-view<?php 
    echo $dismissed_classname;
    ?>
">
            <div class="wpv-dialog-header">
                <h2><?php 
    _e('Remove the Content Template from the view', 'wpv-views');
    ?>
</h2>
                <i class="icon-remove js-dialog-close"></i>
            </div>
            <div class="wpv-dialog-content">
                <p>
                    <?php 
    _e("This will remove the link between your view and the Content Template.  The Content Template will not be deleted.");
    ?>
                </p>
				<p>
					<label for="wpv-dettach-inline-content-template-dismiss">
						<input type="checkbox" id="wpv-dettach-inline-content-template-dismiss" class="js-wpv-dettach-inline-content-template-dismiss" />
						<?php 
    _e("Don't show this message again", 'wpv-views');
    ?>
					</label>
            	</p>
            </div>
            <div class="wpv-dialog-footer">
                <button class="button js-dialog-close"><?php 
    _e('Cancel', 'wpv-views');
    ?>
</button>
                <button class="button button-primary js-wpv-remove-template-from-view"><?php 
    _e('Remove', 'wpv-views');
    ?>
</button>
            </div>
		</div>
		
		<!-- Pointers -->
		
		<?php 
    $dismissed_classname = '';
    if (isset($dismissed_pointers['inserted-inline-content-template'])) {
        $dismissed_classname = ' js-wpv-pointer-dismissed';
    }
    ?>
		<div class="js-wpv-inserted-inline-content-template-pointer<?php 
    echo $dismissed_classname;
    ?>
">
			<h3><?php 
    _e('Content Template inserted in the layout', 'wpv-views');
    ?>
</h3>
			<p>
				<?php 
    _e('A Content Template works like a subroutine.', 'wpv-views');
    echo WPV_MESSAGE_SPACE_CHAR;
    _e('You can edit its content in one place and use it in several places in the View.', 'wpv-views');
    ?>
			</p>
			<p>
				<label>
					<input type="checkbox" class="js-wpv-dismiss-pointer" data-pointer="inserted-inline-content-template" id="wpv-dismiss-inserted-inline-content-template-pointer" />
					<?php 
    _e('Don\'t show this again', 'wpv-views');
    ?>
				</label>
			</p>
		</div>
	
	
	</div><!-- end of .popup-window-container -->
<?php 
    delete_post_meta($view_id, '_wpv_first_time_load');
}
function add_view_limit_offset($view_settings, $view_id)
{
    $view_settings = wpv_limit_default_settings($view_settings);
    $limit_options = array();
    $offset_options = array();
    for ($index = 1; $index < 51; $index++) {
        $limit_options[$index] = $index;
        $offset_options[$index] = $index;
    }
    $limit_options = apply_filters('wpv_filter_extend_limit_options', $limit_options);
    $offset_options = apply_filters('wpv_filter_extend_offset_options', $offset_options);
    $hide = '';
    if (isset($view_settings['sections-show-hide']) && isset($view_settings['sections-show-hide']['limit-offset']) && 'off' == $view_settings['sections-show-hide']['limit-offset']) {
        $hide = ' hidden';
    }
    $section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer('limit_and_offset');
    ?>
	<div class="wpv-setting-container wpv-settings-limit js-wpv-settings-limit-offset<?php 
    echo $hide;
    ?>
">
		<div class="wpv-settings-header">
			<h3>
				<?php 
    _e('Limit and Offset', 'wpv-views');
    ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php 
    echo esc_attr($section_help_pointer['title']);
    ?>
" 
					data-content="<?php 
    echo esc_attr($section_help_pointer['content']);
    ?>
">
				</i>
			</h3>
		</div>
		<div class="wpv-setting js-wpv-setting">

			<div class="wpv-settings-query-type-posts"<?php 
    echo $view_settings['query_type'][0] != 'posts' ? ' style="display: none;"' : '';
    ?>
>

				<p>
					<span class="wpv-combo">
						<label for="wpv-settings-limit"><?php 
    _e('Display ', 'wpv-views');
    ?>
</label>
						<select name="_wpv_settings[limit]" id="wpv-settings-limit" class="js-wpv-limit" autocomplete="off">
							<option value="-1"><?php 
    _e('No limit', 'wpv-views');
    ?>
</option>
							<?php 
    foreach ($limit_options as $index => $value) {
        ?>
								<option value="<?php 
        echo esc_attr($index);
        ?>
" <?php 
        selected($view_settings['limit'], $index, true);
        ?>
><?php 
        echo $value;
        ?>
</option>
								<?php 
    }
    ?>
						</select>
						<span><?php 
    _e('items ', 'wpv-views');
    ?>
</span>
					</span>
					&nbsp;&nbsp;|&nbsp;&nbsp;
					<span class="wpv-combo">
						<label for="wpv-settings-offset"><?php 
    _e('Skip first', 'wpv-views');
    ?>
</label>
						<select name="_wpv_settings[offset]" id="wpv-settings-offset" class="js-wpv-offset" autocomplete="off">
							<option value="0"><?php 
    _e('None', 'wpv-views');
    ?>
</option>
							<?php 
    foreach ($offset_options as $index => $value) {
        ?>
								<option value="<?php 
        echo esc_attr($index);
        ?>
" <?php 
        selected($view_settings['offset'], $index, true);
        ?>
><?php 
        echo $value;
        ?>
</option>
								<?php 
    }
    ?>
						</select>
						<span><?php 
    _e('items', 'wpv-views');
    ?>
</span>
					<span class="wpv-combo">
				</p>
			</div>

			<div class="wpv-settings-query-type-taxonomy"<?php 
    echo $view_settings['query_type'][0] != 'taxonomy' ? ' style="display: none;"' : '';
    ?>
>

				<p>
					<span class="wpv-combo">
						<label for="wpv-settings-taxonomy-limit"><?php 
    _e('Display ', 'wpv-views');
    ?>
</label>
						<select name="_wpv_settings[taxonomy_limit]" id="wpv-settings-taxonomy-limit" class="js-wpv-taxonomy-limit" autocomplete="off">
							<option value="-1"><?php 
    _e('No limit', 'wpv-views');
    ?>
</option>
							<?php 
    foreach ($limit_options as $index => $value) {
        ?>
								<option value="<?php 
        echo esc_attr($index);
        ?>
" <?php 
        selected($view_settings['taxonomy_limit'], $index, true);
        ?>
><?php 
        echo $value;
        ?>
</option>
								<?php 
    }
    ?>
						</select>
						<span><?php 
    _e('items ', 'wpv-views');
    ?>
</span>
					</span>
					&nbsp;&nbsp;|&nbsp;&nbsp;
					<span class="wpv-combo">
						<label for="wpv-settings-taxonomy-offset"><?php 
    _e('Skip first', 'wpv-views');
    ?>
</label>
						<select name="_wpv_settings[taxonomy_offset]" id="wpv-settings-taxonomy-offset" class="js-wpv-taxonomy-offset" autocomplete="off">
							<option value="0"><?php 
    _e('None', 'wpv-views');
    ?>
</option>
							<?php 
    foreach ($offset_options as $index => $value) {
        ?>
								<option value="<?php 
        echo esc_attr($index);
        ?>
" <?php 
        selected($view_settings['taxonomy_offset'], $index, true);
        ?>
><?php 
        echo $value;
        ?>
</option>
								<?php 
    }
    ?>
						</select>
						<span><?php 
    _e('items', 'wpv-views');
    ?>
</span>
					</span>
				</p>
			</div>
			<div class="wpv-settings-query-type-users"<?php 
    echo $view_settings['query_type'][0] != 'users' ? ' style="display: none;"' : '';
    ?>
>
			     <p>
                    <span class="wpv-combo">
						<label for="wpv-settings-users-limit"><?php 
    _e('Display ', 'wpv-views');
    ?>
</label>
						<select name="_wpv_settings[users_limit]" id="wpv-settings-users-limit" class="js-wpv-users-limit" autocomplete="off">
							<option value="-1"><?php 
    _e('No limit', 'wpv-views');
    ?>
</option>
							<?php 
    foreach ($limit_options as $index => $value) {
        ?>
								<option value="<?php 
        echo esc_attr($index);
        ?>
" <?php 
        selected($view_settings['users_limit'], $index, true);
        ?>
><?php 
        echo $value;
        ?>
</option>
								<?php 
    }
    ?>
						</select>
						<span><?php 
    _e('items ', 'wpv-views');
    ?>
</span>
					</span>
					&nbsp;&nbsp;|&nbsp;&nbsp;
					<span class="wpv-combo">
						<label for="wpv-settings-users-offset"><?php 
    _e('Skip first', 'wpv-views');
    ?>
</label>
						<select name="_wpv_settings[users_offset]" id="wpv-settings-users-offset" class="js-wpv-users-offset" autocomplete="off">
							<option value="0"><?php 
    _e('None', 'wpv-views');
    ?>
</option>
							<?php 
    foreach ($offset_options as $index => $value) {
        ?>
								<option value="<?php 
        echo esc_attr($index);
        ?>
" <?php 
        selected($view_settings['users_offset'], $index, true);
        ?>
><?php 
        echo $value;
        ?>
</option>
								<?php 
    }
    ?>
						</select>
						<span><?php 
    _e('items', 'wpv-views');
    ?>
</span>
					</span>
                </p>
			</div>
		</div>
		<span class="update-action-wrap auto-update js-wpv-update-action-wrap">
			<span class="js-wpv-message-container"></span>
			<input type="hidden" data-success="<?php 
    echo esc_attr(__('Updated', 'wpv-views'));
    ?>
" data-unsaved="<?php 
    echo esc_attr(__('Not saved', 'wpv-views'));
    ?>
" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_limit_offset_nonce');
    ?>
" class="js-wpv-limit-offset-update" />
		</span>
	</div>
<?php 
}
    /**
     * render_toggle_toggled
     *
     * Display the toggled div
     *
     * @param $classname (string) classname of the div to toggle including the $target one in the toggler
     * @param $intro (string) text to introduce the toggler
     * "param $sections (array) list of sections to display
     *
     * @return echo the div HTML tag
     *
     * @since 1.7
     */
    static function render_toggle_toggled($classname = '', $intro = '', $sections = array())
    {
        ?>
		<div class="<?php 
        echo $classname;
        ?>
 hidden">
		<?php 
        if (!empty($intro)) {
            ?>
			<?php 
            echo $intro;
            ?>
		<?php 
        }
        if (!empty($sections)) {
            foreach ($sections as $section) {
                $args = wpv_views_instructions_section_data($section);
                WPV_Admin_Messages::render_toggle_section($args);
            }
        }
        ?>
		</div>
		<?php 
    }
/**
 * View edit screen
 */
function views_redesign_html()
{
    global $WP_Views, $post;
    if (isset($_GET['view_id']) && is_numeric($_GET['view_id'])) {
        do_action('views_edit_screen');
        $view_id = (int) $_GET['view_id'];
        $view = get_post($view_id);
        if (null == $view) {
            wpv_die_toolset_alert_error(__('You attempted to edit a View that doesn&#8217;t exist. Perhaps it was deleted?', 'wpv-views'));
        } elseif ('view' != $view->post_type) {
            wpv_die_toolset_alert_error(__('You attempted to edit a View that doesn&#8217;t exist. Perhaps it was deleted?', 'wpv-views'));
        } else {
            $view_settings = get_post_meta($_GET['view_id'], '_wpv_settings', true);
            /**
             * wpv_view_settings
             *
             * Internal filter to set some View settings that will overwrite the ones existing in the _wpv_settings postmeta
             * Only used to set default values that need to be there on the returned array, but may not be there for legacy reasons
             * Use wpv_filter_override_view_settings to override View settings - like on the Theme Frameworks integration
             *
             * @param $view_settings (array) Unserialized array of the _wpv_settings postmeta
             * @param $view_id (integer) The View ID
             *
             * @return $view_settings (array) The View settings
             *
             * @since unknown
             */
            $view_settings = apply_filters('wpv_view_settings', $view_settings, $view_id);
            $view_layout_settings = get_post_meta($_GET['view_id'], '_wpv_layout_settings', true);
            /**
             * wpv_view_layout_settings
             *
             * Internal filter to set some View layout settings that will overwrite the ones existing in the _wpv_layout_settings postmeta
             * Only used to set default values that need to be there on the returned array,, but may not be there for legacy reasons
             * Use wpv_filter_override_view_layout_settings to override View layout settings
             *
             * @param $view_layout_settings (array) Unserialized array of the _wpv_layout_settings postmeta
             * @param $view_id (integer) The View ID
             *
             * @return $view_layout_settings (array) The View layout settings
             *
             * @since 1.8.0
             */
            $view_layout_settings = apply_filters('wpv_view_layout_settings', $view_layout_settings, $view_id);
            if (isset($view_settings['view-query-mode']) && 'normal' == $view_settings['view-query-mode']) {
                $post = $view;
                if (get_post_status($view_id) == 'trash') {
                    wpv_die_toolset_alert_error(__('You can’t edit this View because it is in the Trash. Please restore it and try again.', 'wpv-views'));
                }
            } else {
                wpv_die_toolset_alert_error(__('You attempted to edit a View that doesn&#8217;t exist. Perhaps it was deleted?', 'wpv-views'));
            }
        }
    } else {
        wpv_die_toolset_alert_error(__('You attempted to edit a View that doesn&#8217;t exist. Perhaps it was deleted?', 'wpv-views'));
    }
    ?>
	<?php 
    /**
     * Screen Options tab
     */
    ?>
	<div id="screen-meta-dup" class="metabox-prefs js-screen-meta-dup hidden">
		<div id="screen-options-wrap" aria-label="<?php 
    echo esc_attr(__('Screen Options Tab'));
    ?>
" class="wpv-screen-options js-wpv-show-hide-container" 
			data-dpsneedsfilter="<?php 
    echo esc_attr(__('The parametric search settings section has unsaved changes, so you can not hide it', 'wpv-views'));
    ?>
" 
			data-pagneedsfilter="<?php 
    echo esc_attr(__('Pagination requires the Filter HTML section to be visible.', 'wpv-views'));
    ?>
" 
			data-unclickable="<?php 
    echo esc_attr(__('This section has unsaved changes, so you can not hide it', 'wpv-views'));
    ?>
">
			<h5><?php 
    _e('Show on screen', 'wpv-views');
    ?>
</h5>
			<p>
				<small><?php 
    echo __('Note that those Screen Options are set per View.', 'wpv-views');
    ?>
</small>
			</p>
			<?php 
    $sections = array();
    $sections = apply_filters('wpv_sections_query_show_hide', $sections);
    if (!empty($sections)) {
        ?>
			<div class="wpv-show-hide-section wpv-show-hide-section-query js-wpv-show-hide-section" data-metasection="wpv-query-section">
				<h6><?php 
        _e('Query section', 'wpv-views');
        ?>
</h6>
				<span class="js-wpv-screen-pref">
				<?php 
        if (isset($view_settings['metasections-hep-show-hide']) && isset($view_settings['metasections-hep-show-hide']['wpv-query-help'])) {
            $state = $view_settings['metasections-hep-show-hide']['wpv-query-help'];
        } else {
            $state = 'on';
        }
        ?>
				<label for="wpv-show-hide-query-help">
					<input type="checkbox" id="wpv-show-hide-query-help" data-metasection="query" class="js-wpv-show-hide-help js-wpv-show-hide-query-help" <?php 
        checked('on', $state);
        ?>
 autocomplete="off" />
					<?php 
        echo __('Display Query section help', 'wpv-views');
        ?>
				</label>
				<input name="wpv-query-help" type="hidden" class="js-wpv-show-hide-help-value js-wpv-show-hide-query-help-value" value="<?php 
        echo esc_attr($state);
        ?>
" autocomplete="off" />
				</span>
				<?php 
        foreach ($sections as $key => $values) {
            if (isset($view_settings['sections-show-hide']) && isset($view_settings['sections-show-hide'][$key])) {
                $values['state'] = $view_settings['sections-show-hide'][$key];
            } else {
                $values['state'] = 'on';
            }
            ?>
						<span class="js-wpv-screen-pref">
						<label for="wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
">
							<input data-section="<?php 
            echo esc_attr($key);
            ?>
" type="checkbox" id="wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
" class="js-wpv-show-hide js-wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
" <?php 
            checked('on', $values['state']);
            ?>
 autocomplete="off" />
							<?php 
            echo $values['name'];
            ?>
						</label>
						<input data-section="<?php 
            echo esc_attr($key);
            ?>
" name="<?php 
            echo esc_attr($key);
            ?>
" class="js-wpv-show-hide-value" type="hidden" value="<?php 
            echo esc_attr($values['state']);
            ?>
" autocomplete="off" />
						</span>
					<?php 
        }
        ?>
			</div>
			<?php 
    }
    ?>
			<?php 
    $sections = array();
    $sections = apply_filters('wpv_sections_filter_show_hide', $sections);
    if (!empty($sections)) {
        ?>
			<div class="wpv-show-hide-section wpv-show-hide-section-filter js-wpv-show-hide-section" data-metasection="wpv-filter-section">
				<h6><?php 
        _e('Filter section', 'wpv-views');
        ?>
</h6>
				<span class="js-wpv-screen-pref">
				<?php 
        if (isset($view_settings['metasections-hep-show-hide']) && isset($view_settings['metasections-hep-show-hide']['wpv-filter-help'])) {
            $state = $view_settings['metasections-hep-show-hide']['wpv-filter-help'];
        } else {
            $state = 'on';
        }
        ?>
				<label for="wpv-show-hide-filter-help">
					<input type="checkbox" id="wpv-show-hide-filter-help" data-metasection="filter" class="js-wpv-show-hide-help js-wpv-show-hide-filter-help" <?php 
        checked('on', $state);
        ?>
 autocomplete="off" />
					<?php 
        echo __('Display Filter section help', 'wpv-views');
        ?>
				</label>
				<input name="wpv-filter-help" type="hidden" class="js-wpv-show-hide-help-value js-wpv-show-hide-filter-help-value" value="<?php 
        echo esc_attr($state);
        ?>
" autocomplete="off" />
				</span>
				<?php 
        foreach ($sections as $key => $values) {
            if (isset($view_settings['sections-show-hide']) && isset($view_settings['sections-show-hide'][$key])) {
                $values['state'] = $view_settings['sections-show-hide'][$key];
            } else {
                $values['state'] = 'on';
            }
            ?>
						<span class="js-wpv-screen-pref">
						<label for="wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
">
							<input data-section="<?php 
            echo esc_attr($key);
            ?>
" type="checkbox" id="wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
" class="js-wpv-show-hide js-wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
" <?php 
            checked('on', $values['state']);
            ?>
 autocomplete="off" />
							<?php 
            echo $values['name'];
            ?>
						</label>
						<input data-section="<?php 
            echo esc_attr($key);
            ?>
" name="<?php 
            echo esc_attr($key);
            ?>
" class="js-wpv-show-hide-value" type="hidden" value="<?php 
            echo esc_attr($values['state']);
            ?>
" autocomplete="off" />
						</span>
					<?php 
        }
        ?>
			</div>
			<?php 
    }
    ?>
			<?php 
    $sections = array();
    $sections = apply_filters('wpv_sections_layout_show_hide', $sections);
    $js = isset($view_layout_settings['additional_js']) ? strval($view_layout_settings['additional_js']) : '';
    if ('' == $js && isset($sections['layout-settings-extra-js'])) {
        unset($sections['layout-settings-extra-js']);
    }
    if (!empty($sections)) {
        ?>
			<div class="wpv-show-hide-section wpv-show-hide-section-layout js-wpv-show-hide-section" data-metasection="wpv-layout-section">
				<h6><?php 
        _e('Loop Output section', 'wpv-views');
        ?>
</h6>
				<span class="js-wpv-screen-pref">
				<?php 
        if (isset($view_settings['metasections-hep-show-hide']) && isset($view_settings['metasections-hep-show-hide']['wpv-layout-help'])) {
            $state = $view_settings['metasections-hep-show-hide']['wpv-layout-help'];
        } else {
            $state = 'on';
        }
        ?>
				<label for="wpv-show-hide-layout-help">
					<input type="checkbox" id="wpv-show-hide-layout-help" data-metasection="layout" class="js-wpv-show-hide-help js-wpv-show-hide-layout-help" <?php 
        checked('on', $state);
        ?>
 autocomplete="off" />
					<?php 
        echo __('Display help for the Loop Output section', 'wpv-views');
        ?>
				</label>
				<input name="wpv-layout-help" type="hidden" class="js-wpv-show-hide-help-value js-wpv-show-hide-layout-help-value" value="<?php 
        echo esc_attr($state);
        ?>
" autocomplete="off" />
				</span>
				<?php 
        foreach ($sections as $key => $values) {
            if (isset($view_settings['sections-show-hide']) && isset($view_settings['sections-show-hide'][$key])) {
                $values['state'] = $view_settings['sections-show-hide'][$key];
            } else {
                $values['state'] = 'on';
            }
            ?>
						<span class="js-wpv-screen-pref">
						<label for="wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
">
							<input data-section="<?php 
            echo esc_attr($key);
            ?>
" type="checkbox" id="wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
" class="js-wpv-show-hide js-wpv-show-hide-<?php 
            echo esc_attr($key);
            ?>
" <?php 
            checked('on', $values['state']);
            ?>
 autocomplete="off" />
							<?php 
            echo $values['name'];
            ?>
						</label>
						<input data-section="<?php 
            echo esc_attr($key);
            ?>
" name="<?php 
            echo esc_attr($key);
            ?>
" class="js-wpv-show-hide-value" type="hidden" value="<?php 
            echo esc_attr($values['state']);
            ?>
" autocomplete="off" />
						</span>
					<?php 
        }
        ?>
			</div>
			<?php 
    }
    ?>
			<?php 
    if (!isset($view_settings['view_purpose']) || $view_settings['view_purpose'] == 'bootstrap-grid') {
        $view_settings['view_purpose'] = 'full';
    }
    ?>
			<p>
				<label for="wpv-view-purpose"><?php 
    echo __('View purpose', 'wpv-views');
    ?>
</label>
				<select id="wpv-view-purpose" class="js-view-purpose" autocomplete="off">
					<?php 
    $purpose_options = array('all' => __('Display all results', 'wpv-views'), 'pagination' => __('Display the results with pagination', 'wpv-views'), 'slider' => __('Display the results as a slider', 'wpv-views'), 'parametric' => __('Display the results as a parametric search', 'wpv-views'), 'full' => __('Full custom display mode', 'wwpv-views'));
    foreach ($purpose_options as $opt => $opt_name) {
        ?>
						<option id="wpv-settings-query-type-posts" <?php 
        selected($view_settings['view_purpose'], $opt);
        ?>
 value="<?php 
        echo esc_attr($opt);
        ?>
"><?php 
        echo $opt_name;
        ?>
</option>
					<?php 
    }
    ?>
				</select>
				<input type="hidden" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_show_hide_nonce');
    ?>
" class="js-wpv-show-hide-update" autocomplete="off" />
			</p>
			<div class="js-wpv-toolset-messages"></div>
		</div>
	</div>
	<div id="screen-meta-links-dup" class="js-screen-meta-links-dup">
		<div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
			<a id="show-settings-link" class="show-settings" aria-expanded="false" aria-controls="screen-options-wrap" href="#screen-options-wrap"><?php 
    _e('Screen Options');
    ?>
</a>
		</div>
	</div>
	<?php 
    /**
     * Actual View edit page
     */
    ?>
	<div class="wrap toolset-views">
	<input id="post_ID" class="js-post_ID" type="hidden" value="<?php 
    echo esc_attr($view_id);
    ?>
" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_edit_general_nonce');
    ?>
" />
    <input id="toolset-edit-data" type="hidden" value="<?php 
    echo esc_attr($view_id);
    ?>
" data-plugin="views" />
	<div id="icon-edit" class="icon32 icon32-posts-post"><br></div>
	<h2><?php 
    echo __('Edit View', 'wpv-views');
    ?>
</h2>
	<?php 
    if (isset($_GET['in-iframe-for-layout'])) {
        $in_iframe = 'yes';
    } else {
        $in_iframe = '';
    }
    $user_id = get_current_user_id();
    ?>
	<input type="hidden" class="js-wpv-display-in-iframe" value="<?php 
    echo esc_attr($in_iframe);
    ?>
" />
		<div id="js-wpv-general-actions-bar" class="wpv-settings-save-all wpv-general-actions-bar wpv-setting-container js-wpv-no-lock js-wpv-general-actions-bar">
			<p class="update-button-wrap js-wpv-update-button-wrap">
				<button class="button-secondary button button-large js-wpv-view-save-all"
						disabled="disabled"
						data-success="<?php 
    echo esc_attr(__('View saved', 'wpv-views'));
    ?>
"
						data-unsaved="<?php 
    echo esc_attr(__('View not saved', 'wpv-views'));
    ?>
">
					<?php 
    _e('Save all sections at once', 'wpv-views');
    ?>
				</button>
			</p>
			<span class="wpv-message-container js-wpv-message-container"></span>
		</div>
		<input type="hidden" name="_wpv_settings[view-query-mode]" value="normal" />
		<div class="wpv-title-section">
			<div class="wpv-setting-container wpv-settings-title-and-desc js-wpv-settings-title-and-desc js-wpv-no-lock">
				<div class="wpv-settings-header">
					<h3>
						<?php 
    _e('Title and Description', 'wpv-views');
    $section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer('title_and_description');
    ?>
						<i class="icon-question-sign js-display-tooltip"
								data-header="<?php 
    echo esc_attr($section_help_pointer['title']);
    ?>
"
								data-content="<?php 
    echo esc_attr($section_help_pointer['content']);
    ?>
">
						</i>
					</h3>
				</div>
				<div class="wpv-setting">

					<div id="titlediv">
						<div id="titlewrap" class="js-wpv-titlewrap">
							<label class="screen-reader-text js-title-reader" id="title-prompt-text" for="title"><?php 
    _e('Enter title here', 'wp-views');
    ?>
</label>
							<input id="title" class="js-title" type="text" name="post_title" size="30" value="<?php 
    echo esc_attr(get_the_title($view_id));
    ?>
" id="title" autocomplete="off">
						</div>
					</div>

					<div id="edit-slug-box" class="js-wpv-slug-container">
						<label for="wpv-slug"><?php 
    _e('Slug of this View', 'wpv-views');
    ?>
						<input id="wpv-slug" class="js-wpv-slug" type="text" value="<?php 
    echo esc_attr($view->post_name);
    ?>
" />
						<span class="js-wpv-inline-trash">
							&bull;
							<button class="button-secondary js-wpv-change-view-status"
									data-statusto="trash"
									data-success="<?php 
    echo esc_attr(__('View moved to trash', 'wpv-views'));
    ?>
"
									data-unsaved="<?php 
    echo esc_attr(__('View not moved to trash', 'wpv-views'));
    ?>
"
									data-redirect="<?php 
    echo admin_url('admin.php?page=views');
    ?>
"
									data-nonce="<?php 
    echo wp_create_nonce('wpv_view_change_status');
    ?>
">
								<i class="icon-trash"></i> <?php 
    _e('Move to trash', 'wpv-views');
    ?>
							</button>
						</span>
					</div>

					<?php 
    $view_description = get_post_meta($_GET['view_id'], '_wpv_description', true);
    ?>

					<p<?php 
    echo isset($view_description) && !empty($view_description) ? ' class="hidden"' : '';
    ?>
>
						<button class="js-wpv-description-toggle button-secondary" ><?php 
    _e('Add description', 'wpv-views');
    ?>
</button>
					</p>

					<div class="js-wpv-description-container wpv-description-container<?php 
    echo isset($view_description) && !empty($view_description) ? '' : ' hidden';
    ?>
">
						<p>
							<label for="wpv-description"><?php 
    _e('Describe this View', 'wpv-views');
    ?>
</label>
						</p>
						<p>
							<textarea id="wpv-description" class="js-wpv-description" name="_wpv_settings[view_description]" cols="72" rows="4"><?php 
    echo isset($view_description) ? esc_html($view_description) : '';
    ?>
</textarea>
						</p>
					</div>

					<p class="update-button-wrap js-wpv-update-button-wrap">
						<span class="js-wpv-message-container"></span>
						<button data-success="<?php 
    echo esc_attr(__('Title and description updated', 'wpv-views'));
    ?>
" data-unsaved="<?php 
    echo esc_attr(__('Title and description not saved', 'wpv-views'));
    ?>
" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_title_description_nonce');
    ?>
" class="js-wpv-title-description-update button-secondary" disabled="disabled"><?php 
    _e('Update', 'wpv-views');
    ?>
</button>
					</p>

				</div>
			</div>
		</div> <!-- .wpv-title-section -->

		<div class="wpv-query-section">
			<?php 
    wpv_get_view_introduction_data();
    ?>
			<h3 class="wpv-section-title"><?php 
    _e('The Query section determines what content the View loads from the database', 'wpv-views');
    ?>
</h3>
			<?php 
    do_action('view-editor-section-query', $view_settings, $view_id, $user_id);
    ?>
		</div>

		<?php 
    /*
     * Query type (content selection) - Priority 10
     * Query options - Priority 20
     * Ordering - Priority 30
     * Limit and offset - Priority 40
     * Filters - Priority 50
     */
    ?>

		<div class="wpv-filter-section">
			<h3 class="wpv-section-title"><?php 
    _e('The Filter section lets you set up pagination and parametric search, which let visitors control the View query', 'wpv-views');
    ?>
</h3>
			<?php 
    wpv_get_view_filter_introduction_data();
    ?>
			<?php 
    do_action('view-editor-section-filter', $view_settings, $view_id, $user_id);
    ?>
		</div>

		<?php 
    /*
     * Pagination TODO review this. https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/161787682/comments - Priority 50
     * Filters Meta HTML/CSS/JS TODO review this. https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/161787682/comments - Priority 80
     */
    ?>

		<div class="wpv-layout-section">
			<h3 class="wpv-section-title"><?php 
    _e('The Loop Output section styles the View output on the page.', 'wpv-views');
    ?>
</h3>
			<?php 
    $data = wpv_get_view_layout_introduction_data();
    wpv_toolset_help_box($data);
    ?>
			<?php 
    do_action('view-editor-section-layout', $view_settings, $view_layout_settings, $view_id, $user_id);
    ?>
			<?php 
    do_action('view-editor-section-extra', $view_settings, $view_id, $user_id);
    ?>
		</div>
		
        <?php 
    $display_help = isset($_GET['in-iframe-for-layout']) && $_GET['in-iframe-for-layout'] == 1 ? false : true;
    if ($display_help === true) {
        ?>
		<div class="wpv-help-section">
		<?php 
        wpv_display_view_howto_help_box();
        ?>
		</div>
        <?php 
    }
    ?>

		<script type="text/javascript">
			jQuery( function( $ ) {
				jQuery('li.current a').attr('href',jQuery('li.current a').attr('href')+'&view_id=<?php 
    echo esc_attr($view_id);
    ?>
');
			});
		</script>
		<?php 
    /*
     * Output (layout) type - TODO review this https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/162512599/comments - Priority 10 - To remove
     * Output fields TODO this has been reviewed and may be used as training - Priority 20 - To remove
     * Layout templates TODO insert here the new Content Templates editor. https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/161787695/comments - Priority 20 - To review
     * Layout Meta HTML/CSS/JS TODO this has been reviewed and needs some changes. https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/161787640/comments - Priority 40
     * Aditional Javascript files TODO move to its own file - Priority 50
     * Extra sections:
     * 1. Complete output (the_content)
     * 2. Module manager TODO needs to be added
     */
    ?>
	</div>
	<?php 
    /**
     * view-editor-section-hidden
     *
     * Show hidden container for dialogs, pointers and messages that need to be taken by ColorBox from an existing HTML element
     *
     * @param $view_settings
     * @param $view_laqyout_settings
     * @param $view_id
     * @param $user_id
     *
     * @note that you can use the .popup-window-container classname to hide the containers added here
     *
     * @since 1.7
     */
    do_action('view-editor-section-hidden', $view_settings, $view_layout_settings, $view_id, $user_id);
    if (!class_exists('_WP_Editors')) {
        require ABSPATH . WPINC . '/class-wp-editor.php';
    }
    _WP_Editors::wp_link_dialog();
}
function add_view_query_options( $view_settings, $view_id ) {
	$hide = '';
	if (
		isset( $view_settings['sections-show-hide'] ) 
		&& isset( $view_settings['sections-show-hide']['query-options'] ) 
		&& 'off' == $view_settings['sections-show-hide']['query-options']
	) {
		$hide = ' hidden';
	}
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'query_options' );
	?>
	<div class="wpv-setting-container wpv-settings-query-options js-wpv-settings-query-options<?php echo $hide; ?>">
		<div class="wpv-settings-header">
			<h3>
				<?php _e( 'Query Options', 'wpv-views' ) ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
					data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
				</i>
			</h3>
		</div>
		<div class="wpv-setting js-wpv-setting">
			<ul class="wpv-query-options wpv-settings-query-type-posts"<?php echo ( $view_settings['query_type'][0] != 'posts' ) ? ' style="display: none;"' : ''; ?>>
				<li>
					<?php $checked = ( isset( $view_settings['post_type_dont_include_current_page'] ) && $view_settings['post_type_dont_include_current_page'] ) ? ' checked="checked"' : '';?>
					<input type="checkbox" id="wpv-settings-post-include-current" class="js-wpv-query-options-post-type-dont" name="_wpv_settings[post_type_dont_include_current_page]" value="1"<?php echo $checked; ?> autocomplete="off" />
					<label for="wpv-settings-post-include-current"><?php _e("Don't include current page in query result", 'wpv-views'); ?></label>
				</li>
			</ul>
			<ul class="wpv-query-options wpv-settings-query-type-taxonomy"<?php echo ( $view_settings['query_type'][0] != 'taxonomy' ) ? ' style="display: none;"' : ''; ?>>
				<li>
					<?php $checked = ( isset( $view_settings['taxonomy_hide_empty'] ) && $view_settings['taxonomy_hide_empty'] ) ? ' checked="checked"' : '';?>
					<input type="checkbox" id="wpv-settings-taxonomy-hide-empty" class="js-wpv-query-options-taxonomy-hide-empty" name="_wpv_settings[taxonomy_hide_empty]" value="1"<?php echo $checked; ?> autocomplete="off" />
					<label for="wpv-settings-taxonomy-hide-empty"><?php _e( "Don't show empty terms", 'wpv-views' ) ?></label>
				</li>
				<li>
					<?php $checked = ( isset( $view_settings['taxonomy_include_non_empty_decendants'] ) && $view_settings['taxonomy_include_non_empty_decendants'] ) ? ' checked="checked"' : '';?>
					<input type="checkbox" id="wpv-settings-taxonomy-non-empty-decendants" class="js-wpv-query-options-taxonomy-non-empty-decendants" name="_wpv_settings[taxonomy_include_non_empty_decendants]" value="1"<?php echo $checked; ?> autocomplete="off" />
					<label for="wpv-settings-taxonomy-non-empty-decendants"><?php _e( 'Include terms that have non-empty descendants', 'wpv-views' ) ?></label>
				</li>
				<li>
					<?php $checked = ( isset( $view_settings['taxonomy_pad_counts'] ) && $view_settings['taxonomy_pad_counts'] ) ? ' checked="checked"' : '';?>
					<input id="wpv-settings-taxonomy-pad-counts" type="checkbox" class="js-wpv-query-options-taxonomy-pad-counts" name="_wpv_settings[taxonomy_pad_counts]" value="1"<?php echo $checked; ?> autocomplete="off" />
					<label for="wpv-settings-taxonomy-pad-counts"><?php _e( 'Include children in the post count', 'wpv-views' ) ?></label>
				</li>
			</ul>
			<ul class="wpv-query-options wpv-settings-query-type-users"<?php echo ( $view_settings['query_type'][0] != 'users' ) ? ' style="display: none;"' : ''; ?>>
				<li>
					<?php $checked = ( isset( $view_settings['users-show-current'] ) && $view_settings['users-show-current'] ) ? ' checked="checked"' : '';?>
					<input type="checkbox" id="wpv-settings-users-show-current" class="js-wpv-query-options-users-show-current" name="_wpv_settings[users-show-current]" value="1"<?php echo $checked; ?> autocomplete="off" />
					<label for="wpv-settings-users-show-current"><?php _e( "Don't show current logged user.", 'wpv-views' ) ?></label>
				</li>
				<?php
				/*
				 * NOTE: in future if users will ask query users from entire network, we can uncomment it.
				 */
				 /*if ( is_multisite() ): ?> 
				<li>
					<?php $checked = ( !isset( $view_settings['users-show-multisite'] ) || 
						( isset( $view_settings['users-show-multisite'] ) && $view_settings['users-show-multisite'] == 'all' ) ) ? ' checked="checked"' : '';?>
					<input type="radio" id="wpv-settings-users-show-multisite" class="js-wpv-query-options-users-show-multisite" 
					name="_wpv_settings[users-show-multisite]" value="all"<?php echo $checked; ?> />
					<label for="wpv-settings-users-show-multisite"><?php _e( "Load all users from the multisite network.", 'wpv-views' ) ?></label>
				</li>
				<li>
					<?php $checked = ( isset( $view_settings['users-show-multisite'] ) && $view_settings['users-show-multisite'] == 'current' ) ? ' checked="checked"' : '';?>
					<input type="radio" id="wpv-settings-users-show-multisite2" class="js-wpv-query-options-users-show-multisite" 
					name="_wpv_settings[users-show-multisite]" value="current"<?php echo $checked; ?> />
					<label for="wpv-settings-users-show-multisite2"><?php _e( "Load only users from the child site in the network.", 'wpv-views' ) ?></label>
				</li>
				
				<?php endif; */?>
			</ul>
		</div>
		<span class="update-action-wrap auto-update js-wpv-update-action-wrap">
			<span class="js-wpv-message-container"></span>
			<input type="hidden" data-success="<?php echo esc_attr( __('Updated', 'wpv-views') ); ?>" data-unsaved="<?php echo esc_attr( __('Not saved', 'wpv-views') ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_query_options_nonce' ); ?>" class="js-wpv-query-options-update" />
		</span>
	</div>
<?php }
function wpv_embedded_combined_output($view_settings, $view_layout_settings, $view_id)
{
    $section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer('complete_output');
    ?>
	<div class="wpv-setting-container wpv-setting-container-horizontal">
		<div class="wpv-settings-header">
			<h3>
				<?php 
    _e('Filter and Loop Output Integration', 'wpv-views');
    ?>
				<i class="icon-question-sign js-display-tooltip"
						data-header="<?php 
    echo esc_attr($section_help_pointer['title']);
    ?>
"
						data-content="<?php 
    echo esc_attr($section_help_pointer['content']);
    ?>
">
				</i>
			</h3>
		</div>
		<div class="wpv-setting">
			<?php 
    $full_view = get_post($view_id);
    $content = $full_view->post_content;
    ?>
			<textarea cols="30" rows="10" id="wpv_content" name="wpv_content"><?php 
    echo esc_textarea($content);
    ?>
</textarea>
		</div>
	</div>
	<?php 
}
function add_view_content( $view_settings, $view_id ) {
    /* This section will be visible if
     * - this is a View (not WPA) edit page and
     * - the 'filter-extra' section is displayed (not hidden).
     *
     * Apparently default behaviour for sections is to be visible unless
     * $view_settings['sections-show-hide'][ $section_name ] == 'off'
     *
     * Note that the container div has class js-wpv-settings-filter-extra, which will cause it to be shown or hidden
     * simultaneously with the filter-extra section when user changes the according option Screen options.
     */ 
	$is_section_hidden = false;

	// Hide if we're not editing a View
	if ( 
		isset( $view_settings['view-query-mode'] )
		&& 'normal' != $view_settings['view-query-mode'] )
	{
		$is_section_hidden = true;
	// Hide if 'filter-extra' section should be hidden.
	} else if ( 
		isset( $view_settings['sections-show-hide'] )
		&& isset( $view_settings['sections-show-hide']['filter-extra'] )
		&& 'off' == $view_settings['sections-show-hide']['filter-extra'] )
	{
		$is_section_hidden = true;
	}
	$hide_class = $is_section_hidden ? 'hidden' : '';
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'complete_output' );
	?>
	<div class="wpv-setting-container wpv-setting-container-horizontal wpv-settings-complete-output js-wpv-settings-content js-wpv-settings-filter-extra <?php echo $hide_class; ?>">

		<div class="wpv-settings-header">
			<h3>
				<?php _e( 'Filter and Loop Output Integration', 'wpv-views' ) ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
					data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
				</i>
			</h3>
		</div>

		<div class="wpv-setting">
			<div class="js-code-editor code-editor content-editor" data-name="complete-output-editor">
				<?php
					$full_view = get_post( $view_id );
					$content = $full_view->post_content;
				?>
				<div class="code-editor-toolbar js-code-editor-toolbar">
					<ul>
						<?php
						do_action( 'wpv_views_fields_button', 'wpv_content' );
						do_action( 'wpv_cred_forms_button', 'wpv_content' );
						?>
						<li>
							<button class="button-secondary js-code-editor-toolbar-button js-wpv-media-manager" data-id="<?php echo esc_attr( $view_id );?>" data-content="wpv_content">
								<i class="icon-picture"></i>
								<span class="button-label"><?php _e('Media','wpv-views'); ?></span>
							</button>
						</li>
					</ul>
				</div>
				<textarea cols="30" rows="10" id="wpv_content" name="_wpv_settings[content]" autocomplete="off"><?php echo esc_textarea( $content ); ?></textarea>
				<?php
				wpv_formatting_help_combined_output();
				?>
			</div>
			<p class="update-button-wrap js-wpv-update-button-wrap">
				<span class="js-wpv-message-container"></span>
				<button data-success="<?php echo esc_attr( __('Content updated', 'wpv-views') ); ?>" data-unsaved="<?php echo esc_attr( __('Content not saved', 'wpv-views') ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_content_nonce' ); ?>" class="js-wpv-content-update button-secondary" disabled="disabled"><?php _e('Update', 'wpv-views'); ?></button>
			</p>
		</div>

	</div>
<?php }
function add_view_layout_extra($view_settings, $view_layout_settings, $view_id)
{
    //Get loop content template
    $loop_content_template = get_post_meta($view_id, '_view_loop_template', true);
    $loop_content_template_name = '';
    if (!empty($loop_content_template)) {
        $loop_template = get_post($loop_content_template);
        $loop_content_template_name = $loop_template->post_title;
    }
    // What kind of view are we showing?
    if (!isset($view_settings['view-query-mode']) || 'normal' == $view_settings['view-query-mode']) {
        $view_kind = 'view';
    } else {
        // we assume 'archive' or 'layouts-loop'
        $view_kind = 'wpa';
    }
    $section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer('layout_html_css_js');
    ?>
	<div class="wpv-setting-container wpv-setting-container-horizontal wpv-settings-layout-markup js-wpv-settings-layout-extra">

		<div class="wpv-settings-header">
			<h3>
				<?php 
    _e('Loop Output', 'wpv-views');
    ?>
				<i class="icon-question-sign js-display-tooltip"
						data-header="<?php 
    echo esc_attr($section_help_pointer['title']);
    ?>
"
						data-content="<?php 
    echo esc_attr($section_help_pointer['content']);
    ?>
">
				</i>
			</h3>
		</div>
		<div class="wpv-setting">
            <input type="hidden" value="<?php 
    echo esc_attr($loop_content_template);
    ?>
" id="js-loop-content-template" />
            <input type="hidden" value="<?php 
    echo esc_attr($loop_content_template_name);
    ?>
" id="js-loop-content-template-name" />
			<div class="js-error-container js-wpv-error-container js-wpv-toolset-messages"></div>
			<div class="js-code-editor code-editor layout-html-editor" data-name="layout-html-editor">
				<div class="code-editor-toolbar js-code-editor-toolbar">
					<ul class="js-wpv-layout-edit-toolbar">
						<li>
							<button class="button-secondary js-code-editor-toolbar-button js-open-meta-html-wizard">
								<i class="icon-th"></i>
								<span class="button-label"><?php 
    _e('Loop Wizard', 'wpv-views');
    ?>
</span>
							</button>
						</li>
						<?php 
    do_action('wpv_views_fields_button', 'wpv_layout_meta_html_content');
    ?>
						<li>
							<button class="button-secondary js-code-editor-toolbar-button js-wpv-ct-assign-to-view" data-id="<?php 
    echo esc_attr($view_id);
    ?>
">
								<i class="icon-paste"></i>
								<span class="button-label"><?php 
    _e('Content Template', 'wpv-views');
    ?>
</span>
							</button>
						</li>
						<?php 
    if ('view' == $view_kind) {
        // we only add the pagination button to the Layout box if the View is not a WPA
        ?>
								<li class="js-editor-pagination-button-wrapper">
									<button class="button-secondary js-code-editor-toolbar-button js-wpv-pagination-popup" data-content="wpv_layout_meta_html_content">
										<i class="icon-pagination"></i>
										<span class="button-label"><?php 
        _e('Pagination controls', 'wpv-views');
        ?>
</span>
									</button>
								</li>
								<?php 
    } else {
        if ('wpa' == $view_kind) {
            // Button to the Archive pagination controls popup for WPAs
            ?>
								<li>
									<button class="button-secondary js-code-editor-toolbar-button js-wpv-archive-pagination-popup"
											data-content="wpv_layout_meta_html_content">
										<i class="icon-pagination"></i>
										<span class="button-label"><?php 
            _e('Pagination controls', 'wpv-views');
            ?>
</span>
									</button>
								</li>
								<?php 
        }
    }
    do_action('wpv_cred_forms_button', 'wpv_layout_meta_html_content');
    ?>
						<li>
							<button class="button-secondary js-code-editor-toolbar-button js-wpv-media-manager"
									data-id="<?php 
    echo esc_attr($view_id);
    ?>
"
									data-content="wpv_layout_meta_html_content">
								<i class="icon-picture"></i>
								<span class="button-label"><?php 
    _e('Media', 'wpv-views');
    ?>
</span>
							</button>
						</li>
					</ul>
				</div>

				<textarea cols="30" rows="10" id="wpv_layout_meta_html_content" autocomplete="off"
						name="_wpv_layout_settings[layout_meta_html]"><?php 
    echo isset($view_layout_settings['layout_meta_html']) ? esc_textarea($view_layout_settings['layout_meta_html']) : '';
    ?>
</textarea>
				
				<?php 
    wpv_formatting_help_layout();
    ?>
			</div>
			
			<ul id="wpv-layout-meta-html-extra" class="wpv-layout-meta-html-extra js-wpv-layout-meta-html-extra">
				<li class="wpv-has-itembox-header js-wpv-layout-meta-html-extra-item js-wpv-layout-meta-html-extra-css">
					<?php 
    $layout_extra_css = isset($view_settings['layout_meta_html_css']) ? $view_settings['layout_meta_html_css'] : '';
    ?>
					<div class="wpv-layout-meta-html-extra-header wpv-itembox-header">
						<strong>
							<?php 
    _e('CSS editor', 'wpv-views');
    ?>
						</strong>
						<button class="button button-secondary button-small wpv-code-editor-toggler js-wpv-code-editor-toggler" data-kind="css" data-target="layout-css-editor">
							<i class="icon-pushpin js-wpv-textarea-full" style="<?php 
    if (empty($layout_extra_css)) {
        echo ' display:none;';
    }
    ?>
"></i>
							<span class="js-wpv-text-holder"><?php 
    _e('Open CSS editor', 'wpv-views');
    ?>
</span>
						</button>
					</div>
					<div class="code-editor layout-css-editor wpv-code-editor-closed js-wpv-code-editor js-wpv-layout-css-editor js-wpv-code-editor-closed hidden">
						<div class="code-editor-toolbar js-code-editor-toolbar">
							<ul>
								<li>
									<button class="button-secondary js-code-editor-toolbar-button js-wpv-media-manager" data-id="<?php 
    echo esc_attr($view_id);
    ?>
" data-content="wpv_layout_meta_html_css">
										<i class="icon-picture"></i>
										<span class="button-label"><?php 
    _e('Media', 'wpv-views');
    ?>
</span>
									</button>
								</li>
							</ul>
						</div>
						<textarea cols="30" rows="10" id="wpv_layout_meta_html_css" autocomplete="off" name="_wpv_settings[layout_meta_html_css]"><?php 
    echo esc_textarea($layout_extra_css);
    ?>
</textarea>
						<?php 
    wpv_formatting_help_extra_css('layout');
    ?>
					</div>
				</li>
				<li class="wpv-has-itembox-header js-wpv-layout-meta-html-extra-item js-wpv-layout-meta-html-extra-js">
					<?php 
    $layout_extra_js = isset($view_settings['layout_meta_html_js']) ? $view_settings['layout_meta_html_js'] : '';
    ?>
					<div class="wpv-layout-meta-html-extra-header wpv-itembox-header">
						<strong>
							<?php 
    _e('JS editor', 'wpv-views');
    ?>
						</strong>
						<button class="button button-secondary button-small wpv-code-editor-toggler js-wpv-code-editor-toggler" data-kind="js" data-target="layout-js-editor">
							<i class="icon-pushpin js-wpv-textarea-full" style="<?php 
    if (empty($layout_extra_js)) {
        echo ' display:none;';
    }
    ?>
"></i>
							<span class="js-wpv-text-holder"><?php 
    _e('Open JS editor', 'wpv-views');
    ?>
</span>
						</button>
					</div>
					<div class="code-editor layout-js-editor wpv-code-editor-closed js-wpv-code-editor js-wpv-layout-js-editor js-wpv-code-editor-closed hidden">
						<div class="code-editor-toolbar js-code-editor-toolbar">
							<ul>
								<li>
									<button class="button-secondary js-code-editor-toolbar-button js-wpv-media-manager" data-id="<?php 
    echo esc_attr($view_id);
    ?>
" data-content="wpv_layout_meta_html_js">
										<i class="icon-picture"></i>
										<span class="button-label"><?php 
    _e('Media', 'wpv-views');
    ?>
</span>
									</button>
								</li>
							</ul>
						</div>
						<textarea cols="30" rows="10" id="wpv_layout_meta_html_js" autocomplete="off" name="_wpv_settings[layout_meta_html_js]"><?php 
    echo esc_textarea($layout_extra_js);
    ?>
</textarea>
						<?php 
    wpv_formatting_help_extra_js('layout');
    ?>
					</div>
				</li>
			</ul>

			<p class="update-button-wrap js-wpv-update-button-wrap">
				<span class="js-wpv-message-container"></span>
				<button data-success="<?php 
    echo esc_attr(__('Data updated', 'wpv-views'));
    ?>
"
						data-unsaved="<?php 
    echo esc_attr(__('Data not saved', 'wpv-views'));
    ?>
"
						data-nonce="<?php 
    echo wp_create_nonce('wpv_view_layout_extra_nonce');
    ?>
"
						class="js-wpv-layout-extra-update button-secondary" disabled="disabled">
					<?php 
    _e('Update', 'wpv-views');
    ?>
				</button>
			</p>
		</div>
	</div>
	<?php 
}
function add_view_ordering($view_settings, $view_id)
{
    global $WP_Views;
    $hide = '';
    if (isset($view_settings['sections-show-hide']) && isset($view_settings['sections-show-hide']['ordering']) && 'off' == $view_settings['sections-show-hide']['ordering']) {
        $hide = ' hidden';
    }
    $section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer('ordering');
    ?>
	<div class="wpv-setting-container wpv-settings-ordering js-wpv-settings-ordering<?php 
    echo $hide;
    ?>
">
		<div class="wpv-settings-header">
			<h3>
				<?php 
    _e('Ordering', 'wpv-views');
    ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php 
    echo esc_attr($section_help_pointer['title']);
    ?>
" 
					data-content="<?php 
    echo esc_attr($section_help_pointer['content']);
    ?>
">
				</i>
			</h3>
		</div>
		<div class="wpv-setting js-wpv-setting">
			<p class="wpv-settings-query-type-posts js-wpv-settings-posts-order"<?php 
    echo $view_settings['query_type'][0] != 'posts' ? ' style="display: none;"' : '';
    ?>
>
				<?php 
    $view_settings = wpv_order_by_default_settings($view_settings);
    // TODO this should not be needed
    ?>
				<label for="wpv-settings-orderby"><?php 
    _e('Order by: ', 'wpv-views');
    ?>
</label>
				<select id="wpv-settings-orderby" class="js-wpv-posts-orderby" name="_wpv_settings[orderby]" autocomplete="off" data-rand="<?php 
    echo esc_attr(__('Pagination and random ordering do not work together and would produce unexpected results. Please disable pagination or random ordering.', 'wpv-views'));
    ?>
">
					<option value="post_date"><?php 
    _e('Post date', 'wpv-views');
    ?>
</option>
					<option value="post_title" <?php 
    selected($view_settings['orderby'], 'post_title');
    ?>
><?php 
    _e('Post title', 'wpv-views');
    ?>
</option>
					<option value="ID" <?php 
    selected($view_settings['orderby'], 'ID');
    ?>
><?php 
    _e('Post ID', 'wpv-views');
    ?>
</option>
					<option value="modified" <?php 
    selected($view_settings['orderby'], 'modified');
    ?>
><?php 
    _e('Last modified', 'wpv-views');
    ?>
</option>
					<option value="menu_order" <?php 
    selected($view_settings['orderby'], 'menu_order');
    ?>
><?php 
    _e('Menu order', 'wpv-views');
    ?>
</option>
					<option value="rand" <?php 
    selected($view_settings['orderby'], 'rand');
    ?>
><?php 
    _e('Random order', 'wpv-views');
    ?>
</option>
					<?php 
    $all_types_fields = get_option('wpcf-fields', array());
    $cf_keys = $WP_Views->get_meta_keys();
    foreach ($cf_keys as $key) {
        $selected = $view_settings['orderby'] == "field-" . $key ? ' selected="selected"' : '';
        $option = '<option value="field-' . esc_attr($key) . '"' . $selected . '>';
        if (stripos($key, 'wpcf-') === 0) {
            if (isset($all_types_fields[substr($key, 5)]) && isset($all_types_fields[substr($key, 5)]['name'])) {
                $option .= sprintf(__('Field - %s', 'wpv-views'), $all_types_fields[substr($key, 5)]['name']);
            } else {
                $option .= sprintf(__('Field - %s', 'wpv-views'), $key);
            }
        } else {
            $option .= sprintf(__('Field - %s', 'wpv-views'), $key);
        }
        $option .= '</option>';
        echo $option;
    }
    ?>
				</select>
				<select name="_wpv_settings[order]" class="js-wpv-posts-order" autocomplete="off">
					<option value="DESC" <?php 
    selected($view_settings['order'], 'DESC');
    ?>
><?php 
    _e('Descending', 'wpv-views');
    ?>
</option>
					<option value="ASC" <?php 
    selected($view_settings['order'], 'ASC');
    ?>
><?php 
    _e('Ascending', 'wpv-views');
    ?>
</option>
				</select>
			</p>
			<p class="wpv-settings-query-type-taxonomy"<?php 
    echo $view_settings['query_type'][0] != 'taxonomy' ? ' style="display: none;"' : '';
    ?>
>
				<?php 
    $view_settings = wpv_taxonomy_order_by_default_settings($view_settings);
    $taxonomy_order_by = array('id' => __('Term ID'), 'count' => __('Post count'), 'name' => __('Term name'), 'slug' => __('Term slug'), 'term_group' => __('Term group'), 'none' => __('No order'));
    ?>
				<label for="wpv-settings-orderby"><?php 
    _e('Order by: ', 'wpv-views');
    ?>
</label>
				<select id="wpv-settings-orderby" class="js-wpv-taxonomy-orderby" name="_wpv_settings[taxonomy_orderby]" autocomplete="off">
					<?php 
    foreach ($taxonomy_order_by as $id => $text) {
        ?>
							<option value="<?php 
        echo esc_attr($id);
        ?>
" <?php 
        selected($view_settings['taxonomy_orderby'], $id);
        ?>
><?php 
        echo $text;
        ?>
</option>
						<?php 
    }
    ?>
				</select>
				<select name="_wpv_settings[taxonomy_order]" class="js-wpv-taxonomy-order" autocomplete="off">
					<option value="DESC" <?php 
    selected($view_settings['taxonomy_order'], 'DESC');
    ?>
><?php 
    _e('Descending', 'wpv-views');
    ?>
</option>
					<option value="ASC" <?php 
    selected($view_settings['taxonomy_order'], 'ASC');
    ?>
><?php 
    _e('Ascending', 'wpv-views');
    ?>
</option>
				</select>
			</p>
			<p class="wpv-settings-query-type-users"<?php 
    echo $view_settings['query_type'][0] != 'users' ? ' style="display: none;"' : '';
    ?>
>
				<?php 
    $users_order_by = array('user_login' => __('User login'), 'ID' => __('User ID'), 'user_name' => __('User name'), 'display_name' => __('User display name'), 'user_nicename' => __('User nicename'), 'user_email' => __('User email'), 'user_url' => __('User URL'), 'user_registered' => __('User registered date'), 'post_count' => __('User post count'));
    if (!isset($view_settings['users_orderby'])) {
        $view_settings['users_orderby'] = 'user_login';
    }
    if (!isset($view_settings['users_order'])) {
        $view_settings['users_order'] = 'DESC';
    }
    ?>
				<label for="wpv-settings-orderby"><?php 
    _e('Order by: ', 'wpv-views');
    ?>
</label>
				<select id="wpv-settings-orderby" class="js-wpv-users-orderby" name="_wpv_settings[users_orderby]" autocomplete="off">
					<?php 
    foreach ($users_order_by as $id => $text) {
        ?>
							<option value="<?php 
        echo esc_attr($id);
        ?>
" <?php 
        selected($view_settings['users_orderby'], $id);
        ?>
><?php 
        echo $text;
        ?>
</option>
						<?php 
    }
    ?>
				</select>
				<select name="_wpv_settings[users_order]" class="js-wpv-users-order" autocomplete="off">
					<option value="DESC" <?php 
    selected($view_settings['users_order'], 'DESC');
    ?>
><?php 
    _e('Descending', 'wpv-views');
    ?>
</option>
					<option value="ASC" <?php 
    selected($view_settings['users_order'], 'ASC');
    ?>
><?php 
    _e('Ascending', 'wpv-views');
    ?>
</option>
				</select>
			</p>
			<div class="js-wpv-toolset-messages"></div>
		</div>
		<span class="update-action-wrap auto-update js-wpv-update-action-wrap">
			<span class="js-wpv-message-container"></span>
			<span type="hidden" data-success="<?php 
    echo esc_attr(__('Updated', 'wpv-views'));
    ?>
" data-unsaved="<?php 
    echo esc_attr(__('Not saved', 'wpv-views'));
    ?>
" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_ordering_nonce');
    ?>
" class="js-wpv-ordering-update" />
		</span>
	</div>
<?php 
}
function add_view_filters($view_settings, $view_id)
{
    $hide = '';
    if (isset($view_settings['sections-show-hide']) && isset($view_settings['sections-show-hide']['content-filter']) && 'off' == $view_settings['sections-show-hide']['content-filter']) {
        $hide = ' hidden';
    }
    $section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer('filter_the_results');
    ?>
	<div class="wpv-setting-container wpv-settings-content-filter js-wpv-settings-content-filter<?php 
    echo $hide;
    ?>
">
		<div class="wpv-settings-header">
			<h3>
				<?php 
    _e('Query Filter', 'wpv-views');
    ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php 
    echo esc_attr($section_help_pointer['title']);
    ?>
" 
					data-content="<?php 
    echo esc_attr($section_help_pointer['content']);
    ?>
">
				</i>
			</h3>
		</div>
		<div class="wpv-setting">
			<p class="js-no-filters hidden"><?php 
    _e('No filters set', 'wpv-views');
    ?>
</p>
			<ul class="filter-list js-filter-list hidden">
				<?php 
    if (isset($view_settings['query_type']) && isset($view_settings['query_type'][0])) {
        wpv_display_filters_list($view_settings['query_type'][0], $view_settings);
    }
    ?>
			</ul>
			<input type="hidden" class="js-wpv-filter-update-filters-list-nonce" value="<?php 
    echo wp_create_nonce('wpv_view_filter_update_filters_list_nonce');
    ?>
" />
			<p>
				<button class="button-secondary js-wpv-filter-add-filter" type="button" data-empty="<?php 
    echo esc_attr(__('Add a filter', 'wpv-views'));
    ?>
" data-nonempty="<?php 
    echo esc_attr(__('Add another filter', 'wpv-views'));
    ?>
" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_filter_add_filter');
    ?>
">
					<i class="icon-plus"></i> <?php 
    echo esc_attr(__('Add a filter', 'wpv-views'));
    ?>
				</button>
			</p>
		</div>
	</div>

	<div class="popup-window-container"> <!-- Use this element as a container for all popup windows. This element is hidden. @todo we do now have a container for that in somewhere -->

		<div class="wpv-dialog js-filter-add-filter-form-dialog">
			<div class="wpv-dialog-header">
				<h2><?php 
    _e('Add a filter', 'wpv-views');
    ?>
</h2>
				<i class="icon-remove js-dialog-close"></i>
			</div>
			<div class="wpv-dialog-content">

				<strong><?php 
    _e('Select what to filter by:', 'wpv-views');
    ?>
</strong>

				<?php 
    wpv_filters_add_filter_select($view_settings);
    ?>

			</div>
			<div class="wpv-dialog-footer">
				<button class="button js-dialog-close js-filters-cancel-filter"><?php 
    _e('Cancel', 'wpv-views');
    ?>
</button>
				<button class="button button-primary js-filters-insert-filter" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_filters_add_filter_nonce');
    ?>
"><?php 
    _e('Add filter', 'wpv-views');
    ?>
</button>
			</div>
		</div>

		<div class="wpv-dialog js-filter-taxonomy-delete-filter-row-dialog">
			<div class="wpv-dialog-header">
				<h2><?php 
    _e('Delete taxonomy filters', 'wpv-views');
    ?>
</h2>
				<i class="icon-remove js-dialog-close"></i>
			</div>
			<div class="wpv-dialog-content">

				<h3><?php 
    _e('There are more than one taxonomy filters', 'wpv-views');
    ?>
</h3>
				<p>
					<?php 
    _e('You can delete them all at once or open the editor and delete individual filters.', 'wpv-views');
    ?>
				</p>
			</div>
			<div class="wpv-dialog-footer">
				<button class="button js-dialog-close js-filters-cancel-filter"><?php 
    _e('Cancel', 'wpv-views');
    ?>
</button>
				<button class="button js-wpv-filter-taxonomy-edit-filter-row"><?php 
    _e('Edit the taxonomy filters', 'wpv-views');
    ?>
</button>
				<button class="button button-primary js-wpv-filters-taxonomy-delete-filter-row" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_filter_taxonomy_row_delete_nonce');
    ?>
"><?php 
    _e('Delete all taxonomy filters', 'wpv-views');
    ?>
</button>
			</div>
		</div>

		<div class="wpv-dialog js-filter-custom-field-delete-filter-row-dialog">
			<div class="wpv-dialog-header">
				<h2><?php 
    _e('Delete custom field filters', 'wpv-views');
    ?>
</h2>
				<i class="icon-remove js-dialog-close"></i>
			</div>
			<div class="wpv-dialog-content">
				<h3><?php 
    _e('There are more than one custom field filters', 'wpv-views');
    ?>
</h3>
				<p>
					<?php 
    _e('You can delete them all at once or open the editor and delete individual filters.', 'wpv-views');
    ?>
				</p>
			</div>
			<div class="wpv-dialog-footer">
				<button class="button js-dialog-close js-filters-cancel-filter"><?php 
    _e('Cancel', 'wpv-views');
    ?>
</button>
				<button class="button js-filter-custom-field-edit-filter-row"><?php 
    _e('Edit the custom field filters', 'wpv-views');
    ?>
</button>
				<button class="button button-primary js-filters-custom-field-delete-filter-row" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_filter_custom_field_row_delete_nonce');
    ?>
"><?php 
    _e('Delete all custom field filters', 'wpv-views');
    ?>
</button>
			</div>
		</div>
		<div class="wpv-dialog js-filter-usermeta-field-delete-filter-row-dialog">
			<div class="wpv-dialog-header">
				<h2><?php 
    _e('Delete usermeta field filters', 'wpv-views');
    ?>
</h2>
				<i class="icon-remove js-dialog-close"></i>
			</div>
			<div class="wpv-dialog-content">
				<p>
					<strong><?php 
    _e('There are more than one usermeta field filters. What would you like to do?', 'wpv-views');
    ?>
</strong>
				</p>
			</div>
			<div class="wpv-dialog-footer">
				<button class="button js-dialog-close js-filters-cancel-filter"><?php 
    _e('Cancel', 'wpv-views');
    ?>
</button>
				<button class="button js-filter-usermeta-field-edit-filter-row"><?php 
    _e('Edit the usermeta field filters', 'wpv-views');
    ?>
</button>
				<button class="button button-primary js-filters-usermeta-field-delete-filter-row" data-nonce="<?php 
    echo wp_create_nonce('wpv_view_filter_usermeta_field_row_delete_nonce');
    ?>
"><?php 
    _e('Delete all usermeta field filters', 'wpv-views');
    ?>
</button>
			</div>
		</div>

	</div>
<?php 
}
function add_view_filter_extra( $view_settings, $view_id ) {
	$is_section_hidden = false;
	if ( isset( $view_settings['sections-show-hide'] )
		&& isset( $view_settings['sections-show-hide']['filter-extra'] )
		&& 'off' == $view_settings['sections-show-hide']['filter-extra'] )
	{
		$is_section_hidden = true;
	}
	$hidden_class = $is_section_hidden ? 'hidden' : '';

	/* An additional class js-wpv-filter-extra-section was added to the container div, so we can be sure we can
	 * distinguish it in JS.
	 *
	 * Since 1.7 we're showing the 'content' (Filter and Loop Output Integration, see add_view_content()) section on View
	 * edit page at the same time as this one, so they have to share the "js-wpv-settings-filter-extra" class (because
	 * in Screen options we're changing visibility of elements with "js-wpv-settings-{$section_name}").
	 *
	 * So, in case you need to select this particular element in JS, please use the "js-wpv-filter-extra-section" class,
	 * which is unique.
	 */ 
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'filters_html_css_js' );
	?>
	<div class="wpv-setting-container wpv-setting-container-horizontal wpv-settings-filter-markup js-wpv-settings-filter-extra js-wpv-filter-extra-section <?php echo $hidden_class; ?>">

		<div class="wpv-settings-header">
			<h3>
				<?php _e( 'Filter', 'wpv-views' ) ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
					data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
				</i>
			</h3>
		</div>
		<?php
		$listing = '';
		$purpose = 'full';
		if ( 
			isset( $view_settings['query_type'] ) 
			&& is_array( $view_settings['query_type'] ) 
			&& in_array( 'posts', $view_settings['query_type'] ) 
		) {
			$listing = 'posts';
		}
		if ( isset( $view_settings['view_purpose'] ) ) {
			$purpose = $view_settings['view_purpose'];
		}
		
		$controls_per_kind = wpv_count_filter_controls( $view_settings );
		if ( 
			isset( $controls_per_kind['missing'] ) 
			&& is_array( $controls_per_kind['missing'] ) 
			&& ! empty( $controls_per_kind['missing'] ) 
		) {
		?>
		<div class="toolset-help js-wpv-missing-filter-container"<?php echo $listing == 'posts' ? '' : ' style="display:none"'; ?>">
			<div class="toolset-help-content">
				<?php
				_e( 'This View has some query filters that are missing from the form. Maybe you have removed them:', 'wpv-views' );
				?>
				<ul class="js-wpv-filter-missing">
				<?php
				foreach ( $controls_per_kind['missing'] as $missed ) {
					?>
					<li class="js-wpv-missing-filter" data-type="<?php echo esc_attr( $missed['type'] ); ?>" data-name="<?php echo esc_attr( $missed['name'] ); ?>">
						<?php
						echo sprintf( __( 'Filter by <strong>%s</strong>', 'wpv-views' ), $missed['name'] );
						?>
					</li>
					<?php
				}
				?>
				</ul>
				<?php
				_e( 'Can they also be removed from the query filtering?', 'wpv-views' );
				?>
				<p>
					<a href="#" class="button button-primary js-wpv-filter-missing-delete" data-nonce="<?php echo wp_create_nonce( 'wpv_view_filter_missing_delete' ); ?>"><?php _e( 'Yes (recommended)', 'wpv-views' ); ?></a> <a href="#" class="button button-secondary js-wpv-filter-missing-close"><?php _e( 'No', 'wpv-views' ); ?></a>
				</p>
			</div>
			<div class="toolset-help-sidebar">
				<div class="toolset-help-sidebar-ico"></div>
			</div>
		</div>
		<?php
		} else {
		?>
		<div class="toolset-help js-wpv-missing-filter-container" style="display:none"></div>
		<?php
		}

		$controls_count = $controls_per_kind['cf'] + $controls_per_kind['tax'] + $controls_per_kind['pr'] + $controls_per_kind['search'];
		?>
		<div class="toolset-alert js-wpv-no-filters-container"<?php if ( $listing == 'posts' && $purpose == 'parametric' ) { if ( $controls_count != 0 ) { echo ' style="display:none"'; } } else { echo ' style="display:none"'; } ?>">
			<p>
				<?php _e('Remember to add filters here. Right now, this parametric search has no filter items.', 'wpv-views'); ?>
			</p>
		</div>

		<div class="wpv-setting">

			<div class="js-error-container js-wpv-parametric-error-container"></div>
			<div class="code-editor js-code-editor filter-html-editor" data-name="filter-html-editor" >
				<div class="code-editor-toolbar js-code-editor-toolbar">
					<ul class="js-wpv-filter-edit-toolbar">
						<?php 
						do_action( 'wpv_parametric_search_buttons', 'wpv_filter_meta_html_content' );
						do_action( 'wpv_views_fields_button', 'wpv_filter_meta_html_content' );
						?>
						<li class="js-editor-pagination-button-wrapper">
							<button class="button-secondary js-code-editor-toolbar-button js-wpv-pagination-popup" data-content="wpv_filter_meta_html_content">
								<i class="icon-pagination"></i>
								<span class="button-label"><?php _e('Pagination controls','wpv-views'); ?></span>
							</button>
						</li>
						<li>
							<button class="button-secondary js-code-editor-toolbar-button js-wpv-media-manager" data-id="<?php echo esc_attr( $view_id ); ?>" data-content="wpv_filter_meta_html_content">
								<i class="icon-picture"></i>
								<span class="button-label"><?php _e('Media','wpv-views'); ?></span>
							</button>
						</li>
					</ul>
				</div>
				<textarea cols="30" rows="10" id="wpv_filter_meta_html_content" autocomplete="off" name="_wpv_settings[filter_meta_html]"><?php echo ( isset( $view_settings['filter_meta_html'] ) ) ? esc_textarea( $view_settings['filter_meta_html'] ) : ''; ?></textarea>
				<?php 
				$filter_extra_css = isset( $view_settings['filter_meta_html_css'] ) ? $view_settings['filter_meta_html_css'] : '';
				$filter_extra_js = isset( $view_settings['filter_meta_html_js'] ) ? $view_settings['filter_meta_html_js'] : '';
				?>
				<div class="wpv-editor-metadata-toggle js-wpv-editor-metadata-toggle js-wpv-assets-editor-toggle" data-instance="filter-css-editor" data-target="js-wpv-assets-filter-css-editor" data-type="css">
					<span class="wpv-toggle-toggler-icon js-wpv-toggle-toggler-icon">
						<i class="icon-caret-down icon-large"></i>
					</span>
					<i class="icon-pushpin js-wpv-textarea-full" style="<?php echo ( empty( $filter_extra_css ) ) ? 'display:none;' : ''; ?>"></i>
					<strong><?php _e( 'CSS editor', 'wpv-views' ); ?></strong>
				</div>
				<div id="wpv-assets-filter-css-editor" class="wpv-assets-editor hidden js-wpv-assets-filter-css-editor">
					<textarea cols="30" rows="10" id="wpv_filter_meta_html_css" autocomplete="off" name="_wpv_settings[filter_meta_html_css]"><?php echo esc_textarea( $filter_extra_css ); ?></textarea>
				</div>
				
				<div class="wpv-editor-metadata-toggle js-wpv-editor-metadata-toggle js-wpv-assets-editor-toggle" data-instance="filter-js-editor" data-target="js-wpv-assets-filter-js-editor" data-type="js">
					<span class="wpv-toggle-toggler-icon js-wpv-toggle-toggler-icon">
						<i class="icon-caret-down icon-large"></i>
					</span>
					<i class="icon-pushpin js-wpv-textarea-full" style="<?php echo ( empty( $filter_extra_js ) ) ? 'display:none;' : ''; ?>"></i>
					<strong><?php _e( 'JS editor', 'wpv-views' ); ?></strong>
				</div>
				<div id="wpv-assets-filter-js-editor" class="wpv-assets-editor hidden js-wpv-assets-filter-js-editor">
					<div class="code-editor-toolbar js-code-editor-toolbar">
						<ul class="js-wpv-filter-js-edit-toolbar">
							<li class="js-wpv-views-frontend-events-wrapper">
								<button class="button button-secondary button-small js-code-editor-toolbar-button js-wpv-views-frontend-events-popup" data-content="wpv_filter_meta_html_js">
									<i class="icon-fire"></i>
									<span class="button-label"><?php _e('Frontend events','wpv-views'); ?></span>
								</button>
							</li>
						</ul>
					</div>
					<textarea cols="30" rows="10" id="wpv_filter_meta_html_js" autocomplete="off" name="_wpv_settings[filter_meta_html_js]"><?php echo esc_textarea( $filter_extra_js ); ?></textarea>
				</div>
				<?php
				wpv_formatting_help_filter();
				?>
			</div>
			<p class="update-button-wrap js-wpv-update-button-wrap">
				<span class="js-wpv-message-container"></span>
				<button data-success="<?php echo esc_attr( __('Updated', 'wpv-views') ); ?>" data-unsaved="<?php echo esc_attr( __('Not saved', 'wpv-views') ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_filter_extra_nonce' ); ?>" class="js-wpv-filter-extra-update button-secondary" disabled="disabled"><?php _e('Update', 'wpv-views'); ?></button>
			</p>
		</div>

	</div>
	
	<div id="js-wpv-parametric-search-dialogs" class="popup-window-container"> <!-- Use this element as a container for all popup windows. This element is hidden. -->
		
		<!-- Dialogs for settings when inserting shortcodes -->
		<div class="toolset-shortcode-gui-dialog-container wpv-shortcode-gui-dialog-container wpv-dialog-parametric-filter wpv-dialog-search-box js-dialog-search-box-button">
			
			<div class="wpv-dialog wpv-shortcode-gui-content-wrapper js-search_shortcode_label-wrap">
				<h3>
					<?php _e( 'Where to search', 'wpv-views' ); ?>
				</h3>
				<p>
					<input value="full_content" name="wpv-post-search-options-dialog" class="js-wpv-post-search-options-dialog" checked="checked" id="search-shortcode-full" type="radio">
					<label for="search-shortcode-full" class="label-alignleft"><?php _e('Post content and title', 'wpv-views'); ?></label>
					<span class="wpv-helper-text"><?php _e( 'Use this to search in both post contents and titles', 'wpv-views' ); ?></span>
				</p>
				<p>
					<input value="just_title" name="wpv-post-search-options-dialog" class="js-wpv-post-search-options-dialog" id="search-shortcode-title" type="radio">
					<label for="search-shortcode-title" class="label-alignleft"><?php _e('Just post title', 'wpv-views'); ?></label>
					<span class="wpv-helper-text"><?php _e( 'Use this to search just in titles', 'wpv-views' ); ?></span>
				</p>
				<h3><?php _e( 'Styling options', 'wpv-views' ); ?></h3>
				<p>
					<label for="search_box_shortcode_button_classname" class="label-alignleft"><?php _e('Input classname:', 'wpv-views'); ?></label>
					<input value="" id="search_box_shortcode_button_classname" type="text" class="js-wpv-search-box-class" />
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own classnames to the text input', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="search_box_shortcode_button_style" class="label-alignleft"><?php _e('Input style:', 'wpv-views'); ?></label>
					<input value="" id="search_box_shortcode_button_style" type="text" class="js-wpv-search-box-style" />
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own styling to the text input', 'wpv-views' ); ?></span>
				</p>
			</div>
			
			<div class="js-errors-in-parametric-box"></div>
			
		</div> <!-- End of popup for the search box addition -->
		
		<div class="toolset-shortcode-gui-dialog-container wpv-shortcode-gui-dialog-container wpv-dialog-parametric-filter wpv-dialog-search-override js-dialog-search-override-button">
			
			<div class="wpv-dialog wpv-shortcode-gui-content-wrapper js-search_shortcode_override_label-wrap">
				<h3><?php _e( 'Complete the search filter', 'wpv-views' ); ?></h3>
				<p class="js-wpv-search-filter-override-var js-wpv-search-filter-override-valid">
				<?php _e('This View already has a valid search filter, but it is missing the search box.', 'wpv-views' ); ?>
				</p>
				<p class="js-wpv-search-filter-override-var js-wpv-search-filter-override-valid">
				<?php _e( 'You can override the filter settings and add the search box here.', 'wpv-views'); ?>
				</p>
				<p class="js-wpv-search-filter-override-var js-wpv-search-filter-override-specific">
				<?php _e('This View already has a filter set to filter by a specific string.', 'wpv-views' ); ?>
				</p>
				<p class="js-wpv-search-filter-override-var js-wpv-search-filter-override-specific">
				<?php _e( 'You can fix this filter here.', 'wpv-views'); ?>
				</p>
				<p class="js-wpv-search-filter-override-var js-wpv-search-filter-override-missing">
				<?php _e('This View already has a content search box, but the relevant filter is missing.', 'wpv-views' ); ?>
				</p>
				<p class="js-wpv-search-filter-override-var js-wpv-search-filter-override-missing">
				<?php _e( 'You can add this filter here.', 'wpv-views'); ?>
				</p>
				
				<h3>
					<?php _e( 'Where to search', 'wpv-views' ); ?>
				</h3>
				<p>
					<input value="full_content" name="wpv-post-search-override-dialog" class="js-wpv-post-search-override-dialog" checked="checked" id="search-override-full" type="radio">
					<label for="search-override-full" class="label-alignleft"><?php _e('Post content and title', 'wpv-views'); ?></label>
					<span class="wpv-helper-text"><?php _e( 'Use this to search in both post contents and titles', 'wpv-views' ); ?></span>
				</p>
				<p>
					<input value="just_title" name="wpv-post-search-override-dialog" class="js-wpv-post-search-override-dialog" id="search-override-title" type="radio">
					<label for="search-override-title" class="label-alignleft"><?php _e('Just post title', 'wpv-views'); ?></label>
					<span class="wpv-helper-text"><?php _e( 'Use this to search just in titles', 'wpv-views' ); ?></span>
				</p>
				
				<h3><?php _e( 'Styling options', 'wpv-views' ); ?></h3>
				<p>
					<label for="search_override_shortcode_button_classname" class="label-alignleft"><?php _e('Input classname:', 'wpv-views'); ?></label>
					<input value="" id="search_override_shortcode_button_classname" type="text" class="js-wpv-search-override-class" />
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own classnames to the text input', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="search_override_shortcode_button_style" class="label-alignleft"><?php _e('Input style:', 'wpv-views'); ?></label>
					<input value="" id="search_override_shortcode_button_style" type="text" class="js-wpv-search-override-style" />
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own styling to the text input', 'wpv-views' ); ?></span>
				</p>
			</div>
			
		</div> <!-- End of popup for the search override -->
		
		<div class="toolset-shortcode-gui-dialog-container wpv-shortcode-gui-dialog-container wpv-dialog-parametric-filter wpv-dialog-submit-button js-wpv-dialog-submit-button"> <!-- Popup for the submit button addition -->
			
			<div class="wpv-dialog ">
				<p>
					<label for="submit_shortcode_label" class="label-alignleft"><?php _e('Button label:', 'wpv-views'); ?></label>
					<input value="<?php echo esc_attr( __('Search', 'wpv-views') ); ?>" id="submit_shortcode_label" type="text">
				</p>
				<p>
					<label for="submit_shortcode_button_classname" class="label-alignleft"><?php _e('Button classname:', 'wpv-views'); ?></label>
					<input value="" id="submit_shortcode_button_classname" type="text">
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own classnames to the submit button', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="submit_shortcode_button_style" class="label-alignleft"><?php _e('Button style:', 'wpv-views'); ?></label>
					<input value="" id="submit_shortcode_button_style" type="text">
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own styling to the submit button', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="submit_shortcode_button_tag" class="label-alignleft"><?php _e('Button HTML tag:', 'wpv-views'); ?></label>
					<select id="submit_shortcode_button_tag">
						<option selected=·selected· value="input"><?php _e( 'Input', 'wpv-views' ); ?></option>
						<option value="button"><?php _e( 'Button', 'wpv-views' ); ?></option>
					</select>
					<span class="wpv-helper-text"><?php _e( 'You can use an input or a button', 'wpv-views' ); ?></span>
				</p>
			</div>
			
			<div class="js-errors-in-parametric-box"></div>
			
		</div> <!-- End of popup for the submit button addition -->
		
		<div class="toolset-shortcode-gui-dialog-container wpv-shortcode-gui-dialog-container wpv-dialog-parametric-filter wpv-dialog-reset-button js-wpv-dialog-reset-button"> <!-- Popup for the reset button addition -->
			
			<div class="wpv-dialog">
				<p>
					<label for="reset_shortcode_label" class="label-alignleft"><?php _e('Button label:', 'wpv-views'); ?></label>
					<input value="<?php echo esc_attr( __('Reset', 'wpv-views') ); ?>" id="reset_shortcode_label" type="text">
					<!--<span class="wpv-helper-text">lorem</span>-->
				</p>
				<p>
					<label for="reset_shortcode_button_classname" class="label-alignleft"><?php _e('Button classname:', 'wpv-views'); ?></label>
					<input value="" id="reset_shortcode_button_classname" type="text">
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own classnames to the reset button', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="reset_shortcode_button_style" class="label-alignleft"><?php _e('Button style:', 'wpv-views'); ?></label>
					<input value="" id="reset_shortcode_button_style" type="text">
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own styling to the reset button', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="reset_shortcode_button_tag" class="label-alignleft"><?php _e('Button HTML tag:', 'wpv-views'); ?></label>
					<select id="reset_shortcode_button_tag">
						<option selected=·selected· value="input"><?php _e( 'Input', 'wpv-views' ); ?></option>
						<option value="button"><?php _e( 'Button', 'wpv-views' ); ?></option>
					</select>
					<span class="wpv-helper-text"><?php _e( 'You can use an input or a button', 'wpv-views' ); ?></span>
				</p>
			</div>
			
			<div class="js-errors-in-parametric-box"></div>
			
		</div> <!-- End of popup for the reset button addition -->
		
		<div class="toolset-shortcode-gui-dialog-container wpv-shortcode-gui-dialog-container wpv-dialog-parametric-filter wpv-dialog-spinner-button js-wpv-dialog-spinner-button"> <!-- Popup for the spinner button addition -->
			
			<div class="wpv-dialog">
			
				<p>
					<label for="spinner_shortcode_container_type" class="label-alignleft"><?php _e('Container type:', 'wpv-views'); ?></label>
					<select id="spinner_shortcode_container_type">
						<option value="div"><?php _e('Division', 'wpv-views'); ?></option>
						<option value="p"><?php _e('Paragraph', 'wpv-views'); ?></option>
						<option value="span"><?php _e('Span', 'wpv-views'); ?></option>
					</select>
					<span class="wpv-helper-text"><?php _e( 'You can display your spinner inside different kind of HTML elements', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="spinner_shortcode_container_classname" class="label-alignleft"><?php _e('Container classname:', 'wpv-views'); ?></label>
					<input value="" id="spinner_shortcode_container_classname" type="text">
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own classnames to the spinner container', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="spinner_shortcode_container_style" class="label-alignleft"><?php _e('Container style:', 'wpv-views'); ?></label>
					<input value="" id="spinner_shortcode_container_style" type="text">
					<span class="wpv-helper-text"><?php _e( 'Use this to add your own styling to the spinner container', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="spinner_shortcode_spinner_position" class="label-alignleft"><?php _e('Spinner placement:', 'wpv-views'); ?></label>
					<select id="spinner_shortcode_spinner_position">
						<option value="none"><?php _e('Do not show the spinner', 'wpv-views'); ?></option>
						<option value="before"><?php _e('Before the text', 'wpv-views'); ?></option>
						<option value="after"><?php _e('After the text', 'wpv-views'); ?></option>
					</select>
					<span class="wpv-helper-text"><?php _e( 'Whether the spinner should be added at the beginning or the end of the container', 'wpv-views' ); ?></span>
				</p>
				<p>
					<label for="spinner_shortcode_spinner_image" class="label-alignleft"><?php _e('Spinner image:', 'wpv-views'); ?></label>
					<ul style="overflow:hidden">
					<?php
					$has_spinner_image_checked = false;
					$available_spinners = array();
					$available_spinners = apply_filters( 'wpv_admin_available_spinners', $available_spinners );
					foreach ( $available_spinners as $av_spinner ) {
						?>
						<li style="min-width:49%;float:left;">
							<label>
								<input type="radio" class="js-wpv-ps-spinner-image" name="wpv-dps-spinner-image" value="<?php echo esc_url( $av_spinner['url'] ); ?>" <?php if ( ! $has_spinner_image_checked ) { echo ' checked="checked"'; } ?> />
								<img src="<?php echo esc_url( $av_spinner['url'] ); ?>" title="<?php echo esc_attr( $av_spinner['title'] ); ?>" />
							</label>
						</li>
						<?php 
						$has_spinner_image_checked = true;
					};
					?>
					</ul>
				</p>
				<p>
					<label for="spinner_shortcode_content" class="label-alignleft"><?php _e('Container text:','wpv-views'); ?></label>
					<textarea id="spinner_shortcode_content"></textarea>
					<span class="wpv-helper-text"><?php _e( 'This will be shown inside the container and along with the spinner', 'wpv-views' ); ?></span>
				</p>
				
				<div class="js-errors-in-parametric-box"></div>
			
			</div>
			
		</div> <!-- End of popup for the spinner button addition -->
		
		<!-- Pointer contents -->
		
		
	
	</div><!-- popup-window-container end -->
<?php }
function add_view_pagination( $view_settings, $view_id ) { //TODO review that default values are set before we display any of this
    global $WP_Views_fapi;
	$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'),
	);
	$ajax_effects = 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'),
	);
	$posts_per_page_options = array();
	for ( $index = 1; $index < 51; $index++ ) {
		$posts_per_page_options[$index] = $index;
	}
	$posts_per_page_options = apply_filters( 'wpv_filter_extend_posts_per_page_options', $posts_per_page_options );
	$hide = '';
	if (
		isset( $view_settings['sections-show-hide'] ) 
		&& isset( $view_settings['sections-show-hide']['pagination'] ) 
		&& 'off' == $view_settings['sections-show-hide']['pagination']
	) {
		$hide = ' hidden';
	}
	$section_help_pointer = WPV_Admin_Messages::edit_section_help_pointer( 'pagination_and_sliders_settings' );
	?>
	<div class="wpv-setting-container wpv-settings-pagination js-wpv-settings-pagination<?php echo $hide; ?>">
		<div class="wpv-settings-header">
			<h3>
				<?php _e( 'Pagination and Sliders Settings', 'wpv-views' ) ?>
				<i class="icon-question-sign js-display-tooltip" 
					data-header="<?php echo esc_attr( $section_help_pointer['title'] ); ?>" 
					data-content="<?php echo esc_attr( $section_help_pointer['content'] ); ?>">
				</i>
			</h3>
		</div>
		<div class="wpv-setting js-wpv-setting">
			<form class="js-pagination-settings-form">
				<?php
				if ( ! isset( $view_settings['pagination'][0] ) ) {
					$view_settings['pagination'][0] = 'disable';
				}
				if ( ! isset( $view_settings['pagination']['mode'] ) ) {
					$view_settings['pagination']['mode'] = 'none';
				}
				?>
				<input type="hidden" class="js-pagination-zero" name="pagination[]" value="<?php echo esc_attr( $view_settings['pagination'][0] ); ?>" autocomplete="off" />
				<ul>
					<li>
						<input type="radio" id="wpv-settings-no-pagination" class="js-wpv-pagination-mode" name="pagination[mode]" value="none" <?php checked( $view_settings['pagination'][0], 'disable' ); ?> autocomplete="off" />
						<label for="wpv-settings-no-pagination"><strong><?php _e('No pagination','wpv-views') ?></strong></label>
						<span class="helper-text"><?php _e('All query results will display.','wpv-views') ?></span>
					</li>
					<li>
						<?php $checked = ( $view_settings['pagination'][0]=='enable' && $view_settings['pagination']['mode']=='paged' ) ? ' checked="checked"' : ''; ?>
						<input type="radio" id="wpv-settings-manual-pagination" class="js-wpv-pagination-mode" name="pagination[mode]" value="paged"<?php echo $checked; ?> autocomplete="off" />
						<label for="wpv-settings-manual-pagination"><strong><?php _e( 'Pagination enabled with manual transition', 'wpv-views' ) ?></strong></label>
						<span class="helper-text"><?php _e( 'The query results will display in pages, which visitors will switch.', 'wpv-views' ) ?></span>
					</li>
					<li>
						<input type="radio" id="wpv-settings-ajax-pagination" class="js-wpv-pagination-mode" name="pagination[mode]" value="rollover" <?php checked( $view_settings['pagination']['mode'], 'rollover' ); ?> autocomplete="off" />
						<label for="wpv-settings-ajax-pagination"><strong><?php _e( 'Pagination enabled with automatic transition', 'wpv-views' ) ?></strong></label>
						<span class="helper-text"><?php _e( 'The query results will display in pages, which will switch automatically (good for sliders).', 'wpv-views' ) ?></span>
					</li>
				</ul>

				<div class="wpv-advanced-setting wpv-pagination-options-box">

					<h3 class="wpv-pagination-paged"><?php _e('Options for manual pagination','wpv-views'); ?></h3>
					<ul class="wpv-pagination-paged">
						<li>
							<label><?php _e('Number of items per page:', 'wpv-views')?></label>
							<select name="posts_per_page" autocomplete="off">
								<?php if ( 
									! isset( $view_settings['posts_per_page'] ) 
									|| (
										! $WP_Views_fapi->framework_valid
										&& strpos( $view_settings['posts_per_page'], 'FRAME_KEY' ) !== false
									)
								) {
									$view_settings['posts_per_page'] = '10';
								}
								foreach ( $posts_per_page_options as $index => $value ) {
									?>
									<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $view_settings['posts_per_page'], $index, true ); ?>><?php echo $value; ?></option>
									<?php
								}
								?>
							</select>
						</li>
						<li>
							<?php $checked = ( isset( $view_settings['ajax_pagination'][0] ) && $view_settings['ajax_pagination'][0] == 'disable') ? ' checked="checked"' : ''; ?>
							<input type="radio" id="wpv-settings-ajax-pagination-disabled" class="js-wpv-ajax_pagination" value="disable" name="ajax_pagination[]"<?php echo $checked; ?> autocomplete="off" />
							<label for="wpv-settings-ajax-pagination-disabled"><?php _e('Pagination updates the entire page', 'wpv-views'); ?></label>
						</li>
						<li>
							<?php $checked = ( isset( $view_settings['ajax_pagination'][0] ) && $view_settings['ajax_pagination'][0] == 'enable') ? ' checked="checked"' : ''; ?>
							<input type="radio" id="wpv-settings-ajax-pagination-enabled" class="js-wpv-ajax_pagination" value="enable" name="ajax_pagination[]"<?php echo $checked; ?> autocomplete="off" />
							<label for="wpv-settings-ajax-pagination-enabled"><?php _e('Pagination updates only the view (use AJAX)', 'wpv-views'); ?></label>
						</li>
					</ul>

					<ul class="wpv-pagination-paged-ajax" style="margin-bottom:0;">
						<li>
							<p>
								<label><?php _e('Transition effect:', 'wpv-views')?></label>
								<select name="ajax_pagination[style]" autocomplete="off">
									<?php 
									if ( ! isset( $view_settings['ajax_pagination']['style'] ) ) {
										$view_settings['ajax_pagination']['style'] = 'fade';
									}
									?>
									<option value="fade"<?php if ($view_settings['ajax_pagination']['style'] == 'fade' || $view_settings['ajax_pagination']['style'] == 'fadefast' || $view_settings['ajax_pagination']['style'] == 'fadeslow') { echo ' selected="selected"'; } ?>><?php _e('Fade',  'wpv-views'); ?></option>
									<option value="slideh" <?php selected( $view_settings['ajax_pagination']['style'], 'slideh' ); ?>><?php _e('Slide horizontally',  'wpv-views'); ?></option>
									<option value="slidev" <?php selected( $view_settings['ajax_pagination']['style'], 'slidev' ); ?>><?php _e('Slide vertically',  'wpv-views'); ?></option>
								</select>

								<label>
									<?php _e('with duration',  'wpv-views'); ?>
									<?php 
									if ( ! isset( $view_settings['ajax_pagination']['duration'] ) ) {
										$view_settings['ajax_pagination']['duration'] = 500;
									}
									if ( $view_settings['ajax_pagination']['style'] == 'fadefast' ) {
										$view_settings['ajax_pagination']['duration'] = 1;
									}
									if ( $view_settings['ajax_pagination']['style'] == 'fadeslow' ) {
										$view_settings['ajax_pagination']['duration'] = 1500;
									}
									?>
									<input type="text" class="transition-duration" name="ajax_pagination[duration]" value="<?php echo esc_attr( $view_settings['ajax_pagination']['duration'] ); ?>" size="5" autocomplete="off" />
								</label>
								<?php _e('miliseconds', 'wpv-views'); ?>
								<span class="duration-error" style="color:red;display:none;">&larr; <?php _e('Please add a numeric value', 'wpv-views'); ?></span>
							</p>
							<p>
								<button class="js-pagination-advanced button-secondary" type="button" data-closed="<?php echo esc_attr( __( 'Advanced options', 'wpv-views' ) ); ?>" data-opened="<?php echo esc_attr( __( 'Close advanced options', 'wpv-views' ) ); ?>" data-section="ajax_pagination" data-state="closed"><?php _e( 'Advanced options', 'wpv-views' ); ?></button>
							</p>
						</li>
						<li class="wpv-pagination-advanced hidden">
							<h4><?php _e( 'Cache and preload', 'wpv-views' ); ?></h4>
							<?php $checked = ( isset( $view_settings['pagination']['preload_images'] ) && $view_settings['pagination']['preload_images'] ) ? ' checked="checked"' : '';?>
							<label>
								<input type="checkbox" name="pagination[preload_images]" value="1"<?php echo $checked; ?> autocomplete="off" />
								<?php _e('Preload images before transition',  'wpv-views'); ?>
							</label>
						</li>
					</ul>

					<h3 class="wpv-pagination-rollover"><?php _e('Options for automatic pagination', 'wpv-views')?></h3>
					<ul class="wpv-pagination-rollover" style="margin-bottom:0;">
						<li>
							<label for="rollover[posts_per_page]"><?php _e('Number of items per page:', 'wpv-views'); ?></label>
							<select name="rollover[posts_per_page]" autocomplete="off">
								<?php 
								if ( 
									! isset( $view_settings['rollover']['posts_per_page'] ) 
									|| (
										! $WP_Views_fapi->framework_valid
										&& strpos( $view_settings['rollover']['posts_per_page'], 'FRAME_KEY' ) !== false
									)
								) {
									$view_settings['rollover']['posts_per_page'] = '10';
								}
								foreach ( $posts_per_page_options as $index => $value ) {
									?>
									<option value="<?php echo esc_attr( $index ); ?>" <?php selected( $view_settings['rollover']['posts_per_page'], $index ); ?>><?php echo $value; ?></option>
									<?php
								}
								?>
							</select>
						</li>
						<li>
							<label><?php _e('Show each page for:', 'wpv-views')?></label>
							<select name="rollover[speed]" autocomplete="off">
								<?php 
								if ( ! isset( $view_settings['rollover']['speed'] ) ) {
									$view_settings['rollover']['speed'] = '5';
								}
								for ( $i = 1; $i < 20; $i++ ) {
									?>
									<option value="<?php echo esc_attr( $i ); ?>" <?php selected( $view_settings['rollover']['speed'], (string) $i ); ?>><?php echo $i; ?></option>
									<?php
								}
								?>
							</select>&nbsp;<?php _e('seconds', 'wpv-views')?>
						</li>
						<li>
							<label><?php _e('Transition effect:', 'wpv-views')?></label>
							<select name="rollover[effect]" autocomplete="off">
								<?php
								if ( ! isset( $view_settings['rollover']['effect'] ) ) {
									$view_settings['rollover']['effect'] = 'fade';
								}
								foreach ( $rollover_effects as $i => $title ) {
									?>
									<option value="<?php echo esc_attr( $i ); ?>" <?php selected( $view_settings['rollover']['effect'], (string) $i ); ?>><?php echo $title; ?></option>
									<?php
								}
								?>
							</select>
							<label><?php _e('with duration',  'wpv-views'); ?></label>
								<?php 
								if ( ! isset( $view_settings['rollover']['duration'] ) ) {
									$view_settings['rollover']['duration'] = 500;
								}
								?>
								<input type="text" class="transition-duration" name="rollover[duration]" value="<?php echo esc_attr( $view_settings['rollover']['duration'] ); ?>" size="5" autocomplete="off" />
							<?php _e('miliseconds', 'wpv-views'); ?>
							<span class="duration-error" style="color:red;display:none;"><?php _e(' <- Please add a numeric value', 'wpv-views'); ?></span>
							<p>
								<button class="js-pagination-advanced button-secondary" type="button" data-closed="<?php _e( 'Advanced options', 'wpv-views' ) ?>" data-opened="<?php _e( 'Close advanced options', 'wpv-views' ) ?>" data-section="rollover" data-state="closed"><?php _e( 'Advanced options', 'wpv-views' ) ?></button>
							</p>
						</li>
						<li class="wpv-pagination-advanced hidden">
							<h4><?php _e( 'Cache and preload', 'wpv-views' ); ?></h4>
							<?php $checked = ( isset( $view_settings['rollover']['preload_images'] ) && $view_settings['rollover']['preload_images'] ) ? ' checked="checked"' : '';?>
							<label>
								<input type="checkbox" name="rollover[preload_images]" value="1"<?php echo $checked; ?> autocomplete="off" />
								<?php _e('Preload images before transition',  'wpv-views'); ?>
							</label>
						</li>
					</ul>

					<ul class="wpv-pagination-paged wpv-pagination-rollover wpv-pagination-shared wpv-pagination-advanced hidden" style="padding-bottom:10px;">
						<li>
							<?php $checked = ( isset( $view_settings['pagination']['cache_pages'] ) && $view_settings['pagination']['cache_pages'] ) ? ' checked="checked"' : '';?>
							<p>
								<label>
									<input type="checkbox" name="pagination[cache_pages]" value="1"<?php echo $checked; ?> autocomplete="off" />
									<?php _e('Cache pages',  'wpv-views'); ?>
								</label>
							</p>
						</li>
						<li>
							<?php $checked = ( isset( $view_settings['pagination']['preload_pages'] ) && $view_settings['pagination']['preload_pages'] ) ? ' checked="checked"' : '';?>
							<p>
								<label>
									<input type="checkbox" name="pagination[preload_pages]" value="1"<?php echo $checked; ?> autocomplete="off" />
									<?php _e('Pre-load the next and previous pages - avoids loading delays when users move between pages',  'wpv-views'); ?>
								</label>
							</p>

							<p>
								<label><?php _e('Pages to pre-load: ',  'wpv-views'); ?></label>
								<select name="pagination[pre_reach]" autocomplete="off">
								<?php 
									if ( ! isset( $view_settings['pagination']['pre_reach'] ) ) {
										$view_settings['pagination']['pre_reach'] = 1;
									}
									for ( $i = 1; $i < 20; $i++ ) {
										?>
										<option value="<?php echo esc_attr( $i ); ?>" <?php selected( $view_settings['pagination']['pre_reach'], $i ); ?>><?php echo $i; ?></option>
										<?php
									}
									?>
								</select>
							</p>
						</li>
						<li>
							<h4><?php _e('Spinners',  'wpv-views'); ?></h4>
							<?php $checked = ( isset($view_settings['pagination']['spinner']) && $view_settings['pagination']['spinner'] == 'default' ) ? ' checked="checked"' : '';?>
							<ul>
								<li>
									<label>
										<input type="radio" class="js-wpv-pagination-spinner" name="pagination[spinner]" value="default"<?php echo $checked; ?> autocomplete="off" />
										<?php _e('Spinner graphics from Views', 'wpv-views'); ?>
									</label>
									<ul id="wpv-spinner-default" class="wpv-spinner-selection wpv-mightlong-list wpv-setting-extra js-wpv-pagination-spinner-default">
									<?php
									if ( isset( $view_settings['pagination']['spinner_image'] ) ) {
										$spinner_image = $view_settings['pagination']['spinner_image'];
									} else {
										$spinner_image = '';
									}
									$available_spinners = array();
									$available_spinners = apply_filters( 'wpv_admin_available_spinners', $available_spinners );
									foreach ( $available_spinners as $av_spinner ) {
									?>
										<li>
											<label>
												<input type="radio" name="pagination[spinner_image]" value="<?php echo esc_url( $av_spinner['url'] ); ?>" <?php checked( $spinner_image, $av_spinner['url'] ); ?> autocomplete="off" />
												<img style="background-color: #FFFFFF;" src="<?php echo esc_url( $av_spinner['url'] ); ?>" title="<?php echo esc_attr( $av_spinner['title'] ); ?>" />
											</label>
										</li>
									<?php } ?>
									</ul>
								</li>
								<?php $checked = ( isset( $view_settings['pagination']['spinner'] ) && $view_settings['pagination']['spinner'] == 'uploaded' ) ? ' checked="checked"' : '';?>
								<li>
									<label>
										<input type="radio" class="js-wpv-pagination-spinner" name="pagination[spinner]" value="uploaded"<?php echo $checked; ?> autocomplete="off" />
										<?php _e('My custom spinner graphics', 'wpv-views'); ?>
									</label>
									<p id="wpv-spinner-uploaded" class="wpv-spinner-selection js-wpv-pagination-spinner-uploaded">
										<input id="wpv-pagination-spinner-image" class="js-wpv-pagination-spinner-image" type="text" name="pagination[spinner_image_uploaded]" value="<?php echo isset( $view_settings['pagination']['spinner_image_uploaded'] ) ? esc_url( $view_settings['pagination']['spinner_image_uploaded'] ) : ''; ?>" autocomplete="off" />
										<button class="button-secondary js-code-editor-toolbar-button js-wpv-media-manager" data-content="wpv-pagination-spinner-image" data-id="<?php echo esc_attr( $view_id ); ?>"><?php _e('Upload Image', 'wpv-views'); ?></button>
										<?php 
										$spinner_image_uploaded = '';
										if ( isset( $view_settings['pagination']['spinner_image_uploaded'] ) && ! empty( $view_settings['pagination']['spinner_image_uploaded'] ) ) {
											$spinner_image_uploaded = $view_settings['pagination']['spinner_image_uploaded'];
										}
										?>
										<img id="wpv-pagination-spinner-image-preview" class="js-wpv-pagination-spinner-image-preview" src="<?php echo esc_url( $spinner_image_uploaded ); ?>" height="16"<?php if ( empty( $spinner_image_uploaded ) ) { echo ' style="display:none;"'; } ?> />
									</p>
								</li>
								<li>
								<?php $checked = ( isset( $view_settings['pagination']['spinner'] ) &&  $view_settings['pagination']['spinner'] == 'no' ) ? ' checked="checked"' : '';?>
									<label>
										<input type="radio" class="js-wpv-pagination-spinner" name="pagination[spinner]" value="no"<?php echo $checked; ?> autocomplete="off" />
										<?php _e('No spinner graphics', 'wpv-views'); ?>
									</label>
								</li>
							</ul>
						</li>
						<li>
							<h4><?php _e('Callback function', 'wpv-views'); ?></h4>
							<p><?php _e('Javascript function to execute after the pagination transition has been completed:', 'wpv-views'); ?></p>
							<ul><?php // TODO add a callback to execute before the pagination starts ?>
								<li>
									<input id="wpv-pagination-callback-next" class="js-wpv-pagination-callback-next" type="text" name="pagination[callback_next]" value="<?php echo isset( $view_settings['pagination']['callback_next'] ) ? esc_attr( $view_settings['pagination']['callback_next'] ) : ''; ?>" autocomplete="off" />
								</li>
							</ul>
						</li>
					</ul>
				</div> <!-- .ggwpv-pagination-options-box -->

			</form>
			<div class="js-wpv-toolset-messages"></div>
		</div>
		<span class="update-button-wrap auto-update js-wpv-update-action-wrap">
			<span class="js-wpv-message-container"></span>
			<input type="hidden" data-success="<?php echo esc_attr( __('Updated', 'wpv-views') ); ?>" data-unsaved="<?php echo esc_attr( __('Not saved', 'wpv-views') ); ?>" data-nonce="<?php echo wp_create_nonce( 'wpv_view_pagination_nonce' ); ?>" class="js-wpv-pagination-update" />
		</span>

	</div>
	
<?php }