function wpv_admin_archive_listing_usage() {

    ?>
	<table id="wpv_view_list_usage" class="js-wpv-views-listing wpv-views-listing wpv-views-listing-by-usage widefat">
		<thead>
			<tr>
				<th class="wpv-admin-listing-col-usage js-wpv-col-one"><?php _e('Archive loop','wpv-views') ?></th>
				<th class="wpv-admin-listing-col-title js-wpv-col-two"><?php _e('WordPress Archive used','wpv-views') ?></th>
			</tr>
		</thead>
		<tfoot>
			<tr>
				<th class="wpv-admin-listing-col-usage js-wpv-col-one"><?php _e('Used for','wpv-views') ?></th>
				<th class="wpv-admin-listing-col-title js-wpv-col-two"><?php _e('Title','wpv-views') ?></th>
			</tr>
		</tfoot>

		<tbody class="js-wpv-views-listing-body">
			<?php
				global $WPV_settings;

				$alternate = '';

				$loops = array(
						'home-blog-page' => __('Home/Blog', 'wpv-views'),
						'search-page' => __('Search results', 'wpv-views'),
						'author-page' => __('Author archives', 'wpv-views'),
						'year-page' => __('Year archives', 'wpv-views'),
						'month-page' => __('Month archives', 'wpv-views'),
						'day-page' => __('Day archives', 'wpv-views') );

				foreach ( $loops as $slug => $name ) {
					$alternate = ' alternate' == $alternate ? '' : ' alternate';
					$post = null;
					if ( isset( $WPV_settings['view_' . $slug] ) ) {
						$post = get_post( $WPV_settings['view_' . $slug] );
					}

					?>
					<tr class="js-wpv-view-list-row<?php echo $alternate; ?>">
						<td class="wpv-admin-listing-col-usage">
							<span class="row-title"><?php echo $name ?></span>
							<?php
								echo wpv_admin_table_row_actions(
										array( "change_usage js-wpv-wpa-usage-action-change-usage" => sprintf( '<a href="#">%s</a>', __( 'Change WordPress Archive' , 'wpv-views' ) ) ),
										array( "data-view-id" => 'view_' . $slug ) );
							?>
						</td>
						<?php
							if ( is_null( $post ) ) {
								?>
								<td colspan="2">
									<a class="button button-small js-wpv-create-wpa-for-archive-loop" data-forwhomtitle="<?php echo esc_attr( $name ); ?>" data-forwhomloop="<?php echo esc_attr( 'wpv-view-loop-' . $slug ); ?>" href="#">
										<i class="icon-plus"></i>
										<?php _e('Create a WordPress Archive for this loop');?>
									</a>
								</td>
								<?php
							} else {
								?>
								<td class="wpv-admin-listing-col-title">
									<?php
										printf(
											'<a href="%s">%s</a>',
											esc_url( add_query_arg(
													array( 'page' => 'view-archives-editor', 'view_id' => $post->ID ),
													admin_url( 'admin.php' ) ) ),
											esc_html( $post->post_title )
										);
									?>
								</td>
								<?php
							}
						?>
					</tr>
					<?php
				}

				$pt_loops = array();
				// Only offer loops for post types that already have an archive
				$post_types = get_post_types( array( 'public' => true, 'has_archive' => true), 'objects' );
				foreach ( $post_types as $post_type ) {
					if ( !in_array( $post_type->name, array( 'post', 'page', 'attachment' ) ) ) {
						$type = 'cpt_' . $post_type->name;
						$name = $post_type->labels->name;
						$pt_loops[ $type ] = $name;
					}
				}

				if ( count( $pt_loops ) > 0 ) {
					foreach ( $pt_loops as $slug => $name ) {
						$alternate = ' alternate' == $alternate ? '' : ' alternate';
						$post = null;
						if ( isset( $WPV_settings['view_' . $slug] ) ) {
							$post = get_post( $WPV_settings['view_' . $slug] );
						}
						?>
						<tr class="js-wpv-view-list-row<?php echo $alternate; ?>">
							<td class="wpv-admin-listing-col-usage">
								<span class="row-title"><?php echo $name . __(' (post type archive)', 'wpv-views'); ?></span>
								<?php
									echo wpv_admin_table_row_actions(
											array( "change_usage js-wpv-wpa-usage-action-change-usage" => sprintf( '<a href="#">%s</a>', __( 'Change WordPress Archive' , 'wpv-views' ) ) ),
											array( "data-view-id" => 'view_' . $slug ) );
								?>
							</td>
							<?php
								if ( is_null( $post ) ) {
									?>
									<td colspan="2">
										<a class="button button-small js-wpv-create-wpa-for-archive-loop" data-forwhomtitle="<?php echo esc_attr( $name ); ?>" data-forwhomloop="<?php echo esc_attr( 'wpv-view-loop-' . $slug ); ?>" href="#"><i class="icon-plus"></i><?php _e('Create a WordPress Archive for this loop');?></a>
									</td>
									<?php
								} else {
									?>
									<td class="wpv-admin-listing-col-title">
										<?php
											printf(
												'<a href="%s">%s</a>',
												esc_url( add_query_arg(
														array( 'page' => 'view-archives-editor', 'view_id' => $post->ID ),
														admin_url( 'admin.php' ) ) ),
												esc_html( $post->post_title ) 
											);
										?>
									</td>
									<?php
								}
							?>
						</tr>
						<?php
					}
				}

				$taxonomies = get_taxonomies( '', 'objects' );
				$exclude_tax_slugs = array();
				$exclude_tax_slugs = apply_filters( 'wpv_admin_exclude_tax_slugs', $exclude_tax_slugs );
				foreach ( $taxonomies as $category_slug => $category ) {
					if ( in_array( $category_slug, $exclude_tax_slugs ) ) {
						continue;
					}
					// Only show taxonomies with show_ui set to TRUE
					if ( !$category->show_ui ) {
						continue;
					}
					$alternate = ' alternate' == $alternate ? '' : ' alternate';
					$name = $category->name;
					$label = $category->labels->singular_name;
					$post = null;
					if ( isset( $WPV_settings['view_taxonomy_loop_'.$name] ) ) {
						$post = get_post( $WPV_settings['view_taxonomy_loop_' . $name] );
					}
					?>
					<tr class="js-wpv-view-list-row<?php echo $alternate; ?>">
						<td class="wpv-admin-listing-col-usage">
							<span class="row-title"><?php echo $label . __(' (taxonomy archive)', 'wpv-views'); ?></span>
							<?php
								echo wpv_admin_table_row_actions(
										array( "change_usage js-wpv-wpa-usage-action-change-usage" => sprintf( '<a href="#">%s</a>', __( 'Change WordPress Archive' , 'wpv-views' ) ) ),
										array( "data-view-id" => 'view_taxonomy_loop_' . $name ) );
							?>
						</td>
						<?php
							if ( is_null( $post ) ) {
								?>
								<td colspan="2">
									<a class="button button-small js-wpv-create-wpa-for-archive-loop" data-forwhomtitle="<?php echo esc_attr( $label ); ?>" data-forwhomloop="<?php echo esc_attr( 'wpv-view-taxonomy-loop-' . $name ); ?>" href="#"><i class="icon-plus"></i><?php _e('Create a WordPress Archive for this loop');?></a>
								</td>
								<?php
							} else {
								?>
								<td class="wpv-admin-listing-col-title">
									<?php
										printf(
											'<a href="%s">%s</a>',
											esc_url( add_query_arg(
													array( 'page' => 'view-archives-editor', 'view_id' => $post->ID ),
													admin_url( 'admin.php' ) ) ),
											esc_html( $post->post_title ) 
										);
									?>
								</td>
								<?php
							}
						?>
					</tr>
					<?php
				}
			?>
		</tbody>
	</table>
    <?php
}
function wpv_admin_menu_content_template_listing_by_type_row( $sort, $page = 0 ) {
	global $WPV_settings, $post;

	$post_types_array = wpv_get_pt_tax_array();

	ob_start();
	if ( $sort == 'usage-single' ){

		$counter = count( $post_types_array['single_post'] );
		$alternate = '';
		for ( $i = 0; $i < $counter; ++$i ) {
			$type = $post_types_array['single_post'][ $i ][0];
			$label = $post_types_array['single_post'][ $i ][1];
			$alternate = ' alternate' == $alternate ? '' : ' alternate';

			?>
			<tr id="wpv_ct_list_row_<?php echo $type; ?>" class="js-wpv-ct-list-row<?php echo $alternate; ?>">

				<td class="wpv-admin-listing-col-usage post-title page-title column-title">
					<span class="row-title">
						<?php echo $label;?>
					</span>
					<?php
						$row_actions = array(
								"change_pt js-wpv-change-ct-assigned-to-something-popup" => sprintf( '<a href="#">%s</a>', __('Change Content Template','wpv-views') ) );

						echo wpv_admin_table_row_actions( $row_actions,	array(
								"data-pt" => 'views_template_for_' . $type ) );
					?>
				</td>

				<td class="wpv-admin-listing-col-used-title">
					<ul>
						<?php
							$add_button = wpv_ct_listing_render_create_ct_button(
                                sprintf( __( 'Create a Content Template for single %s', 'wpv-views' ), $label ),
                                $label,
                                array( 'single_post_types' => array( $type ) )
                            );


							if ( isset( $WPV_settings[ 'views_template_for_' . $type ] ) && $WPV_settings[ 'views_template_for_' . $type ] != 0 ) {

                                // There is a Content Template assigned for single posts of this type

                                $ct_id = $WPV_settings[ 'views_template_for_' . $type ];
                                $ct = WPV_Content_Template::get_instance( $ct_id );

                                if ( null != $ct ) {
                                    printf(
                                        '<a href="%s">%s</a>',
                                        esc_url(
                                            add_query_arg(
                                                array( 'page' => WPV_CT_EDITOR_PAGE_NAME, 'ct_id' => $ct->id, 'action' => 'edit' ),
                                                admin_url( 'admin.php' )
                                            )
                                        ),
                                        $ct->title
                                    );

									// @todo We do not need the exact number here, let's create a has_dissident_posts method instead with a LIMITed query
                                    $dissident_post_count = $ct->get_dissident_posts( $type, 'count' );

                                    if ( $dissident_post_count > 0 ) {
                                        ?>
                                        <span class="js-wpv-apply-ct-to-cpt-single-<?php echo $type; ?>">
                                            <?php
                                                printf(
                                                    '<a class="%s" data-type="%s" data-id="%s" data-nonce="%s"> %s</a>',
                                                    'button button-small button-leveled icon-warning-sign js-wpv-apply-ct-to-all-cpt-single-dialog',
													$type,
													$ct->id,
													wp_create_nonce( 'work_view_template' ),
                                                    sprintf( __( 'Bind %u %s ', 'wpv-views' ), $dissident_post_count, $label )
                                                );
                                            ?>
                                        </span>
                                        <?php
                                    }
                                    //}
                                } else {
                                    echo $add_button;
                                }
                            } else {

                                // Single posts of this type have no Content Template assigned

                                echo $add_button;

                                $assigned_posts_count = WPV_Content_Template_Embedded::get_posts_using_content_template_by_type( $type, 'count' );

                                if ( $assigned_posts_count > 0 ) {
                                    ?>
                                    <a class="button button-small js-wpv-clear-cpt-from-ct-popup" href="#"
                                            data-unclear="<?php echo $assigned_posts_count; ?>"
                                            data-slug="<?php echo $type; ?>"
                                            data-label="<?php echo htmlentities( $label, ENT_QUOTES ); ?>">
                                        <i class="icon-unlink"></i>
                                        <?php echo sprintf( __('Clear %d %s', 'wpv-views'), $assigned_posts_count, $label ); ?>
                                    </a>
                                    <?php
                                }

                            }
						?>
					</ul>
				</td>
			</tr>
			<?php
		}

	} else if ( $sort == 'usage-post-archives' ){

		$alternate = '';
		$counter = count( $post_types_array['archive_post'] );
		for ( $i = 0; $i < $counter; ++$i ) {

			$type = $post_types_array['archive_post'][ $i ][0];
			$label = $post_types_array['archive_post'][ $i ][1];

			$add_button = wpv_ct_listing_render_create_ct_button(
                __( 'Add a new Content Template for this post type', 'wpv-views' ),
                $label,
                array( 'post_archives' => array( $type ) )
            );

			$alternate = ' alternate' == $alternate ? '' : ' alternate';
			?>
			<tr id="wpv_ct_list_row_<?php echo $type; ?>" class="js-wpv-ct-list-row<?php echo $alternate; ?>">
				<td class="post-title page-title column-title">
					<span class="row-title">
						<?php echo $label; ?>
					</span>
					<?php
						$row_actions = array(
								"change_pt js-wpv-change-ct-assigned-to-something-popup" => sprintf( '<a href="#">%s</a>', __( 'Change Content Template', 'wpv-views' ) ) );

						echo wpv_admin_table_row_actions( $row_actions,	array(
								"data-pt" => 'views_template_archive_for_' . $type ) );
					?>
				</td>
				<td>
					<ul>
						<?php
							if ( isset( $WPV_settings[ 'views_template_archive_for_' . $type ] )
									&& $WPV_settings[ 'views_template_archive_for_' . $type ] != 0) {
								$post = get_post( $WPV_settings[ 'views_template_archive_for_' . $type ] );
								if ( is_object( $post ) ) {
                                    wpv_ct_editor_render_link( $post->ID, esc_html( $post->post_title ) );
								} else {
									echo $add_button;
								}
							} else {
								echo $add_button;
							}
						?>
					</ul>
				</td>
			</tr>
			<?php
		}

	} else if ( $sort == 'usage-taxonomy-archives' ){

		$counter = count( $post_types_array['taxonomy_post'] );
		$alternate = '';

		for ( $i = 0; $i < $counter; ++$i ) {
			$type = $post_types_array['taxonomy_post'][ $i ][0];
			$label = $post_types_array['taxonomy_post'][ $i ][1];

			$add_button = wpv_ct_listing_render_create_ct_button(
                __( 'Add a new Content Template for this taxonomy', 'wpv-views' ),
                $label,
                array( 'taxonomy_archives' => array( $type ) )
            );

			$alternate = ' alternate' == $alternate ? '' : ' alternate';

			?>
			<tr id="wpv_ct_list_row_<?php echo $type; ?>" class="js-wpv-ct-list-row<?php echo $alternate; ?>">
				<td class="post-title page-title column-title">
					<span class="row-title">
						<?php echo $label;?>
					</span>
					<?php
						$row_actions = array(
								"change_pt js-wpv-change-ct-assigned-to-something-popup" => sprintf( '<a href="#">%s</a>', __( 'Change Content Template', 'wpv-views' ) ) );

						echo wpv_admin_table_row_actions( $row_actions,	array(
								"data-pt" => 'views_template_loop_' . $type ) );
					?>
				</td>
				<td>
					<ul>
						<?php
							if ( isset( $WPV_settings[ 'views_template_loop_' . $type ] )
									&& $WPV_settings[ 'views_template_loop_' . $type ] != 0 ) {
								$post = get_post( $WPV_settings['views_template_loop_' . $type] );
								if ( is_object( $post ) ) {
                                    wpv_ct_editor_render_link( $post->ID, esc_html( $post->post_title ) );
								} else {
									echo $add_button;
								}
							} else {
								echo $add_button;
							}
						?>
					</ul>
				</td>
			</tr>
			<?php
		}
	}

	$row = ob_get_contents();
	ob_end_clean();

	return $row;
}
/**
 * wpv_admin_view_listing_table
 *
 * Displays the content of the Views admin listing page: status, table and pagination.
 *
 * @param array $views_pre_query_data Array with IDs of possible results and counts per post status.
 *     See wpv_prepare_view_listing_query() for details.
 * @param string $current_post_status Status of posts to display. Can be 'publish' or 'trash'.
 *
 * @since unknown
 */
