| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
class FV_Player_List_Table_View { |
| 6 |
|
| 7 |
var $list_page = false; |
| 8 |
|
| 9 |
function __construct() { |
| 10 |
add_action( 'init', array( $this, 'load_options' ) ); |
| 11 |
} |
| 12 |
|
| 13 |
function admin_menu(){ |
| 14 |
if( current_user_can('edit_posts') ) { |
| 15 |
add_menu_page( 'FV Player', 'FV Player', 'edit_posts', 'fv_player', '', flowplayer::get_plugin_url().'/images/icon@x2.png', 30 ); |
| 16 |
$this->list_page = add_submenu_page( 'fv_player', 'FV Player', 'Videos/Playlists', 'edit_posts', 'fv_player', array($this, 'tools_panel') ); |
| 17 |
|
| 18 |
add_action( 'load-'.$this->list_page, array( $this, 'screen_options' ) ); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
function settings_link() { |
| 23 |
add_submenu_page( 'fv_player', 'FV Player Settings', 'Settings', 'manage_options', 'fvplayer', 'fv_player_admin_page' ); |
| 24 |
} |
| 25 |
|
| 26 |
function load_options() { |
| 27 |
add_action( 'admin_menu', array($this, 'admin_menu') ); |
| 28 |
|
| 29 |
add_action( 'admin_menu', array($this, 'settings_link'), 12 ); |
| 30 |
|
| 31 |
add_action( 'admin_head', array($this, 'admin_menu_styling') ); |
| 32 |
add_action( 'admin_print_styles-toplevel_page_fv_player', array($this, 'styling') ); |
| 33 |
add_filter( 'set-screen-option', array($this, 'set_screen_option'), 10, 3); |
| 34 |
add_filter( 'set_screen_option_fv_player_per_page', array($this, 'set_screen_option'), 10, 3); |
| 35 |
|
| 36 |
add_filter( 'manage_toplevel_page_fv_player_columns', array( $this, 'screen_columns' ) ); |
| 37 |
add_filter( 'hidden_columns', array( $this, 'screen_columns_hidden' ), 10, 3 ); |
| 38 |
} |
| 39 |
|
| 40 |
function set_screen_option($status, $option, $value) { |
| 41 |
if( 'fv_player_per_page' == $option ) return $value; |
| 42 |
return $status; |
| 43 |
} |
| 44 |
|
| 45 |
function screen_columns() { |
| 46 |
return FV_Player_List_Table::get_columns_worker(); |
| 47 |
} |
| 48 |
|
| 49 |
function screen_columns_hidden( $hidden, $screen, $use_defaults ) { |
| 50 |
if ( $use_defaults && 'toplevel_page_fv_player' === $screen->id ) { |
| 51 |
$hidden = array( 'subtitles_count', 'chapters_count', 'transcript_count', 'author' ); |
| 52 |
} |
| 53 |
return $hidden; |
| 54 |
} |
| 55 |
|
| 56 |
function screen_options() { |
| 57 |
$screen = get_current_screen(); |
| 58 |
if(!is_object($screen) || $screen->id != $this->list_page) |
| 59 |
return; |
| 60 |
|
| 61 |
$args = array( |
| 62 |
'label' => __( 'Players per page', 'fv-player' ), |
| 63 |
'default' => 25, |
| 64 |
'option' => 'fv_player_per_page' |
| 65 |
); |
| 66 |
add_screen_option( 'per_page', $args ); |
| 67 |
} |
| 68 |
|
| 69 |
function styling() { |
| 70 |
global $fv_wp_flowplayer_ver; |
| 71 |
wp_enqueue_style('fv-player-list-view', flowplayer::get_plugin_url().'/css/list-view.css', array(), filemtime( dirname(__FILE__).'/../css/list-view.css' ) ); |
| 72 |
|
| 73 |
wp_enqueue_media(); |
| 74 |
} |
| 75 |
|
| 76 |
function admin_menu_styling() { |
| 77 |
?> |
| 78 |
<style>#adminmenu #toplevel_page_fv_player .wp-menu-image img {width:28px;height:25px;padding-top:4px !important}</style> |
| 79 |
<?php |
| 80 |
} |
| 81 |
|
| 82 |
function tools_panel() { |
| 83 |
|
| 84 |
$user = get_current_user_id(); |
| 85 |
$screen = get_current_screen(); |
| 86 |
$screen_option = $screen->get_option('per_page', 'option'); |
| 87 |
$per_page = get_user_meta($user, $screen_option, true); |
| 88 |
if ( empty ( $per_page) || $per_page < 1 ) { |
| 89 |
$per_page = $screen->get_option( 'per_page', 'default' ); |
| 90 |
} |
| 91 |
$table = new FV_Player_List_Table( array( |
| 92 |
'per_page' => $per_page |
| 93 |
) ); |
| 94 |
|
| 95 |
$table->prepare_items(); |
| 96 |
?> |
| 97 |
<div class="wrap"> |
| 98 |
<h1 class="wp-heading-inline">FV Player</h1> |
| 99 |
<a href="#" class="page-title-action fv-player-edit" data-add_new="1">Add New</a> |
| 100 |
<a href="#" class="page-title-action fv-player-import">Import</a> |
| 101 |
|
| 102 |
<div id="fv_player_players_table"> |
| 103 |
<form id="fv-player-filter" method="get" action="<?php echo admin_url( 'admin.php?page=fv_player' ); ?>"> |
| 104 |
<input type="hidden" name="page" value="fv_player" /> |
| 105 |
|
| 106 |
<?php |
| 107 |
// Show the current taxonomy filtering, if any |
| 108 |
// This is filtering players by post type, core WordPress wp-admin -> Posts does not use nonce for filters either |
| 109 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 110 |
$desired_post_type = ! empty( $_GET['post_type'] ) ? sanitize_key( $_GET['post_type'] ) : false; |
| 111 |
|
| 112 |
if ( $desired_post_type ) { |
| 113 |
$post_type_taxonomies = get_taxonomies( array( |
| 114 |
'object_type' => array( $desired_post_type ), |
| 115 |
'public' => true, |
| 116 |
'show_ui' => true, |
| 117 |
), 'objects' ); |
| 118 |
|
| 119 |
foreach ( $post_type_taxonomies AS $tax ) { |
| 120 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 121 |
$desired_tax = ! empty( $_GET[ $tax->name ] ) ? sanitize_key( $_GET[ $tax->name ] ) : false; |
| 122 |
|
| 123 |
if ( $desired_tax ) : |
| 124 |
$term = term_exists( $desired_tax, $tax->name ); |
| 125 |
if ( $term ) : |
| 126 |
$term = get_term( $term['term_id'], $tax->name ); |
| 127 |
?> |
| 128 |
<p class="subsubsub" style="position: absolute; margin-top: 43px;"><?php echo esc_html( $tax->labels->singular_name ); ?>: <strong><?php echo esc_html( $term->name ); ?></strong></p> |
| 129 |
<?php |
| 130 |
endif; |
| 131 |
endif; |
| 132 |
} |
| 133 |
} |
| 134 |
?> |
| 135 |
|
| 136 |
<p class="subsubsub" style="line-height: 26px; margin-right: .5em">Embed post type:</p> |
| 137 |
|
| 138 |
<?php $table->views() ?> |
| 139 |
|
| 140 |
<?php $table->advanced_filters(); ?> |
| 141 |
|
| 142 |
<?php $table->display() ?> |
| 143 |
</form> |
| 144 |
</div> |
| 145 |
|
| 146 |
</div> |
| 147 |
<?php |
| 148 |
fv_player_shortcode_editor_scripts_enqueue(); |
| 149 |
fv_wp_flowplayer_edit_form_after_editor(); |
| 150 |
|
| 151 |
wp_enqueue_script( 'fv-player-list-view', flowplayer::get_plugin_url().'/js/list-table.js', array('jquery'), filemtime( dirname(__FILE__).'/../js/list-table.js' ), true ); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
$FV_Player_List_Table_View = new FV_Player_List_Table_View; |
| 156 |
|