PluginProbe
TablePress – Tables in WordPress made easy / 1.14
TablePress – Tables in WordPress made easy v1.14
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
tablepress / views / view-options.php

view-options.php in TablePress – Tables in WordPress made easy 1.14, at views/view-options.php

198 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Options 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 * Plugin Options View class
16 * @package TablePress
17 * @subpackage Views
18 * @author Tobias Bäthge
19 * @since 1.0.0
20 */
21 class TablePress_Options_View extends TablePress_View {
22
23 /**
24 * Set up the view with data and do things that are specific for this view.
25 *
26 * @since 1.0.0
27 *
28 * @param string $action Action for this view.
29 * @param array $data Data for this view.
30 */
31 public function setup( $action, array $data ) {
32 parent::setup( $action, $data );
33
34 // Enqueue WordPress copy of CodeMirror, with CSS linting, etc.
35 $codemirror_settings = wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
36 if ( ! empty( $codemirror_settings ) ) {
37 // Load CSS adjustments for CodeMirror and the added vertical resizing.
38 $this->admin_page->enqueue_style( 'codemirror', array( 'code-editor' ) ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
39 $this->admin_page->enqueue_script( 'codemirror', array( 'jquery', 'jquery-ui-resizable' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
40 'codemirror_settings' => $codemirror_settings,
41 ) );
42 }
43
44 $this->admin_page->enqueue_script( 'options', array( 'jquery' ), array( // phpcs:ignore PEAR.Functions.FunctionCallSignature.MultipleArguments
45 'strings' => array(
46 'uninstall_warning_1' => __( 'Do you really want to uninstall TablePress and delete ALL data?', 'tablepress' ),
47 'uninstall_warning_2' => __( 'Are you really sure?', 'tablepress' ),
48 ),
49 ) );
50
51 $this->process_action_messages( array(
52 'success_save' => __( 'Options saved successfully.', 'tablepress' ),
53 'success_save_error_custom_css' => __( 'Options saved successfully, but &#8220;Custom CSS&#8221; was not saved to file.', 'tablepress' ),
54 'error_save' => __( 'Error: Options could not be saved.', 'tablepress' ),
55 ) );
56
57 $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' );
58 if ( current_user_can( 'tablepress_edit_options' ) ) {
59 $this->add_meta_box( 'frontend-options', __( 'Frontend Options and Styling', 'tablepress' ), array( $this, 'postbox_frontend_options' ), 'normal' );
60 }
61 $this->add_meta_box( 'user-options', __( 'User Options', 'tablepress' ), array( $this, 'postbox_user_options' ), 'normal' );
62 $this->data['submit_button_caption'] = __( 'Save Changes', 'tablepress' );
63 $this->add_text_box( 'submit', array( $this, 'textbox_submit_button' ), 'submit' );
64 if ( current_user_can( 'deactivate_plugin', TABLEPRESS_BASENAME ) && current_user_can( 'tablepress_edit_options' ) && current_user_can( 'tablepress_delete_tables' ) && ! is_plugin_active_for_network( TABLEPRESS_BASENAME ) ) {
65 $this->add_text_box( 'uninstall-tablepress', array( $this, 'textbox_uninstall_tablepress' ), 'submit' );
66 }
67 }
68
69 /**
70 * Print the screen head text.
71 *
72 * @since 1.0.0
73 *
74 * @param array $data Data for this screen.
75 * @param array $box Information about the text box.
76 */
77 public function textbox_head( array $data, array $box ) {
78 ?>
79 <p>
80 <?php _e( 'TablePress has some options which affect the plugin&#8217;s behavior in different areas.', 'tablepress' ); ?>
81 </p>
82 <?php
83 }
84
85 /**
86 * Print the content of the "Frontend Options" post meta box.
87 *
88 * @since 1.0.0
89 *
90 * @param array $data Data for this screen.
91 * @param array $box Information about the meta box.
92 */
93 public function postbox_frontend_options( array $data, array $box ) {
94 ?>
95 <table class="tablepress-postbox-table fixed">
96 <tbody>
97 <tr>
98 <th class="column-1" scope="row"><label for="option-custom-css"><?php _e( 'Custom CSS', 'tablepress' ); ?></label>:</th>
99 <td class="column-2"><label for="option-use-custom-css"><input type="checkbox" id="option-use-custom-css" name="options[use_custom_css]" value="true"<?php checked( $data['frontend_options']['use_custom_css'] ); ?> /> <?php _e( 'Load this &#8220;Custom CSS&#8221; code to change the table styling:', 'tablepress' ); ?></label>
100 </td>
101 </tr>
102 <tr>
103 <td class="column-1"></td>
104 <td class="column-2">
105 <textarea name="options[custom_css]" id="option-custom-css" class="large-text" rows="8"><?php echo esc_textarea( $data['frontend_options']['custom_css'] ); ?></textarea>
106 <p class="description">
107 <?php
108 printf( __( '&#8220;Custom CSS&#8221; (<a href="%s">Cascading Style Sheets</a>) can be used to change the styling or layout of a table.', 'tablepress' ), 'https://www.htmldog.com/guides/css/beginner/' );
109 echo ' ';
110 printf( __( 'You can get styling examples from the <a href="%s">FAQ</a>.', 'tablepress' ), 'https://tablepress.org/faq/' );
111 echo ' ';
112 printf( __( 'Information on available CSS selectors can be found in the <a href="%s">Documentation</a>.', 'tablepress' ), 'https://tablepress.org/documentation/' );
113 echo ' ';
114 _e( 'Please note that invalid CSS code will be stripped, if it can not be corrected automatically.', 'tablepress' );
115 ?>
116 </p>
117 </td>
118 </tr>
119 </tbody>
120 </table>
121 <?php
122 }
123
124 /**
125 * Print the content of the "User Options" post meta box.
126 *
127 * @since 1.0.0
128 *
129 * @param array $data Data for this screen.
130 * @param array $box Information about the meta box.
131 */
132 public function postbox_user_options( array $data, array $box ) {
133 ?>
134 <table class="tablepress-postbox-table fixed">
135 <tbody>
136 <?php
137 // Get list of current admin menu entries.
138 $entries = array();
139 foreach ( $GLOBALS['menu'] as $entry ) {
140 if ( false !== strpos( $entry[2], '.php' ) ) {
141 $entries[ $entry[2] ] = $entry[0];
142 }
143 }
144
145 // Remove <span> elements with notification bubbles (e.g. update or comment count).
146 if ( isset( $entries['plugins.php'] ) ) {
147 $entries['plugins.php'] = preg_replace( '/ <span.*span>/', '', $entries['plugins.php'] );
148 }
149 if ( isset( $entries['edit-comments.php'] ) ) {
150 $entries['edit-comments.php'] = preg_replace( '/ <span.*span>/', '', $entries['edit-comments.php'] );
151 }
152
153 // Add separator and generic positions.
154 $entries['-'] = '---';
155 $entries['top'] = __( 'Top-Level (top)', 'tablepress' );
156 $entries['middle'] = __( 'Top-Level (middle)', 'tablepress' );
157 $entries['bottom'] = __( 'Top-Level (bottom)', 'tablepress' );
158
159 $select_box = '<select id="option-admin-menu-parent-page" name="options[admin_menu_parent_page]">' . "\n";
160 foreach ( $entries as $page => $entry ) {
161 $select_box .= '<option' . selected( $page, $data['user_options']['parent_page'], false ) . disabled( $page, '-', false ) . ' value="' . $page . '">' . $entry . "</option>\n";
162 }
163 $select_box .= "</select>\n";
164 ?>
165 <tr>
166 <th class="column-1" scope="row"><label for="option-admin-menu-parent-page"><?php _e( 'Admin menu entry', 'tablepress' ); ?>:</label></th>
167 <td class="column-2"><?php printf( __( 'TablePress shall be shown in this section of my admin menu: %s', 'tablepress' ), $select_box ); ?></td>
168 </tr>
169 </tbody>
170 </table>
171 <?php
172 }
173
174 /**
175 * Print the content of the "Admin Options" post meta box.
176 *
177 * @since 1.0.0
178 *
179 * @param array $data Data for this screen.
180 * @param array $box Information about the text box.
181 */
182 public function textbox_uninstall_tablepress( array $data, array $box ) {
183 ?>
184 <h1 style="margin-top:40px;"><?php _e( 'Uninstall TablePress', 'tablepress' ); ?></h1>
185 <p>
186 <?php
187 echo __( 'Uninstalling <strong>will permanently delete</strong> all TablePress tables and options from the database.', 'tablepress' ) . '<br />'
188 . __( 'It is recommended that you create a backup of the tables (by exporting the tables in the JSON format), in case you later change your mind.', 'tablepress' ) . '<br />'
189 . __( 'You will manually need to remove the plugin&#8217;s files from the plugin folder afterwards.', 'tablepress' ) . '<br />'
190 . __( 'Be very careful with this and only click the button if you know what you are doing!', 'tablepress' );
191 ?>
192 </p>
193 <p><a href="<?php echo TablePress::url( array( 'action' => 'uninstall_tablepress' ), true, 'admin-post.php' ); ?>" id="uninstall-tablepress" class="button"><?php _e( 'Uninstall TablePress', 'tablepress' ); ?></a></p>
194 <?php
195 }
196
197 } // class TablePress_Options_View
198