function wpv_admin_view_listing_table($views_pre_query_data, $current_post_status)
{
    // array of URL modifiers
    $mod_url = array('orderby' => '', 'order' => '', 's' => '', 'items_per_page' => '', 'paged' => '', 'status' => $current_post_status);
    // array of WP_Query parameters
    $wpv_args = array('post_type' => 'view', 'post__in' => $views_pre_query_data['post__in'], 'posts_per_page' => WPV_ITEMS_PER_PAGE, 'order' => 'ASC', 'orderby' => 'title', 'post_status' => $current_post_status);
    // perform the search in Views titles and decriptions and update post__in argument to $wpv_args.
    if (isset($_GET["s"]) && '' != $_GET["s"]) {
        $wpv_args = wpv_modify_wpquery_for_search($_GET["s"], $wpv_args);
        $mod_url['s'] = sanitize_text_field($_GET["s"]);
    }
    // apply posts_per_page coming from the URL parameters
    if (isset($_GET["items_per_page"]) && '' != $_GET["items_per_page"]) {
        $wpv_args['posts_per_page'] = (int) $_GET["items_per_page"];
        $mod_url['items_per_page'] = (int) $_GET["items_per_page"];
    }
    // apply orderby coming from the URL parameters
    if (isset($_GET["orderby"]) && '' != $_GET["orderby"]) {
        $wpv_args['orderby'] = sanitize_text_field($_GET["orderby"]);
        $mod_url['orderby'] = sanitize_text_field($_GET["orderby"]);
        // apply order coming from the URL parameters
        if (isset($_GET["order"]) && '' != $_GET["order"]) {
            $wpv_args['order'] = sanitize_text_field($_GET["order"]);
            $mod_url['order'] = sanitize_text_field($_GET["order"]);
        }
    }
    // apply paged coming from the URL parameters
    if (isset($_GET["paged"]) && '' != $_GET["paged"]) {
        $wpv_args['paged'] = (int) $_GET["paged"];
        $mod_url['paged'] = (int) $_GET["paged"];
    }
    $wpv_query = new WP_Query($wpv_args);
    // The number of Views being displayed.
    $wpv_count_posts = $wpv_query->post_count;
    // Total number of Views matching query parameters.
    $wpv_found_posts = $wpv_query->found_posts;
    ?>
		<ul class="subsubsub"><!-- links to lists Views in different statuses -->
			<?php 
    // "publish" status
    $is_current = 'publish' == $current_post_status && !isset($_GET["s"]);
    printf('<li><a href="%s" %s >%s</a> (%s) | </li>', esc_url(add_query_arg(array('page' => 'views', 'status' => 'publish'), admin_url('admin.php'))), $is_current ? ' class="current" ' : '', __('Published', 'wpv-views'), $views_pre_query_data['published_count']);
    // "trash" status
    $is_current = 'trash' == $current_post_status && !isset($_GET["s"]);
    printf('<li><a href="%s" %s >%s</a> (%s)</li>', esc_url(add_query_arg(array('page' => 'views', 'status' => 'trash'), admin_url('admin.php'))), $is_current ? ' class="current" ' : '', __('Trash', 'wpv-views'), $views_pre_query_data['trashed_count']);
    ?>
		</ul>
	<?php 
    // A nonce for view action - used for individual as well as for bulk actions
    $view_action_nonce = wp_create_nonce('wpv_view_listing_actions_nonce');
    // === Render "tablenav" section (Bulk actions and Search box) ===
    echo '<div class="tablenav top">';
    // If there is one or more Views in this query, show search box
    if ($wpv_found_posts > 0) {
        ?>
		<div class="alignright">
			<form id="posts-filter" action="" method="get">
				<p class="search-box">
					<label class="screen-reader-text" for="post-search-input"><?php 
        _e('Search Views', 'wpv-views');
        ?>
:</label>
					<?php 
        $search_term = isset($_GET["s"]) ? urldecode(sanitize_text_field($_GET["s"])) : '';
        ?>
					<input type="search" id="post-search-input" name="s" value="<?php 
        echo $search_term;
        ?>
" />
					<input type="submit" name="" id="search-submit" class="button" value="<?php 
        echo htmlentities(__('Search Views', 'wpv-views'), ENT_QUOTES);
        ?>
" />
					<input type="hidden" name="paged" value="1" />
				</p>
			</form>
		</div>
		<?php 
    }
    // If this page has one or more Views, show Bulk actions controls
    if ($wpv_count_posts > 0) {
        // Prepare ender bulk actions dropdown.
        if ('publish' == $current_post_status) {
            $bulk_actions = array('trash' => __('Move to trash', 'wpv-views'));
        } else {
            $bulk_actions = array('restore-from-trash' => __('Restore from trash', 'wpv-views'), 'delete' => __('Delete permanently', 'wpv-views'));
        }
        $bulk_actions_args = array('data-viewactionnonce' => $view_action_nonce);
        $bulk_actions_class = 'js-wpv-views-listing-bulk-action';
        echo wpv_admin_table_bulk_actions($bulk_actions, $bulk_actions_class, $bulk_actions_args, 'top');
    }
    echo '</div>';
    // End of tablenav section
    // If this page has one or more Views, show the table
    if ($wpv_count_posts > 0) {
        ?>
		<table class="wpv-views-listing js-wpv-views-listing widefat">
			<thead>
				<?php 
        /* To avoid code duplication, table header is stored in output buffer and echoed twice - within
         * thead and tfoot tags. */
        ob_start();
        ?>
				<tr>
					<th class="wpv-admin-listing-col-bulkactions check-column">
						<input type="checkbox" />
					</th>
					<?php 
        $column_active = '';
        $column_sort_to = 'ASC';
        $column_sort_now = 'ASC';
        if ($wpv_args['orderby'] === 'title') {
            $column_active = ' views-list-sort-active';
            $column_sort_to = $wpv_args['order'] === 'ASC' ? 'DESC' : 'ASC';
            $column_sort_now = $wpv_args['order'];
        }
        ?>
					<th class="wpv-admin-listing-col-title">
						<?php 
        // "sort by title" link
        printf('<a href="%s" class="%s" data-orderby="title">%s <i class="%s"></i></a>', wpv_maybe_add_query_arg(array('page' => 'views', 'orderby' => 'title', 'order' => $column_sort_to, 's' => $mod_url['s'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => $mod_url['paged'], 'status' => $mod_url['status']), admin_url('admin.php')), 'js-views-list-sort views-list-sort ' . $column_active, __('Title', 'wpv-views'), 'DESC' === $column_sort_now ? 'icon-sort-by-alphabet-alt' : 'icon-sort-by-alphabet');
        ?>
					</th>

					<th class="wpv-admin-listing-col-summary js-wpv-col-two"><?php 
        _e('Content to load', 'wpv-views');
        ?>
</th>
					<th class="wpv-admin-listing-col-scan"><?php 
        _e('Used on', 'wpv-views');
        ?>
</th>

					<?php 
        $column_active = '';
        $column_sort_to = 'DESC';
        $column_sort_now = 'DESC';
        if ($wpv_args['orderby'] === 'date') {
            $column_active = ' views-list-sort-active';
            $column_sort_to = $wpv_args['order'] === 'ASC' ? 'DESC' : 'ASC';
            $column_sort_now = $wpv_args['order'];
        }
        ?>
					<th class="wpv-admin-listing-col-date">
						<?php 
        // "sort by date" link
        printf('<a href="%s" class="%s" data-orderby="date">%s <i class="%s"></i></a>', wpv_maybe_add_query_arg(array('page' => 'views', 'orderby' => 'date', 'order' => $column_sort_to, 's' => $mod_url['s'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => $mod_url['paged'], 'status' => $mod_url['status']), admin_url('admin.php')), 'js-views-list-sort views-list-sort ' . $column_active, __('Date', 'wpv-views'), 'DESC' === $column_sort_now ? 'icon-sort-by-attributes-alt' : 'icon-sort-by-attributes');
        ?>
					</th>
				</tr>
				<?php 
        // Get table header from output buffer and stop buffering
        $table_header = ob_get_contents();
        ob_end_clean();
        echo $table_header;
        ?>
			</thead>
			<tfoot>
				<?php 
        echo $table_header;
        ?>
			</tfoot>

			<tbody class="js-wpv-views-listing-body">
				<?php 
        $alternate = '';
        while ($wpv_query->have_posts()) {
            $wpv_query->the_post();
            $post_id = get_the_id();
            $post = get_post($post_id);
            $meta = get_post_meta($post_id, '_wpv_settings');
            $view_description = get_post_meta($post_id, '_wpv_description', true);
            $alternate = ' alternate' == $alternate ? '' : ' alternate';
            ?>
						<tr id="wpv_view_list_row_<?php 
            echo $post->ID;
            ?>
" class="js-wpv-view-list-row<?php 
            echo $alternate;
            ?>
">
							<th class="wpv-admin-listing-col-bulkactions check-column">
								<?php 
            printf('<input type="checkbox" value="%s" name="view[]" />', $post->ID);
            ?>
							</th>
							<td class="wpv-admin-listing-col-title">
								<span class="row-title">
								<?php 
            if ('trash' == $current_post_status) {
                echo $post->post_title;
            } else {
                printf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => 'views-editor', 'view_id' => $post->ID), admin_url('admin.php'))), $post->post_title);
            }
            ?>
								</span>
								<?php 
            if (isset($view_description) && '' != $view_description) {
                ?>
										<p class="desc">
											<?php 
                echo nl2br($view_description);
                ?>
										</p>
										<?php 
            }
            /* Generate and show row actions.
             * Note that we want to add also 'simple' action names to the action list because
             * they get echoed as a class of the span tag and get styled from WordPress core css
             * accordingly (e.g. trash in different colour than the rest) */
            $row_actions = array();
            if ('publish' == $current_post_status) {
                $row_actions['edit'] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => 'views-editor', 'view_id' => $post->ID), admin_url('admin.php'))), __('Edit', 'wpv-views'));
                $row_actions['duplicate js-views-actions-duplicate'] = sprintf('<a href="#">%s</a>', __('Duplicate', 'wpv-views'));
                $row_actions['trash js-views-actions-trash'] = sprintf('<a href="#">%s</a>', __('Move to trash', 'wpv-views'));
            } else {
                if ('trash' == $current_post_status) {
                    $row_actions['restore-from-trash js-views-actions-restore-from-trash'] = sprintf('<a href="#">%s</a>', __('Restore from trash', 'wpv-views'));
                    $row_actions['delete js-views-actions-delete'] = sprintf('<a href="#">%s</a>', __('Delete', 'wpv-views'));
                }
            }
            echo wpv_admin_table_row_actions($row_actions, array("data-view-id" => $post->ID, "data-view-title" => $post->post_title, "data-viewactionnonce" => $view_action_nonce));
            ?>
							</td>
							<td class="wpv-admin-listing-col-summary">
								<?php 
            echo wpv_create_content_summary_for_listing($post->ID);
            ?>
							</td>
							<td class="wpv-admin-listing-col-scan">
								<button class="button js-scan-button" data-view-id="<?php 
            echo $post->ID;
            ?>
