PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.85
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.85
5.5.85 5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 All 161 releases
← All changes | WPDataAccess/Settings/WPDA_Settings_FrontEnd.php +179 -237 5.5.41 → 5.5.85 View file →
@@ -1,182 +1,156 @@
1 1 <?php
2 2
3 -namespace WPDataAccess\Settings;
3 +namespace WPDataAccess\Settings {
4 4
5 -use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist;
6 -use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists;
7 -use WPDataAccess\Utilities\WPDA_Message_Box;
8 -use WPDataAccess\WPDA;
9 -class WPDA_Settings_FrontEnd extends WPDA_Settings {
10 - /**
11 - * Available UI themes
12 - */
13 - const UI_THEMES = array(
14 - 'ui-darkness',
15 - 'ui-lightness',
16 - 'swanky-purse',
17 - 'sunny',
18 - 'start',
19 - 'smoothness',
20 - 'black-tie',
21 - 'blitzer',
22 - 'cupertino',
23 - 'dark-hive',
24 - 'dot-luv',
25 - 'eggplant',
26 - 'excite-bike',
27 - 'flick',
28 - 'hot-sneaks',
29 - 'humanity',
30 - 'le-frog',
31 - 'mint-choc',
32 - 'overcast',
33 - 'pepper-grinder',
34 - 'redmond',
35 - 'south-street',
36 - 'trontastic',
37 - 'vader'
38 - );
5 + use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist;
6 + use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists;
7 + use WPDataAccess\Utilities\WPDA_Message_Box;
8 + use WPDataAccess\WPDA;
39 9
40 - /**
41 - * Add front-end tab content
42 - *
43 - * See class documentation for flow explanation.
44 - *
45 - * @since 1.0.0
46 - */
47 - protected function add_content() {
48 - global $wpdb;
49 - if ( isset( $_REQUEST['database'] ) ) {
50 - $database = sanitize_text_field( wp_unslash( $_REQUEST['database'] ) );
51 - // input var okay.
52 - } else {
53 - $database = $wpdb->dbname;
54 - }
55 - $is_wp_database = $database === $wpdb->dbname;
56 - if ( isset( $_REQUEST['action'] ) ) {
57 - $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) );
58 - // input var okay.
59 - // Security check.
60 - $wp_nonce = ( isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '' );
61 - // input var okay.
62 - if ( !wp_verify_nonce( $wp_nonce, 'wpda-front-end-settings-' . WPDA::get_current_user_login() ) ) {
63 - wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) );
64 - }
65 - if ( 'save' === $action ) {
66 - if ( $is_wp_database ) {
67 - WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS, ( isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null ) );
68 - } else {
69 - update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database, ( isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null ) );
70 - }
71 - $table_access_selected_new_value = ( isset( $_REQUEST['table_access_selected'] ) ? WPDA::sanitize_text_field_array( $_REQUEST['table_access_selected'] ) : null );
72 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
73 - if ( is_array( $table_access_selected_new_value ) ) {
74 - // Check the requested table names for sql injection. This is simply done by checking if the table
75 - // name exists in our WordPress database.
76 - $table_access_selected_new_value_checked = array();
77 - foreach ( $table_access_selected_new_value as $key => $value ) {
78 - $wpda_dictionary_checks = new WPDA_Dictionary_Exist($database, $value);
79 - if ( $wpda_dictionary_checks->table_exists( false, false ) ) {
80 - // Add existing table to list.
81 - $table_access_selected_new_value_checked[$key] = $value;
82 - } else {
83 - // An invalid table name was provided. Might be an sql injection attack or an invalid state.
84 - wp_die( __( 'ERROR: Table not found', 'wp-data-access' ) );
85 - }
86 - }
87 - } else {
88 - $table_access_selected_new_value_checked = '';
89 - }
90 - if ( $is_wp_database ) {
91 - WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS_SELECTED, $table_access_selected_new_value_checked );
92 - } else {
93 - update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_SELECTED . $database, $table_access_selected_new_value_checked );
94 - }
95 - WPDA::set_option( WPDA::OPTION_FE_PAGINATION, ( isset( $_REQUEST['pagination'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['pagination'] ) ) : null ) );
96 - if ( isset( $_REQUEST['ui_theme'] ) ) {
97 - WPDA::set_option( WPDA::WPDA_DT_UI_THEME_DEFAULT, sanitize_text_field( wp_unslash( $_REQUEST['ui_theme'] ) ) );
98 - }
99 - WPDA::set_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR, ( isset( $_REQUEST['add_projects_to_toolbar'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['add_projects_to_toolbar'] ) ) : 'off' ) );
100 - } elseif ( 'setdefaults' === $action ) {
101 - // Set all front-end settings back to default
102 - if ( $is_wp_database ) {
103 - WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS );
104 - WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS_SELECTED );
105 - } else {
106 - update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database, 'select' );
107 - update_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_SELECTED . $database, '' );
108 - }
109 - WPDA::set_option( WPDA::OPTION_FE_PAGINATION );
110 - WPDA::set_option( WPDA::WPDA_DT_UI_THEME_DEFAULT );
111 - WPDA::set_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR );
112 - }
113 - $msg = new WPDA_Message_Box(array(
114 - 'message_text' => __( 'Settings saved', 'wp-data-access' ),
115 - ));
116 - $msg->box();
117 - }
118 - // Get options
119 - if ( $is_wp_database ) {
120 - $table_access = WPDA::get_option( WPDA::OPTION_FE_TABLE_ACCESS );
121 - $table_access_selected = WPDA::get_option( WPDA::OPTION_FE_TABLE_ACCESS_SELECTED );
122 - } else {
123 - $table_access = get_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database );
124 - if ( false === $table_access ) {
125 - $table_access = 'select';
126 - }
127 - $table_access_selected = get_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_SELECTED . $database );
128 - if ( false === $table_access_selected ) {
129 - $table_access_selected = '';
130 - }
131 - }
132 - if ( is_array( $table_access_selected ) ) {
133 - // Convert table for simple access.
134 - $table_access_selected_by_name = array();
135 - foreach ( $table_access_selected as $key => $value ) {
136 - $table_access_selected_by_name[$value] = true;
137 - }
138 - }
139 - $pagination = WPDA::get_option( WPDA::OPTION_FE_PAGINATION );
140 - $ui_theme_default = WPDA::get_option( WPDA::WPDA_DT_UI_THEME_DEFAULT );
141 - $add_projects_to_toolbar = WPDA::get_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR );
142 - ?>
10 + class WPDA_Settings_FrontEnd extends WPDA_Settings {
11 +
12 + /**
13 + * Add front-end tab content
14 + *
15 + * See class documentation for flow explanation.
16 + *
17 + * @since 1.0.0
18 + */
19 + protected function add_content() {
20 + global $wpdb;
21 +
22 + if ( isset( $_REQUEST['database'] ) ) {
23 + $database = sanitize_text_field( wp_unslash( $_REQUEST['database'] ) ); // input var okay.
24 + } else {
25 + $database = $wpdb->dbname;
26 + }
27 + $is_wp_database = $database === $wpdb->dbname;
28 +
29 + if ( isset( $_REQUEST['action'] ) ) {
30 + $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // input var okay.
31 +
32 + // Security check.
33 + $wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay.
34 + if ( ! wp_verify_nonce( $wp_nonce, 'wpda-front-end-settings-' . WPDA::get_current_user_login() ) ) {
35 + wp_die( esc_attr__( 'ERROR: Not authorized', 'wp-data-access' ) );
36 + }
37 +
38 + if ( 'save' === $action ) {
39 + if ( $is_wp_database ) {
40 + WPDA::set_option(
41 + WPDA::OPTION_FE_TABLE_ACCESS,
42 + isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null // input var okay.
43 + );
44 + } else {
45 + update_option(
46 + WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database,
47 + isset( $_REQUEST['table_access'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_access'] ) ) : null // input var okay.
48 + );
49 + }
50 +
51 + $table_access_selected_new_value = isset( $_REQUEST['table_access_selected'] ) ?
52 + WPDA::sanitize_text_field_array( $_REQUEST['table_access_selected'] ) : null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
53 + if ( is_array( $table_access_selected_new_value ) ) {
54 + // Check the requested table names for sql injection. This is simply done by checking if the table
55 + // name exists in our WordPress database.
56 + $table_access_selected_new_value_checked = array();
57 + foreach ( $table_access_selected_new_value as $key => $value ) {
58 + $wpda_dictionary_checks = new WPDA_Dictionary_Exist( $database, $value );
59 + if ( $wpda_dictionary_checks->table_exists( false, false ) ) {
60 + // Add existing table to list.
61 + $table_access_selected_new_value_checked[ $key ] = $value;
62 + } else {
63 + // An invalid table name was provided. Might be an sql injection attack or an invalid state.
64 + wp_die( esc_attr__( 'ERROR: Table not found', 'wp-data-access' ) );
65 + }
66 + }
67 + } else {
68 + $table_access_selected_new_value_checked = '';
69 + }
70 +
71 + if ( $is_wp_database ) {
72 + WPDA::set_option(
73 + WPDA::OPTION_FE_TABLE_ACCESS_SELECTED,
74 + $table_access_selected_new_value_checked
75 + );
76 + } else {
77 + update_option(
78 + WPDA::FRONTEND_OPTIONNAME_DATABASE_SELECTED . $database,
79 + $table_access_selected_new_value_checked
80 + );
81 + }
82 +
83 + WPDA::set_option(
84 + WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR,
85 + isset( $_REQUEST['add_projects_to_toolbar'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['add_projects_to_toolbar'] ) ) : 'off' // input var okay.
86 + );
87 + } elseif ( 'setdefaults' === $action ) {
88 + // Set all front-end settings back to default
89 + if ( $is_wp_database ) {
90 + WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS );
91 + WPDA::set_option( WPDA::OPTION_FE_TABLE_ACCESS_SELECTED );
92 + } else {
93 + update_option(
94 + WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database,
95 + 'select'
96 + );
97 + update_option(
98 + WPDA::FRONTEND_OPTIONNAME_DATABASE_SELECTED . $database,
99 + ''
100 + );
101 + }
102 + WPDA::set_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR );
103 + }
104 +
105 + $msg = new WPDA_Message_Box(
106 + array(
107 + 'message_text' => __( 'Settings saved', 'wp-data-access' ),
108 + )
109 + );
110 + $msg->box();
111 +
112 + }
113 +
114 + // Get options
115 + if ( $is_wp_database ) {
116 + $table_access = WPDA::get_option( WPDA::OPTION_FE_TABLE_ACCESS );
117 + $table_access_selected = WPDA::get_option( WPDA::OPTION_FE_TABLE_ACCESS_SELECTED );
118 + } else {
119 + $table_access = get_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_ACCESS . $database );
120 + if ( false === $table_access ) {
121 + $table_access = 'select';
122 + }
123 + $table_access_selected = get_option( WPDA::FRONTEND_OPTIONNAME_DATABASE_SELECTED . $database );
124 + if ( false === $table_access_selected ) {
125 + $table_access_selected = '';
126 + }
127 + }
128 +
129 + if ( is_array( $table_access_selected ) ) {
130 + // Convert table for simple access.
131 + $table_access_selected_by_name = array();
132 + foreach ( $table_access_selected as $key => $value ) {
133 + $table_access_selected_by_name[ $value ] = true;
134 + }
135 + }
136 +
137 + $add_projects_to_toolbar = WPDA::get_option( WPDA::OPTION_FE_ADD_PROJECTS_TO_TOOLBAR );
138 + ?>
143 139 <form id="wpda_settings_frontend" method="post"
144 - action="?page=<?php
145 - echo esc_attr( $this->page );
146 - ?>&tab=frontend">
140 + action="?page=<?php echo esc_attr( $this->page ); ?>&tab=frontend">
147 141 <table class="wpda-table-settings">
148 - <?php
149 - ?>
150 142 <tr>
151 - <th><?php
152 - echo __( 'Default pagination value', 'wp-data-access' );
153 - ?></th>
143 + <th><?php esc_html_e( 'Table access', 'wp-data-access' ); ?></th>
154 144 <td>
155 - <input
156 - type="number" step="1" min="1" max="999" name="pagination" maxlength="3"
157 - value="<?php
158 - echo esc_attr( $pagination );
159 - ?>">
160 - <div style="padding-top:10px">
161 - Only for shortcode <strong>wpdadiehard</strong>
162 - </div>
163 - </td>
164 - </tr>
165 - <tr>
166 - <th><?php
167 - echo __( 'Table access', 'wp-data-access' );
168 - ?></th>
169 - <td>
170 145 <select name="database" id="schema_name">
171 - <?php
172 - $schema_names = WPDA_Dictionary_Lists::get_db_schemas();
173 - foreach ( $schema_names as $schema_name ) {
174 - $selected = ( $database === $schema_name['schema_name'] ? ' selected' : '' );
175 - echo "<option value='{$schema_name['schema_name']}'{$selected}>{$schema_name['schema_name']}</option>";
176 - // phpcs:ignore WordPress.Security.EscapeOutput
177 - }
178 - ?>
146 + <?php
147 + $schema_names = WPDA_Dictionary_Lists::get_db_schemas();
148 + foreach ( $schema_names as $schema_name ) {
149 + $selected = $database === $schema_name['schema_name'] ? ' selected' : '';
150 + echo "<option value='{$schema_name['schema_name']}'$selected>{$schema_name['schema_name']}</option>"; // phpcs:ignore WordPress.Security.EscapeOutput
151 + }
152 + ?>
179 153 </select>
180 154 <br/><br/>
181 155 <label>
182 156 <input
@@ -182,67 +156,47 @@
182 156 <input
183 157 type="radio"
184 158 name="table_access"
185 159 value="show"
186 - <?php
187 - echo ( 'show' === $table_access ? 'checked' : '' );
188 - ?>
189 - ><?php
190 - echo ( $is_wp_database ? __( 'Show WordPress tables', 'wp-data-access' ) : __( 'Show all tables', 'wp-data-access' ) );
191 - ?>
160 + <?php echo 'show' === $table_access ? 'checked' : ''; ?>
161 + ><?php echo $is_wp_database ? esc_attr__( 'Show WordPress tables', 'wp-data-access' ) : esc_attr__( 'Show all tables', 'wp-data-access' ); ?>
192 162 </label>
193 163 <br/>
194 - <?php
195 - if ( $is_wp_database ) {
196 - ?>
164 + <?php
165 + if ( $is_wp_database ) {
166 + ?>
197 167 <label>
198 168 <input
199 169 type="radio"
200 170 name="table_access"
201 171 value="hide"
202 - <?php
203 - echo ( 'hide' === $table_access ? 'checked' : '' );
204 - ?>
205 - ><?php
206 - echo __( 'Hide WordPress tables', 'wp-data-access' );
207 - ?>
172 + <?php echo 'hide' === $table_access ? 'checked' : ''; ?>
173 + ><?php esc_html_e( 'Hide WordPress tables', 'wp-data-access' ); ?>
208 174 </label>
209 175 <br/>
210 - <?php
211 - }
212 - ?>
176 + <?php
177 + }
178 + ?>
213 179 <label>
214 180 <input
215 181 type="radio"
216 182 name="table_access"
217 183 value="select"
218 - <?php
219 - echo ( 'select' === $table_access ? 'checked' : '' );
220 - ?>
221 - ><?php
222 - echo __( 'Show only selected tables', 'wp-data-access' );
223 - ?>
184 + <?php echo 'select' === $table_access ? 'checked' : ''; ?>
185 + ><?php esc_html_e( 'Show only selected tables', 'wp-data-access' ); ?>
224 186 </label>
225 - <div id="tables_selected" <?php
226 - echo ( 'select' === $table_access ? '' : 'style="display:none"' );
227 - ?>>
187 + <div id="tables_selected" <?php echo 'select' === $table_access ? '' : 'style="display:none"'; ?>>
228 188 <br/>
229 189 <select name="table_access_selected[]" multiple size="10">
230 - <?php
231 - $tables = WPDA_Dictionary_Lists::get_tables( true, $database );
232 - foreach ( $tables as $table ) {
233 - $table_name = $table['table_name'];
234 - ?>
235 - <option value="<?php
236 - echo esc_attr( $table_name );
237 - ?>" <?php
238 - echo ( isset( $table_access_selected_by_name[$table_name] ) ? 'selected' : '' );
239 - ?>><?php
240 - echo esc_attr( $table_name );
241 - ?></option>
242 - <?php
243 - }
244 - ?>
190 + <?php
191 + $tables = WPDA_Dictionary_Lists::get_tables( true, $database );
192 + foreach ( $tables as $table ) {
193 + $table_name = $table['table_name'];
194 + ?>
195 + <option value="<?php echo esc_attr( $table_name ); ?>" <?php echo isset( $table_access_selected_by_name[ $table_name ] ) ? 'selected' : ''; ?>><?php echo esc_attr( $table_name ); ?></option>
196 + <?php
197 + }
198 + ?>
245 199 </select>
246 200 </div>
247 201 <script type='text/javascript'>
248 202 jQuery(function () {
@@ -253,11 +207,9 @@
253 207 jQuery("#tables_selected").hide();
254 208 }
255 209 });
256 210 jQuery('#schema_name').on('change', function() {
257 - window.location = '?page=<?php
258 - echo esc_attr( $this->page );
259 - ?>&tab=frontend&database=' + jQuery(this).val();
211 + window.location = '?page=<?php echo esc_attr( $this->page ); ?>&tab=frontend&database=' + jQuery(this).val();
260 212 });
261 213 });
262 214 </script>
263 215 </td>
@@ -262,52 +214,42 @@
262 214 </script>
263 215 </td>
264 216 </tr>
265 217 <tr>
266 - <th><?php
267 - echo __( 'Admin toolbar', 'wp-data-access' );
268 - ?></th>
218 + <th><?php esc_html_e( 'Admin toolbar', 'wp-data-access' ); ?></th>
269 219 <td>
270 220 <label>
271 221 <input type="checkbox" name="add_projects_to_toolbar"
272 - <?php
273 - echo ( 'on' === $add_projects_to_toolbar ? 'checked' : '' );
274 - ?>
222 + <?php echo 'on' === $add_projects_to_toolbar ? 'checked' : ''; ?>
275 223 />
276 - <?php
277 - echo __( 'Add projects to toolbar', 'wp-data-access' );
278 - ?>
224 + <?php esc_html_e( 'Add projects to toolbar', 'wp-data-access' ); ?>
279 225 </label>
280 226 </td>
281 227 </tr>
282 228 </table>
229 +
283 230 <div class="wpda-table-settings-button">
284 231 <input type="hidden" name="action" value="save"/>
285 232 <button type="submit" class="button button-primary">
286 233 <i class="fas fa-check wpda_icon_on_button"></i>
287 - <?php
288 - echo __( 'Save Front-end Settings', 'wp-data-access' );
289 - ?>
234 + <?php esc_html_e( 'Save Front-end Settings', 'wp-data-access' ); ?>
290 235 </button>
291 236 <a href="javascript:void(0)"
292 - onclick="if (confirm('<?php
293 - echo __( 'Reset to defaults?', 'wp-data-access' );
294 - ?>')) {
237 + onclick="if (confirm('<?php esc_html_e( 'Reset to defaults?', 'wp-data-access' ); ?>')) {
295 238 jQuery('input[name=&quot;action&quot;]').val('setdefaults');
296 239 jQuery('#wpda_settings_frontend').trigger('submit')
297 240 }"
298 241 class="button">
299 242 <i class="fas fa-times-circle wpda_icon_on_button"></i>
300 - <?php
301 - echo __( 'Reset Front-end Settings To Defaults', 'wp-data-access' );
302 - ?>
243 + <?php esc_html_e( 'Reset Front-end Settings To Defaults', 'wp-data-access' ); ?>
303 244 </a>
304 245 </div>
305 - <?php
306 - wp_nonce_field( 'wpda-front-end-settings-' . WPDA::get_current_user_login(), '_wpnonce', false );
307 - ?>
246 + <?php wp_nonce_field( 'wpda-front-end-settings-' . WPDA::get_current_user_login(), '_wpnonce', false ); ?>
308 247 </form>
309 248
310 - <?php
311 - }
249 + <?php
250 +
251 + }
252 +
253 + }
312 254
313 255 }