| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDataAccess\Settings { |
| 4 |
|
| 5 |
use WPDataAccess\Utilities\WPDA_Message_Box; |
| 6 |
use WPDataAccess\WPDA; |
| 7 |
|
| 8 |
class WPDA_Settings_Legacy_BackEnd extends WPDA_Settings_Legacy_Page { |
| 9 |
|
| 10 |
public function show() { |
| 11 |
|
| 12 |
if ( isset( $_REQUEST['action'] ) ) { |
| 13 |
$action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); // input var okay. |
| 14 |
|
| 15 |
// Security check. |
| 16 |
$wp_nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; // input var okay. |
| 17 |
if ( ! wp_verify_nonce( $wp_nonce, 'wpda-back-end-settings' ) ) { |
| 18 |
wp_die( esc_attr__( 'ERROR: Not authorized', 'wp-data-access' ) ); |
| 19 |
} |
| 20 |
|
| 21 |
if ( 'save' === $action ) { |
| 22 |
// Save options. |
| 23 |
WPDA::set_option( |
| 24 |
WPDA::OPTION_BE_VIEW_LINK, |
| 25 |
isset( $_REQUEST['view_link'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['view_link'] ) ) : 'off' // input var okay. |
| 26 |
); |
| 27 |
|
| 28 |
WPDA::set_option( |
| 29 |
WPDA::OPTION_BE_ALLOW_INSERT, |
| 30 |
isset( $_REQUEST['allow_insert'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_insert'] ) ) : 'off' // input var okay. |
| 31 |
); |
| 32 |
WPDA::set_option( |
| 33 |
WPDA::OPTION_BE_ALLOW_UPDATE, |
| 34 |
isset( $_REQUEST['allow_update'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_update'] ) ) : 'off' // input var okay. |
| 35 |
); |
| 36 |
WPDA::set_option( |
| 37 |
WPDA::OPTION_BE_ALLOW_DELETE, |
| 38 |
isset( $_REQUEST['allow_delete'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_delete'] ) ) : 'off' // input var okay. |
| 39 |
); |
| 40 |
|
| 41 |
WPDA::set_option( |
| 42 |
WPDA::OPTION_BE_EXPORT_ROWS, |
| 43 |
isset( $_REQUEST['export_rows'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['export_rows'] ) ) : 'off' // input var okay. |
| 44 |
); |
| 45 |
WPDA::set_option( |
| 46 |
WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX, |
| 47 |
isset( $_REQUEST['export_variable_rows'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['export_variable_rows'] ) ) : 'off' // input var okay. |
| 48 |
); |
| 49 |
|
| 50 |
WPDA::set_option( |
| 51 |
WPDA::OPTION_BE_ALLOW_IMPORTS, |
| 52 |
isset( $_REQUEST['allow_imports'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['allow_imports'] ) ) : 'off' // input var okay. |
| 53 |
); |
| 54 |
|
| 55 |
WPDA::set_option( |
| 56 |
WPDA::OPTION_BE_CONFIRM_EXPORT, |
| 57 |
isset( $_REQUEST['confirm_export'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['confirm_export'] ) ) : 'off' // input var okay. |
| 58 |
); |
| 59 |
WPDA::set_option( |
| 60 |
WPDA::OPTION_BE_CONFIRM_VIEW, |
| 61 |
isset( $_REQUEST['confirm_view'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['confirm_view'] ) ) : 'off' // input var okay. |
| 62 |
); |
| 63 |
|
| 64 |
WPDA::set_option( |
| 65 |
WPDA::OPTION_BE_PAGINATION, |
| 66 |
isset( $_REQUEST['pagination'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['pagination'] ) ) : null // input var okay. |
| 67 |
); |
| 68 |
|
| 69 |
WPDA::set_option( |
| 70 |
WPDA::OPTION_BE_REMEMBER_SEARCH, |
| 71 |
isset( $_REQUEST['remember_search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['remember_search'] ) ) : 'off' // input var okay. |
| 72 |
); |
| 73 |
|
| 74 |
WPDA::set_option( |
| 75 |
WPDA::OPTION_BE_INNODB_COUNT, |
| 76 |
isset( $_REQUEST['innodb_count'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['innodb_count'] ) ) : 100000 // input var okay. |
| 77 |
); |
| 78 |
|
| 79 |
WPDA::set_option( |
| 80 |
WPDA::OPTION_BE_DESIGN_MODE, |
| 81 |
isset( $_REQUEST['design_mode'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['design_mode'] ) ) : 'basic' // input var okay. |
| 82 |
); |
| 83 |
|
| 84 |
WPDA::set_option( |
| 85 |
WPDA::OPTION_BE_TEXT_WRAP_SWITCH, |
| 86 |
isset( $_REQUEST['text_wrap_switch'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['text_wrap_switch'] ) ) : 'off' // input var okay. |
| 87 |
); |
| 88 |
|
| 89 |
WPDA::set_option( |
| 90 |
WPDA::OPTION_BE_TEXT_WRAP, |
| 91 |
isset( $_REQUEST['text_wrap'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['text_wrap'] ) ) : 400 // input var okay. |
| 92 |
); |
| 93 |
|
| 94 |
WPDA::set_option( |
| 95 |
WPDA::OPTION_BE_HIDE_BUTTON_ICONS, |
| 96 |
isset( $_REQUEST['hide_button_icons'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['hide_button_icons'] ) ) : 'off' // input var okay. |
| 97 |
); |
| 98 |
} elseif ( 'setdefaults' === $action ) { |
| 99 |
// Set all back-end settings back to default. |
| 100 |
WPDA::set_option( WPDA::OPTION_BE_VIEW_LINK ); |
| 101 |
WPDA::set_option( WPDA::OPTION_BE_ALLOW_INSERT ); |
| 102 |
WPDA::set_option( WPDA::OPTION_BE_ALLOW_UPDATE ); |
| 103 |
WPDA::set_option( WPDA::OPTION_BE_ALLOW_DELETE ); |
| 104 |
WPDA::set_option( WPDA::OPTION_BE_EXPORT_ROWS ); |
| 105 |
WPDA::set_option( WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX ); |
| 106 |
WPDA::set_option( WPDA::OPTION_BE_ALLOW_IMPORTS ); |
| 107 |
WPDA::set_option( WPDA::OPTION_BE_CONFIRM_EXPORT ); |
| 108 |
WPDA::set_option( WPDA::OPTION_BE_CONFIRM_VIEW ); |
| 109 |
WPDA::set_option( WPDA::OPTION_BE_PAGINATION ); |
| 110 |
WPDA::set_option( WPDA::OPTION_BE_REMEMBER_SEARCH ); |
| 111 |
WPDA::set_option( WPDA::OPTION_BE_INNODB_COUNT ); |
| 112 |
WPDA::set_option( WPDA::OPTION_BE_DESIGN_MODE ); |
| 113 |
WPDA::set_option( WPDA::OPTION_BE_TEXT_WRAP_SWITCH ); |
| 114 |
WPDA::set_option( WPDA::OPTION_BE_TEXT_WRAP ); |
| 115 |
WPDA::set_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS ); |
| 116 |
} |
| 117 |
|
| 118 |
$msg = new WPDA_Message_Box( |
| 119 |
array( |
| 120 |
'message_text' => __( 'Settings saved', 'wp-data-access' ), |
| 121 |
) |
| 122 |
); |
| 123 |
$msg->box(); |
| 124 |
} |
| 125 |
|
| 126 |
// Get options. |
| 127 |
$view_link = WPDA::get_option( WPDA::OPTION_BE_VIEW_LINK ); |
| 128 |
|
| 129 |
$allow_insert = WPDA::get_option( WPDA::OPTION_BE_ALLOW_INSERT ); |
| 130 |
$allow_update = WPDA::get_option( WPDA::OPTION_BE_ALLOW_UPDATE ); |
| 131 |
$allow_delete = WPDA::get_option( WPDA::OPTION_BE_ALLOW_DELETE ); |
| 132 |
|
| 133 |
$export_rows = WPDA::get_option( WPDA::OPTION_BE_EXPORT_ROWS ); |
| 134 |
$export_variable_rows = WPDA::get_option( WPDA::OPTION_BE_EXPORT_VARIABLE_PREFIX ); |
| 135 |
|
| 136 |
$allow_imports = WPDA::get_option( WPDA::OPTION_BE_ALLOW_IMPORTS ); |
| 137 |
|
| 138 |
$confirm_export = WPDA::get_option( WPDA::OPTION_BE_CONFIRM_EXPORT ); |
| 139 |
$confirm_view = WPDA::get_option( WPDA::OPTION_BE_CONFIRM_VIEW ); |
| 140 |
|
| 141 |
$pagination = WPDA::get_option( WPDA::OPTION_BE_PAGINATION ); |
| 142 |
|
| 143 |
$remember_search = WPDA::get_option( WPDA::OPTION_BE_REMEMBER_SEARCH ); |
| 144 |
|
| 145 |
$innodb_count = WPDA::get_option( WPDA::OPTION_BE_INNODB_COUNT ); |
| 146 |
|
| 147 |
$design_mode = WPDA::get_option( WPDA::OPTION_BE_DESIGN_MODE ); |
| 148 |
|
| 149 |
$text_wrap_switch = WPDA::get_option( WPDA::OPTION_BE_TEXT_WRAP_SWITCH ); |
| 150 |
$text_wrap = WPDA::get_option( WPDA::OPTION_BE_TEXT_WRAP ); |
| 151 |
|
| 152 |
$hide_button_icons = WPDA::get_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS ); |
| 153 |
?> |
| 154 |
|
| 155 |
<form id="wpda_settings_backend" method="post" |
| 156 |
action="?page=<?php echo esc_attr( $this->page ); ?>&tab=legacy&vtab=backend"> |
| 157 |
<table class="wpda-table-settings"> |
| 158 |
<tr style="border-top: 1px solid #ccc"> |
| 159 |
<th><?php esc_html_e( 'Row access', 'wp-data-access' ); ?></th> |
| 160 |
<td> |
| 161 |
<label> |
| 162 |
<input |
| 163 |
type="checkbox" |
| 164 |
name="view_link" |
| 165 |
<?php echo 'on' === $view_link ? 'checked' : ''; ?> |
| 166 |
><?php esc_html_e( 'Add view link to list table', 'wp-data-access' ); ?> |
| 167 |
</label> |
| 168 |
</td> |
| 169 |
</tr> |
| 170 |
<tr> |
| 171 |
<th scope="row"><?php esc_html_e( 'Allow transactions?', 'wp-data-access' ); ?></th> |
| 172 |
<td> |
| 173 |
<label> |
| 174 |
<input type="checkbox" name="allow_insert" |
| 175 |
<?php echo 'on' === $allow_insert ? 'checked' : ''; ?> /><?php esc_html_e( 'Allow insert', 'wp-data-access' ); ?> |
| 176 |
</label> |
| 177 |
<br/> |
| 178 |
<label> |
| 179 |
<input type="checkbox" name="allow_update" |
| 180 |
<?php echo 'on' === $allow_update ? 'checked' : ''; ?> /><?php esc_html_e( 'Allow update', 'wp-data-access' ); ?> |
| 181 |
</label> |
| 182 |
<br/> |
| 183 |
<label> |
| 184 |
<input type="checkbox" name="allow_delete" |
| 185 |
<?php echo 'on' === $allow_delete ? 'checked' : ''; ?> /><?php esc_html_e( 'Allow delete', 'wp-data-access' ); ?> |
| 186 |
</label> |
| 187 |
</td> |
| 188 |
</tr> |
| 189 |
<tr> |
| 190 |
<th scope="row"><?php esc_html_e( 'Allow exports?', 'wp-data-access' ); ?></th> |
| 191 |
<td> |
| 192 |
<label> |
| 193 |
<input type="checkbox" name="export_rows" |
| 194 |
<?php echo 'on' === $export_rows ? 'checked' : ''; ?> /><?php esc_html_e( 'Allow row export', 'wp-data-access' ); ?> |
| 195 |
</label> |
| 196 |
<br/> |
| 197 |
<label> |
| 198 |
<input type="checkbox" name="export_variable_rows" |
| 199 |
<?php echo 'on' === $export_variable_rows ? 'checked' : ''; ?> /><?php esc_html_e( 'Export with variable WP prefix', 'wp-data-access' ); ?> |
| 200 |
</label> |
| 201 |
</td> |
| 202 |
</tr> |
| 203 |
<tr> |
| 204 |
<th scope="row"><?php esc_html_e( 'Allow imports?', 'wp-data-access' ); ?></th> |
| 205 |
<td> |
| 206 |
<label> |
| 207 |
<input type="checkbox" name="allow_imports" |
| 208 |
<?php echo 'on' === $allow_imports ? 'checked' : ''; ?> /><?php esc_html_e( 'Allow to import scripts from Data Explorer table pages', 'wp-data-access' ); ?> |
| 209 |
</label> |
| 210 |
</td> |
| 211 |
</tr> |
| 212 |
<tr> |
| 213 |
<th><?php esc_html_e( 'Ask for confirmation?', 'wp-data-access' ); ?></th> |
| 214 |
<td> |
| 215 |
<label> |
| 216 |
<input type="checkbox" name="confirm_export" |
| 217 |
<?php echo 'on' === $confirm_export ? 'checked' : ''; ?> /><?php esc_html_e( 'When starting export', 'wp-data-access' ); ?> |
| 218 |
</label> |
| 219 |
<br/> |
| 220 |
<label> |
| 221 |
<input type="checkbox" name="confirm_view" |
| 222 |
<?php echo 'on' === $confirm_view ? 'checked' : ''; ?> /><?php esc_html_e( 'When viewing non WPDA table', 'wp-data-access' ); ?> |
| 223 |
</label> |
| 224 |
</td> |
| 225 |
</tr> |
| 226 |
<tr> |
| 227 |
<th><?php esc_html_e( 'Default pagination value', 'wp-data-access' ); ?></th> |
| 228 |
<td> |
| 229 |
<input |
| 230 |
type="number" step="1" min="1" max="999" name="pagination" maxlength="3" |
| 231 |
value="<?php echo esc_attr( $pagination ); ?>"> |
| 232 |
</td> |
| 233 |
</tr> |
| 234 |
<tr> |
| 235 |
<th><?php esc_html_e( 'Search box', 'wp-data-access' ); ?></th> |
| 236 |
<td> |
| 237 |
<label> |
| 238 |
<input |
| 239 |
type="checkbox" |
| 240 |
name="remember_search" <?php echo 'on' === $remember_search ? 'checked' : ''; ?> |
| 241 |
><?php esc_html_e( 'Remember last search', 'wp-data-access' ); ?> |
| 242 |
</label> |
| 243 |
</td> |
| 244 |
</tr> |
| 245 |
<tr> |
| 246 |
<th><?php esc_html_e( 'Max row count', 'wp-data-access' ); ?></th> |
| 247 |
<td> |
| 248 |
<input |
| 249 |
type="number" step="1" min="1" max="999999" name="innodb_count" maxlength="3" |
| 250 |
value="<?php echo esc_attr( $innodb_count ); ?>"> |
| 251 |
<p> |
| 252 |
<strong>This works for InnoDB tables and views only!</strong> |
| 253 |
</p> |
| 254 |
<p> |
| 255 |
The real row count is shown for other table types. |
| 256 |
</p> |
| 257 |
<p> |
| 258 |
<strong>BEHAVIOUR</strong><br/> |
| 259 |
IF estimated row count > max row count:<br/> |
| 260 |
use estimated row count<br/> |
| 261 |
ELSE<br/> |
| 262 |
user real row count |
| 263 |
</p> |
| 264 |
<p> |
| 265 |
Showing the estimated row count instead of the real row count <strong>improves performance</strong> |
| 266 |
for <strong>large tables and views</strong>. |
| 267 |
An estimated row count is <strong>less accurate</strong> than a real row count. |
| 268 |
</p> |
| 269 |
<p> |
| 270 |
This option can be changed for InnoDB tables and views in the Data Explorer:<br/> |
| 271 |
WP Data Access > Data Explorer > YOUR TABLE > Manage > Settings > Table Settings > Row count |
| 272 |
</p> |
| 273 |
</td> |
| 274 |
</tr> |
| 275 |
<tr> |
| 276 |
<th><?php esc_html_e( 'Default designer mode', 'wp-data-access' ); ?></th> |
| 277 |
<td> |
| 278 |
<select name="design_mode"> |
| 279 |
<option value="basic" <?php echo 'basic' === $design_mode ? 'selected' : ''; ?>>Basic |
| 280 |
</option> |
| 281 |
<option value="advanced" <?php echo 'advanced' === $design_mode ? 'selected' : ''; ?>> |
| 282 |
Advanced |
| 283 |
</option> |
| 284 |
</select> |
| 285 |
</td> |
| 286 |
</tr> |
| 287 |
<tr> |
| 288 |
<th><?php esc_html_e( 'Content wrap', 'wp-data-access' ); ?></th> |
| 289 |
<td> |
| 290 |
<label> |
| 291 |
<input |
| 292 |
type="checkbox" |
| 293 |
name="text_wrap_switch" <?php echo 'on' === $text_wrap_switch ? 'checked' : ''; ?> |
| 294 |
><?php esc_html_e( 'No content wrap', 'wp-data-access' ); ?> |
| 295 |
</label> |
| 296 |
<br/> |
| 297 |
<input |
| 298 |
type="number" step="1" min="1" max="999999" name="text_wrap" maxlength="3" |
| 299 |
value="<?php echo esc_attr( $text_wrap ); ?>"> |
| 300 |
</td> |
| 301 |
</tr> |
| 302 |
<tr> |
| 303 |
<th><?php esc_html_e( 'Hide button icons', 'wp-data-access' ); ?></th> |
| 304 |
<td> |
| 305 |
<label> |
| 306 |
<input |
| 307 |
type="checkbox" |
| 308 |
name="hide_button_icons" <?php echo 'on' === $hide_button_icons ? 'checked' : ''; ?> |
| 309 |
><?php esc_html_e( 'Hide icons on admin buttons', 'wp-data-access' ); ?> |
| 310 |
</label> |
| 311 |
</td> |
| 312 |
</tr> |
| 313 |
</table> |
| 314 |
<div class="wpda-table-settings-button"> |
| 315 |
<input type="hidden" name="action" value="save"/> |
| 316 |
<button type="submit" class="button button-primary"> |
| 317 |
<i class="fas fa-check wpda_icon_on_button"></i> |
| 318 |
<?php esc_html_e( 'Save Back-end Settings', 'wp-data-access' ); ?> |
| 319 |
</button> |
| 320 |
<a href="javascript:void(0)" |
| 321 |
onclick="if (confirm('<?php esc_html_e( 'Reset to defaults?', 'wp-data-access' ); ?>')) { |
| 322 |
jQuery('input[name="action"]').val('setdefaults'); |
| 323 |
jQuery('#wpda_settings_backend').trigger('submit') |
| 324 |
}" |
| 325 |
class="button"> |
| 326 |
<i class="fas fa-times-circle wpda_icon_on_button"></i> |
| 327 |
<?php esc_html_e( 'Reset Back-end Settings To Defaults', 'wp-data-access' ); ?> |
| 328 |
</a> |
| 329 |
</div> |
| 330 |
<?php wp_nonce_field( 'wpda-back-end-settings', '_wpnonce', false ); ?> |
| 331 |
</form> |
| 332 |
|
| 333 |
<?php |
| 334 |
|
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
} |
| 339 |
|
| 340 |
} |