">
									<?php 
            _e('Scan', 'wp-views');
            ?>
								</button>
								<span class="js-nothing-message hidden"><?php 
            _e('Nothing found', 'wpv-views');
            ?>
</span>
							</td>
							<td class="wpv-admin-listing-col-date">
								<?php 
            echo get_the_time(get_option('date_format'), $post->ID);
            ?>
							</td>
						</tr>
					<?php 
        }
        ?>
			</tbody>
		</table>

		<div class="tablenav bottom">
			<?php 
        echo wpv_admin_table_bulk_actions($bulk_actions, $bulk_actions_class, $bulk_actions_args, 'bottom');
        ?>
		</div>

		<p class="add-new-view" >
			<a class="button js-wpv-views-add-new" href="#">
				<i class="icon-plus"></i><?php 
        _e('Add new View', 'wpv-views');
        ?>
			</a>
		</p>

		<?php 
        wpv_admin_listing_pagination('views', $wpv_found_posts, $wpv_args["posts_per_page"], $mod_url);
        ?>
		<?php 
    } else {
        // No Views matches the criteria
        ?>
		<div class="wpv-views-listing views-empty-list">
			<?php 
        if (isset($_GET["status"]) && $_GET["status"] == 'trash' && isset($_GET["s"]) && $_GET["s"] != '') {
            printf('<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __('No Views in trash matched your criteria.', 'wpv-views'), wpv_maybe_add_query_arg(array('page' => 'views', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1', 'status' => 'trash'), admin_url('admin.php')), __('Return', 'wpv-views'));
        } else {
            if (isset($_GET["status"]) && $_GET["status"] == 'trash') {
                printf('<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __('No Views in trash.', 'wpv-views'), wpv_maybe_add_query_arg(array('page' => 'views', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1'), admin_url('admin.php')), __('Return', 'wpv-views'));
            } else {
                if (isset($_GET["s"]) && $_GET["s"] != '') {
                    printf('<p>%s</p><p><a class="button-secondary" href="%s">%s</a></p>', __('No Views matched your criteria.', 'wpv-views'), wpv_maybe_add_query_arg(array('page' => 'views', 'orderby' => $mod_url['orderby'], 'order' => $mod_url['order'], 'items_per_page' => $mod_url['items_per_page'], 'paged' => '1'), admin_url('admin.php')), __('Return', 'wpv-views'));
                } else {
                    ?>
					<div class="wpv-view-not-exist js-wpv-view-not-exist">
						<p><?php 
                    _e('Views load content from the database and display on the site.');
                    ?>
</p>
						<p><a class="button js-wpv-views-add-first" href="#"><i class="icon-plus"></i><?php 
                    _e('Create your first View', 'wpv-views');
                    ?>
</a></p>
					</div>
					<?php 
                }
            }
        }
        ?>
		</div>
		<?php 
    }
}
function wpv_admin_menu_content_template_listing_by_type_row($sort, $page = 0)
{
    global $WPV_settings, $post, $wpdb;
    // $post_types = get_post_types( array('public' => true), 'objects' );
    $post_types_array = wpv_get_pt_tax_array();
    ob_start();
    if ($sort == 'usage-single') {
        $counter = count($post_types_array['single_post']);
        $alternate = '';
        for ($i = 0; $i < $counter; ++$i) {
            $type = $post_types_array['single_post'][$i][0];
            $label = $post_types_array['single_post'][$i][1];
            $alternate = ' alternate' == $alternate ? '' : ' alternate';
            ?>
			<tr id="wpv_ct_list_row_<?php 
            echo $type;
            ?>
" class="js-wpv-ct-list-row<?php 
            echo $alternate;
            ?>
">

				<td class="wpv-admin-listing-col-usage post-title page-title column-title">
					<span class="row-title">
						<?php 
            echo $label;
            ?>
					</span>
					<?php 
            $row_actions = array("change_pt js-list-ct-action-change-pt" => sprintf('<a href="#">%s</a>', __('Change Content Template', 'wpv-views')));
            echo wpv_admin_table_row_actions($row_actions, array("data-msg" => 1, "data-sort" => $sort, "data-pt" => 'views_template_for_' . $type));
            ?>
				</td>

				<td class="wpv-admin-listing-col-used-title">
					<ul>
						<?php 
            $add_button = sprintf('<a class="button button-small" data-disabled="1"
											href="%s">
										<i class="icon-plus"></i>
										%s
									</a>', esc_url(add_query_arg(array('post_type' => 'view-template', 'action' => 'wpv_ct_create_new', 'post_title' => urlencode(__('Content template for ', 'wpv-views') . $label), 'ct_selected' => 'views_template_for_' . $type, 'toggle' => '1,0,0'), admin_url('post-new.php'))), sprintf(__('Create a Content Template for single %s', 'wpv-views'), $label));
            // TODO get_posts or explanation why is it done this way (optimalization?)
            $posts = $wpdb->get_col($wpdb->prepare("SELECT {$wpdb->posts}.ID FROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t\tWHERE post_type = %s \n\t\t\t\t\t\t\t\t\tAND post_status != 'auto-draft'", $type));
            $count = sizeof($posts);
            $posts_ids = "'" . implode("','", $posts) . "'";
            if (isset($WPV_settings['views_template_for_' . $type])) {
                if ($WPV_settings['views_template_for_' . $type] != 0) {
                    $template = get_post($WPV_settings['views_template_for_' . $type]);
                    if (is_object($template)) {
                        printf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post' => $template->ID, 'action' => 'edit'), admin_url('post.php'))), $template->post_title);
                        if ($count > 0) {
                            $set_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(post_id) FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE meta_key = '_views_template'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND meta_value = %s\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND post_id IN ({$posts_ids}) \n\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT %d", $WPV_settings['views_template_for_' . $type], $count));
                            if ($count - $set_count > 0) {
                                ?>
												<span class="js-alret-icon-hide-<?php 
                                echo $type;
                                ?>
">
													<?php 
                                printf('<a class="%s" data-target="%s"> %s</a>', 'button button-small button-leveled icon-warning-sign js-apply-for-all-posts', esc_url(add_query_arg(array('action' => 'wpv_ct_update_posts', 'type' => $type, 'tid' => $template->ID, 'wpnonce' => wp_create_nonce('work_view_template')), admin_url('admin-ajax.php'))), sprintf(__('Bind %u %s ', 'wpv-views'), $count - $set_count, $label));
                                ?>
												</span>
												<?php 
                            }
                        }
                    } else {
                        echo $add_button;
                    }
                } else {
                    echo $add_button;
                    if ($count > 0) {
                        $set_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(post_id) FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE meta_key = '_views_template'\n\t\t\t\t\t\t\t\t\t\t\t\tAND meta_value != %s\n\t\t\t\t\t\t\t\t\t\t\t\tAND post_id IN ({$posts_ids}) \n\t\t\t\t\t\t\t\t\t\t\t\tLIMIT %d", '0', $count));
                        if ($set_count > 0) {
                            ?>
											<a class="button button-small js-single-unlink-template-open-dialog" href="#"
													data-unclear="<?php 
                            echo $set_count;
                            ?>
"
													data-slug="<?php 
                            echo $type;
                            ?>
"
													data-label="<?php 
                            echo htmlentities($label, ENT_QUOTES);
                            ?>
">
												<i class="icon-unlink"></i>
												<?php 
                            echo sprintf(__('Clear %d %s', 'wpv-views'), $set_count, $label);
                            ?>
											</a>
											<?php 
                        }
                    }
                }
            } else {
                echo $add_button;
                if ($count > 0) {
                    $set_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(post_id) FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\t\t\t\t\tWHERE meta_key = '_views_template'\n\t\t\t\t\t\t\t\t\t\t\tAND meta_value != %s\n\t\t\t\t\t\t\t\t\t\t\tAND post_id IN ({$posts_ids}) \n\t\t\t\t\t\t\t\t\t\t\tLIMIT %d", '0', $count));
                    if ($set_count > 0) {
                        ?>
										<a class="button button-small js-single-unlink-template-open-dialog" href="#"
												data-unclear="<?php 
                        echo $set_count;
                        ?>
"
												data-slug="<?php 
                        echo $type;
                        ?>
"
												data-label="<?php 
                        echo htmlentities($label, ENT_QUOTES);
                        ?>
">
											<i class="icon-unlink"></i>
											<?php 
                        echo sprintf(__('Clear %d %s', 'wpv-views'), $set_count, $label);
                        ?>
										</a>
										<?php 
                    }
                }
            }
            ?>
					</ul>
				</td>
			</tr>
			<?php 
        }
    } else {
        if ($sort == 'usage-post-archives') {
            $alternate = '';
            $counter = count($post_types_array['archive_post']);
            for ($i = 0; $i < $counter; ++$i) {
                $type = $post_types_array['archive_post'][$i][0];
                $label = $post_types_array['archive_post'][$i][1];
                $add_button = sprintf('<a class="button button-small" data-disabled="1" href="%s"><i class="icon-plus"></i> %s</a>', esc_url(add_query_arg(array('post_type' => 'view-template', 'action' => 'wpv_ct_create_new', 'post_title' => urlencode(__('Content template for ', 'wpv-views') . $label), 'ct_selected' => 'views_template_archive_for_' . $type, 'toggle' => '0,1,0'), admin_url('post-new.php'))), __('Add a new Content Template for this post type', 'wpv-views'));
                $alternate = ' alternate' == $alternate ? '' : ' alternate';
                ?>
			<tr id="wpv_ct_list_row_<?php 
                echo $type;
                ?>
" class="js-wpv-ct-list-row<?php 
                echo $alternate;
                ?>
">
				<td class="post-title page-title column-title">
					<span class="row-title">
						<?php 
                echo $label;
                ?>
					</span>
					<?php 
                $row_actions = array("change_pt js-list-ct-action-change-pt" => sprintf('<a href="#">%s</a>', __('Change Content Template', 'wpv-views')));
                echo wpv_admin_table_row_actions($row_actions, array("data-msg" => 1, "data-sort" => $sort, "data-pt" => 'views_template_archive_for_' . $type));
                ?>
				</td>
				<td>
					<ul>
						<?php 
                if (isset($WPV_settings['views_template_archive_for_' . $type]) && $WPV_settings['views_template_archive_for_' . $type] != 0) {
                    $post = get_post($WPV_settings['views_template_archive_for_' . $type]);
                    if (is_object($post)) {
                        printf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post' => $post->ID, 'action' => 'edit'), admin_url('post.php'))), $post->post_title);
                    } else {
                        echo $add_button;
                    }
                } else {
                    echo $add_button;
                }
                ?>
					</ul>
				</td>
			</tr>
			<?php 
            }
        } else {
            if ($sort == 'usage-taxonomy-archives') {
                $counter = count($post_types_array['taxonomy_post']);
                $alternate = '';
                for ($i = 0; $i < $counter; ++$i) {
                    $type = $post_types_array['taxonomy_post'][$i][0];
                    $label = $post_types_array['taxonomy_post'][$i][1];
                    $add_button = sprintf('<a class="button button-small js-wpv-ct-create-new-for-usage" data-disabled="1"
							data-title="%s" data-usage="%s" href="%s">
						<i class="icon-plus"></i>
						%s
					</a>', urlencode(__('Content template for ', 'wpv-views') . $label), 'views_template_loop_' . $type, esc_url(add_query_arg(array('post_type' => 'view-template', 'action' => 'wpv_ct_create_new', 'post_title' => urlencode(__('Content template for ', 'wpv-views') . $label), 'ct_selected' => 'views_template_loop_' . $type, 'toggle' => '0,0,1'), admin_url('post-new.php'))), __('Add a new Content Template for this taxonomy', 'wpv-views'));
                    $alternate = ' alternate' == $alternate ? '' : ' alternate';
                    ?>
			<tr id="wpv_ct_list_row_<?php 
                    echo $type;
                    ?>
" class="js-wpv-ct-list-row<?php 
                    echo $alternate;
                    ?>
">
				<td class="post-title page-title column-title">
					<span class="row-title">
						<?php 
                    echo $label;
                    ?>
					</span>
					<?php 
                    $row_actions = array("change_pt js-list-ct-action-change-pt" => sprintf('<a href="#">%s</a>', __('Change Content Template', 'wpv-views')));
                    echo wpv_admin_table_row_actions($row_actions, array("data-msg" => 2, "data-sort" => $sort, "data-pt" => 'views_template_loop_' . $type));
                    ?>
				</td>
				<td>
					<ul>
						<?php 
                    if (isset($WPV_settings['views_template_loop_' . $type]) && $WPV_settings['views_template_loop_' . $type] != 0) {
                        $post = get_post($WPV_settings['views_template_loop_' . $type]);
                        if (is_object($post)) {
                            printf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post' => $post->ID, 'action' => 'edit'), admin_url('post.php'))), $post->post_title);
                        } else {
                            echo $add_button;
                        }
                    } else {
                        echo $add_button;
                    }
                    ?>
					</ul>
				</td>
			</tr>
			<?php 
                }
            }
        }
    }
    $row = ob_get_contents();
    ob_end_clean();
    return $row;
}