/** * wpv_admin_archive_listing_page * * Creates the main structure of the WPA admin listing page: wrapper and header * */ function wpv_admin_archive_listing_page() { global $WPV_view_archive_loop; ?> <div class="wrap toolset-views"> <!-- wpv-views-listing-archive-page can be removed --> <div class="wpv-views-listing-page wpv-views-listing-archive-page" data-none-message="<?php _e("This WordPress Archive isn't being used for any loops.",'wpv-views') ?>" > <?php // 'trash' or 'publish' $current_post_status = wpv_getget( 'status', 'publish', array( 'trash', 'publish' ) ); $search_term = urldecode( sanitize_text_field( wpv_getget( 's' ) ) ); $arrange_by_usage = ( sanitize_text_field( wpv_getget( 'arrangeby' ) ) == 'usage' ); wp_nonce_field( 'work_views_listing', 'work_views_listing' ); wp_nonce_field( 'wpv_remove_view_permanent_nonce', 'wpv_remove_view_permanent_nonce' ); ?> <div id="icon-views" class="icon32"></div> <h2><!-- classname wpv-page-title removed --> <?php _e( 'WordPress Archives', 'wpv-views' ); ?> <a href="#" class="add-new-h2 page-title-action js-wpv-views-archive-add-new wpv-views-archive-add-new"> <?php _e('Add new WordPress Archive','wpv-views') ?> </a> <?php if ( !empty( $search_term ) ) { $search_message = __('Search results for "%s"','wpv-views'); if ( 'trash' == $current_post_status ) { $search_message = __('Search results for "%s" in trashed WordPress Archives', 'wpv-views'); } ?> <span class="subtitle"> <?php echo sprintf( $search_message, $search_term ); ?> </span> <?php } ?> </h2> <?php // Messages: trashed, untrashed, deleted // We can reuse the function from Views listing (there's a note saying we're doing that). add_filter( 'wpv_maybe_show_listing_message_undo', 'wpv_admin_view_listing_message_undo', 10, 3 ); wpv_maybe_show_listing_message( 'trashed', __( 'WordPress Archive moved to the Trash.', 'wpv-views' ), __( '%d WordPress Archives moved to the Trash.', 'wpv-views' ), true ); wpv_maybe_show_listing_message( 'untrashed', __( 'WordPress Archive restored from the Trash.', 'wpv-views' ), __( '%d WordPress Archives restored from the Trash.', 'wpv-views' ) ); wpv_maybe_show_listing_message( 'deleted', __( 'WordPress Archive permanently deleted.', 'wpv-views' ), __( '%d WordPress Archives permanently deleted.', 'wpv-views' ) ); // "Arrange by" tabs ?> <div class="wpv-admin-tabs"> <ul class="wpv-admin-tabs-links"> <li> <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'view-archives' ), admin_url( 'admin.php' ) ) ); ?>" <?php wpv_current_class( ! $arrange_by_usage ); ?> > <?php _e( 'Arrange by name', 'wpv-views' ); ?> </a> </li> <li> <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'view-archives', 'arrangeby' => 'usage' ), admin_url( 'admin.php' ) ) ); ?>" <?php wpv_current_class( $arrange_by_usage ); ?> > <?php _e( 'Arrange by usage', 'wpv-views' ); ?> </a> </li> </ul> </div> <?php if ( $arrange_by_usage ) { // Show table arranged by Usage wp_nonce_field( 'wpv_wp_archive_arrange_usage', 'wpv_wp_archive_arrange_usage' ); if ( !$WPV_view_archive_loop->check_archive_loops_exists() ) { ?> <p id="js-wpv-no-archive" class="toolset-alert toolset-alert-success update below-h2"> <?php _e('All loops have a WordPress Archive assigned','wpv-views'); ?> </p> <?php } wpv_admin_wordpress_archives_listing_table_by_usage(); ?> <p class="add-new-view js-add-new-view"> <a class="button js-wpv-views-archive-add-new wpv-views-archive-add-new" href="#"> <i class="icon-plus"></i><?php _e('Add new WordPress Archive','wpv-views') ?> </a> </p> <?php } else { // IDs of possible results and counts per post status. $views_pre_query_data = wpv_prepare_view_listing_query( array( 'archive', 'layouts-loop' ), $current_post_status ); // Do we have any Views at all? $has_items = ( $views_pre_query_data['total_count'] > 0 ); // Show table arranged by item names if ( $has_items ) { wpv_admin_wordpress_archives_listing_table_by_name( $views_pre_query_data, $current_post_status ); } else { // No items are present. if ( !$WPV_view_archive_loop->check_archive_loops_exists() ) { ?> <p id="js-wpv-no-archive" class="toolset-alert toolset-alert-success"> <?php _e('All loops have a WordPress Archive assigned','wpv-views'); ?> </p> <?php } ?> <div class="wpv-view-not-exist js-wpv-view-not-exist"> <p><?php _e( 'WordPress Archives let you customize the output of standard Archive pages.', 'wpv-views' );?></p> <p> <a class="button js-wpv-views-archive-create-new" href="#"> <i class="icon-plus"></i> <?php _e( 'Create your first WordPress Archive', 'wpv-views' );?> </a> </p> </div> <?php } } ?> </div> <!-- .wpv-settings-container" --> </div> <?php }
/** * wpv_admin_menu_views_listing_page * * Creates the main structure of the Views admin listing page: wrapper and header * */ function wpv_admin_menu_views_listing_page() { ?> <div class="wrap toolset-views"> <div class="wpv-views-listing-page"> <?php // 'trash' or 'publish' $current_post_status = wpv_getget('status', 'publish', array('trash', 'publish')); $search_term = urldecode(sanitize_text_field(wpv_getget('s'))); // IDs of possible results and counts per post status $views_pre_query_data = wpv_prepare_view_listing_query('normal', $current_post_status); // Do we have any Views at all? $has_views = $views_pre_query_data['total_count'] > 0; // general nonce // TODO please do NOT use this general nonce wp_nonce_field('work_views_listing', 'work_views_listing'); ?> <div id="icon-views" class="icon32"></div> <h2><!-- classname wpv-page-title removed --> <?php _e('Views', 'wpv-views'); printf(' <a href="#" class="add-new-h2 js-wpv-views-add-new-top">%s</a>', __('Add new View', 'wpv-views')); // TODO maybe have this nonce as a data attribute for all buttons opening the popup wp_nonce_field('wp_nonce_create_view_wrapper', 'wp_nonce_create_view_wrapper'); if (!empty($search_term)) { if ('trash' == $current_post_status) { $search_message = __('Search results for "%s" in trashed Views', 'wpv-views'); } else { $search_message = __('Search results for "%s"', 'wpv-views'); } ?> <span class="subtitle"> <?php echo sprintf($search_message, $search_term); ?> </span> <?php } ?> </h2> <?php // Messages: trashed, untrashed, deleted add_filter('wpv_maybe_show_listing_message_undo', 'wpv_admin_view_listing_message_undo', 10, 3); wpv_maybe_show_listing_message('trashed', __('View moved to the Trash.', 'wpv-views'), __('%d Views moved to the Trash.', 'wpv-views'), true); wpv_maybe_show_listing_message('untrashed', __('View restored from the Trash.', 'wpv-views'), __('%d Views restored from the Trash.', 'wpv-views')); wpv_maybe_show_listing_message('deleted', __('View permanently deleted.', 'wpv-views'), __('%d Views permanently deleted.', 'wpv-views')); if ($has_views) { // Display the rest of the content if there are Views to list wpv_admin_view_listing_table($views_pre_query_data, $current_post_status); } else { // Show a message in any other case ?> <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> <!-- .wpv-views-listing-page" --> </div> <!-- .toolset-views" --> <?php wpv_render_view_listing_dialog_templates(); }
function wpv_change_wpa_for_archive_loop_popup_callback() { wpv_ajax_authenticate( 'wpv_wp_archive_arrange_usage', array( 'parameter_source' => 'get', 'type_of_death' => 'data' ) ); if ( ! isset( $_GET["id"] ) ) { $data = array( 'message' => __( 'Untrusted data', 'wpv-views' ) ); wp_send_json_error( $data ); } global $WPV_view_archive_loop, $WPV_settings; // Slug of the loop. $loop_key = sanitize_text_field( $_GET["id"] ); $loops = $WPV_view_archive_loop->_get_post_type_loops(); /* We will slightly misuse this function, but it gives us exactly what we need: * a list of published WPAs. */ $views_pre_query_data = wpv_prepare_view_listing_query( array( 'archive', 'layouts-loop' ), 'publish', array( 'posts.post_title' => 'post_title' ), // also give us post title true, // return rows from the table array( "posts.post_status = 'publish'" ) ); // limit mysql query only to published posts $views = $views_pre_query_data['rows']; // ID of currently assigned view or 0. $currently_assigned_view_id = isset( $WPV_settings[ $loop_key ] ) ? $WPV_settings[ $loop_key ] : 0; ob_start(); ?> <div class="wpv-dialog wpv-shortcode-gui-content-wrapper js-wpv-dialog-change"> <h3><?php _e( 'Select a WordPress Archive', 'wpv-views' ); ?></h3> <?php wp_nonce_field( 'wpv_view_edit_nonce', 'wpv_view_edit_nonce' ); ?> <input type="hidden" value="<?php echo esc_attr( $loop_key ); ?>" id="js-wpv-change-wpa-for-archive-loop-key" name="wpv-archive-loop-key" /> <ul id="js-wpv-change-wpa-for-archive-loop-list" class="wpv-mightlong-list"> <li> <label> <input type="radio" name="wpv-view-loop-archive" value="0" <?php checked( 0 == $currently_assigned_view_id ); ?> /> <?php _e( 'Don\'t use a WordPress Archive for this loop', 'wpv-views' ); ?> </label> </li> <?php foreach ( $views as $view ) { ?> <li> <label> <input type="radio" <?php checked( $view->id == $currently_assigned_view_id ); ?> name="wpv-view-loop-archive" value="<?php echo esc_attr( $view->id ); ?>" /> <?php echo $view->post_title; ?> </label> </li> <?php } ?> </ul> </div> <?php $response = ob_get_clean(); $data = array( 'dialog_content' => $response ); wp_send_json_success( $data ); }
function wpv_show_views_for_loop_callback() { if (!current_user_can('manage_options')) { die("Untrusted user"); } if (!wp_verify_nonce($_POST["wpnonce"], 'wpv_wp_archive_arrange_usage')) { die("Security check"); } if (!isset($_POST["id"])) { die("Untrusted data"); } global $WPV_view_archive_loop, $WPV_settings; // Slug of the loop. $loop_key = sanitize_text_field($_POST["id"]); $loops = $WPV_view_archive_loop->_get_post_type_loops(); ?> <div class="wpv-dialog wpv-dialog-change js-wpv-dialog-change"> <form id="wpv-archive-view-form-for-loop"> <div class="wpv-dialog-header"> <h2><?php _e('Select WordPress Archive For Loop', 'wpv-views'); ?> </h2> <i class="icon-remove js-dialog-close"></i> </div> <div class="wpv-dialog-content"> <h3><?php _e('Archive views', 'wpv-views'); ?> </h3> <?php wp_nonce_field('wpv_view_edit_nonce', 'wpv_view_edit_nonce'); ?> <input type="hidden" value="<?php echo esc_attr($loop_key); ?> " name="wpv-archive-loop-key" /> <?php /* We will slightly misuse this function, but it gives us exactly what we need: * a list of published WPAs. */ $views_pre_query_data = wpv_prepare_view_listing_query(array('archive', 'layouts-loop'), 'publish', array('posts.post_title' => 'post_title'), true, array("posts.post_status = 'publish'")); // limit mysql query only to published posts $views = $views_pre_query_data['rows']; // ID of currently assigned view or 0. $currently_assigned_view_id = isset($WPV_settings[$loop_key]) ? $WPV_settings[$loop_key] : 0; ?> <ul> <li> <label> <input type="radio" name="wpv-view-loop-archive" value="0" <?php checked(0 == $currently_assigned_view_id); ?> /> <?php _e('Don\'t use a WordPress Archive for this loop', 'wpv-views'); ?> </label> </li> <?php foreach ($views as $view) { ?> <li> <label> <input type="radio" <?php checked($view->id == $currently_assigned_view_id); ?> name="wpv-view-loop-archive" value="<?php echo esc_attr($view->id); ?> " /> <?php echo $view->post_title; ?> </label> </li> <?php } ?> </ul> </div> <div class="wpv-dialog-footer"> <button class="button-secondary js-dialog-close" type="button" name="wpv-archive-view-cancel"><?php _e('Cancel', 'wpv-views'); ?> </button> <button class="button-primary js-update-archive-for-loop" type="button" name="wpv-archive-view-ok"> <?php _e('Accept', 'wpv-views'); ?> </button> </div> </form> </div> <?php die; }