| 1 |
<?php |
| 2 |
/** |
| 3 |
* Editor Button Thickbox List View |
| 4 |
* |
| 5 |
* @package TablePress |
| 6 |
* @subpackage Views |
| 7 |
* @author Tobias Bäthge |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
// Prohibit direct script loading. |
| 12 |
defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 13 |
|
| 14 |
/** |
| 15 |
* Editor Button Thickbox List View class |
| 16 |
* |
| 17 |
* @package TablePress |
| 18 |
* @subpackage Views |
| 19 |
* @author Tobias Bäthge |
| 20 |
* @since 1.0.0 |
| 21 |
*/ |
| 22 |
class TablePress_Editor_Button_Thickbox_View extends TablePress_View { |
| 23 |
|
| 24 |
/** |
| 25 |
* Object for the Editor Button Thickbox List Table. |
| 26 |
* |
| 27 |
* @since 1.0.0 |
| 28 |
*/ |
| 29 |
protected \TablePress_Editor_Button_Thickbox_List_Table $wp_list_table; |
| 30 |
|
| 31 |
/** |
| 32 |
* Initializes the View class. |
| 33 |
* |
| 34 |
* @since 1.0.0 |
| 35 |
*/ |
| 36 |
public function __construct() { |
| 37 |
// Intentionally left empty, to void code from parent::__construct(). |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Sets up the view with data and do things that are specific for this view. |
| 42 |
* |
| 43 |
* @since 1.0.0 |
| 44 |
* |
| 45 |
* @param string $action Action for this view. |
| 46 |
* @param array<string, mixed> $data Data for this view. |
| 47 |
*/ |
| 48 |
#[\Override] |
| 49 |
public function setup( /* string */ $action, array $data ) /* : void */ { |
| 50 |
// Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. |
| 51 |
|
| 52 |
$this->action = $action; |
| 53 |
$this->data = $data; |
| 54 |
|
| 55 |
$this->wp_list_table = TablePress::load_class( 'TablePress_Editor_Button_Thickbox_List_Table', 'class-editor-button-thickbox-list-table.php', 'views' ); |
| 56 |
|
| 57 |
$this->wp_list_table->set_items( $this->data['table_ids'] ); |
| 58 |
$this->wp_list_table->prepare_items(); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Renders the current view. |
| 63 |
* |
| 64 |
* @since 1.0.0 |
| 65 |
*/ |
| 66 |
#[\Override] |
| 67 |
public function render(): void { |
| 68 |
_wp_admin_html_begin(); |
| 69 |
|
| 70 |
wp_print_styles( 'colors' ); |
| 71 |
wp_print_scripts( 'jquery-core' ); |
| 72 |
?> |
| 73 |
<title><?php printf( __( '%1$s ‹ %2$s', 'tablepress' ), __( 'List of Tables', 'tablepress' ), 'TablePress' ); ?></title> |
| 74 |
<style> |
| 75 |
/* Account for .wp-toolbar. */ |
| 76 |
html { |
| 77 |
padding-top: 0 !important; |
| 78 |
} |
| 79 |
#tablepress-page { |
| 80 |
margin: 0 15px; |
| 81 |
padding: 0 0 15px 0; |
| 82 |
} |
| 83 |
#tablepress-page .subtitle { |
| 84 |
float: left; |
| 85 |
padding: 10px 0 0; |
| 86 |
} |
| 87 |
#tablepress-page p.search-box { |
| 88 |
position: relative; |
| 89 |
} |
| 90 |
/* Width and font weight for the columns. */ |
| 91 |
.tablepress-editor-button-list thead .column-table_id { |
| 92 |
width: 50px; |
| 93 |
} |
| 94 |
.tablepress-editor-button-list tbody .column-table_id, |
| 95 |
.tablepress-editor-button-list tbody .column-table_name { |
| 96 |
font-weight: bold; |
| 97 |
} |
| 98 |
.tablepress-editor-button-list thead .column-table_action { |
| 99 |
min-width: 150px; |
| 100 |
} |
| 101 |
/* Responsiveness on the All Tables screen. */ |
| 102 |
@media screen and (max-width: 782px) { |
| 103 |
.tablepress-editor-button-list .column-table_id { |
| 104 |
display: none !important; |
| 105 |
padding: 3px 8px 3px 35%; |
| 106 |
} |
| 107 |
} |
| 108 |
<?php if ( is_rtl() ) : ?> |
| 109 |
/* RTL CSS */ |
| 110 |
.rtl #tablepress-page .subtitle { |
| 111 |
float: right; |
| 112 |
} |
| 113 |
<?php endif; ?> |
| 114 |
</style> |
| 115 |
</head> |
| 116 |
<body class="wp-admin wp-core-ui js iframe<?php echo is_rtl() ? ' rtl' : ''; ?>"> |
| 117 |
<div id="tablepress-page" class="wrap"> |
| 118 |
<h1><?php printf( __( '%1$s ‹ %2$s', 'tablepress' ), __( 'List of Tables', 'tablepress' ), 'TablePress' ); ?></h1> |
| 119 |
<div id="poststuff"> |
| 120 |
<p><?php _e( 'This is a list of your tables.', 'tablepress' ); ?> <?php _e( 'You may insert a table into a post or page here.', 'tablepress' ); ?></p> |
| 121 |
<p><?php printf( __( 'Click the “%1$s” button for the desired table to automatically insert its Shortcode into the editor.', 'tablepress' ), __( 'Insert Shortcode', 'tablepress' ) ); ?></p> |
| 122 |
<?php |
| 123 |
if ( ! empty( $_GET['s'] ) ) { |
| 124 |
printf( '<span class="subtitle">' . __( 'Search results for “%s”', 'tablepress' ) . '</span>', esc_html( wp_unslash( $_GET['s'] ) ) ); |
| 125 |
} |
| 126 |
?> |
| 127 |
<form method="get"> |
| 128 |
<input type="hidden" name="action" value="tablepress_<?php echo $this->action; ?>"> |
| 129 |
<?php |
| 130 |
wp_nonce_field( TablePress::nonce( $this->action ), '_wpnonce', false ); |
| 131 |
$this->wp_list_table->search_box( __( 'Search Tables', 'tablepress' ), 'tables_search' ); |
| 132 |
?> |
| 133 |
</form> |
| 134 |
<?php $this->wp_list_table->display(); ?> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
<script> |
| 138 |
jQuery( function( $ ) { |
| 139 |
// Toggle list table rows on small screens. |
| 140 |
$( '.tablepress-editor-button-list' ) |
| 141 |
.on( 'click', 'tr', function() { |
| 142 |
this.classList.toggle( 'is-expanded' ); |
| 143 |
}) |
| 144 |
.on( 'click', '.insert-shortcode', function() { |
| 145 |
const win = window.dialogArguments || opener || parent || top; |
| 146 |
win.send_to_editor( this.title ); |
| 147 |
} ); |
| 148 |
} ); |
| 149 |
</script> |
| 150 |
</body> |
| 151 |
</html> |
| 152 |
<?php |
| 153 |
} |
| 154 |
|
| 155 |
} // class TablePress_Editor_Button_View |
| 156 |
|
| 157 |
|