← All changes
|
WPDataAccess/Utilities/WPDA_Export_Formatted.php
+19
-11
5.5.35
→
5.5.85
View file →
| @@ -127,9 +127,9 @@ | ||
| 127 | 127 | $current_memory_limit = @ini_get( 'memory_limit' ); |
| 128 | 128 | if ( false === $current_memory_limit || |
| 129 | 129 | WPDA::convert_memory_to_decimal( $current_memory_limit ) < WPDA::convert_memory_to_decimal( $wp_memory_limit ) |
| 130 | 130 | ) { |
| 131 | - @ini_set( 'memory_limit', $wp_memory_limit ); | |
| 131 | + @ini_set( 'memory_limit', $wp_memory_limit ); // phpcs:ignore | |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| @@ -138,8 +138,12 @@ | ||
| 138 | 138 | * |
| 139 | 139 | * @since 2.0.13 |
| 140 | 140 | */ |
| 141 | 141 | public function export() { |
| 142 | + if (!WPDA::current_user_is_admin()) { | |
| 143 | + return; | |
| 144 | + } | |
| 145 | + | |
| 142 | 146 | $this->table_names = isset( $_REQUEST['table_names'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['table_names'] ) ) : ''; // input var okay. |
| 143 | 147 | $this->pid = isset( $_REQUEST['pid'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['pid'] ) ) : ''; // input var okay. |
| 144 | 148 | if ( '' !== $this->table_names ) { |
| 145 | 149 | $wp_action = 'wpda-export-' . json_encode( $this->table_names ); |
| @@ -201,9 +205,9 @@ | ||
| 201 | 205 | |
| 202 | 206 | if ( isset( $this->table_primary_key[0] ) && isset( $_REQUEST[ $this->table_primary_key[0] ] ) ) { |
| 203 | 207 | // Build where clause. |
| 204 | 208 | global $wpdb; |
| 205 | - $count_pk = count( $_REQUEST[ $this->table_primary_key[0] ] );//phpcs:ignore - 8.1 proof | |
| 209 | + $count_pk = count( $_REQUEST[ $this->table_primary_key[0] ] ); // phpcs:ignore -- 8.1 proof | |
| 206 | 210 | for ( $i = 0; $i < $count_pk; $i ++ ) { |
| 207 | 211 | $and = ''; |
| 208 | 212 | foreach ( $this->table_primary_key as $key ) { |
| 209 | 213 | $and .= '' === $and ? '(' : ' and '; |
| @@ -211,19 +215,19 @@ | ||
| 211 | 215 | $and .= $wpdb->prepare( |
| 212 | 216 | '`%1s` = %d', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders |
| 213 | 217 | array( |
| 214 | 218 | WPDA::remove_backticks( $key ), |
| 215 | - sanitize_text_field( wp_unslash( $_REQUEST[ $key ][ $i ] ) ) | |
| 219 | + sanitize_text_field( wp_unslash( $_REQUEST[ $key ][ $i ] ) ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 216 | 220 | ) |
| 217 | - ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 221 | + ); | |
| 218 | 222 | } else { |
| 219 | 223 | $and .= $wpdb->prepare( |
| 220 | 224 | '`%1s` = %s', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders |
| 221 | 225 | array( |
| 222 | 226 | WPDA::remove_backticks( $key ), |
| 223 | - sanitize_text_field( wp_unslash( $_REQUEST[ $key ][ $i ] ) ) | |
| 227 | + sanitize_text_field( wp_unslash( $_REQUEST[ $key ][ $i ] ) ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 224 | 228 | ) |
| 225 | - ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 229 | + ); | |
| 226 | 230 | } |
| 227 | 231 | } |
| 228 | 232 | |
| 229 | 233 | $and .= '' === $and ? '' : ')'; |
| @@ -247,9 +251,11 @@ | ||
| 247 | 251 | $query_buffer_size = 0; |
| 248 | 252 | } |
| 249 | 253 | |
| 250 | 254 | if ( is_numeric( $query_buffer_size ) && $query_buffer_size > 0 ) { |
| 255 | + // phpcs:disable Squiz.PHP.DiscouragedFunctions.Discouraged | |
| 251 | 256 | set_time_limit(0); |
| 257 | + // phpcs:enable Squiz.PHP.DiscouragedFunctions.Discouraged | |
| 252 | 258 | $this->send_export_file_large( $query_buffer_size ); |
| 253 | 259 | } else { |
| 254 | 260 | $this->send_export_file(); |
| 255 | 261 | } |
| @@ -263,11 +269,13 @@ | ||
| 263 | 269 | protected function prepare_sql() { |
| 264 | 270 | $this->wpdadb = WPDADB::get_db_connection( $this->schema_name ); |
| 265 | 271 | if ( null === $this->wpdadb ) { |
| 266 | 272 | if ( is_admin() ) { |
| 267 | - wp_die( sprintf( __( 'ERROR - Remote database %s not available', 'wp-data-access' ), esc_attr( $this->schema_name ) ) ); | |
| 273 | + /* translators: %s = database name */ | |
| 274 | + wp_die( sprintf( esc_attr__( 'ERROR - Remote database %s not available', 'wp-data-access' ), esc_attr( $this->schema_name ) ) ); | |
| 268 | 275 | } else { |
| 269 | - die( sprintf( __( 'ERROR - Remote database %s not available', 'wp-data-access' ), esc_attr( $this->schema_name ) ) ); | |
| 276 | + /* translators: %s = database name */ | |
| 277 | + die( sprintf( esc_attr__( 'ERROR - Remote database %s not available', 'wp-data-access' ), esc_attr( $this->schema_name ) ) ); | |
| 270 | 278 | } |
| 271 | 279 | } |
| 272 | 280 | |
| 273 | 281 | if ( '' === $this->schema_name ) { |
| @@ -280,9 +288,9 @@ | ||
| 280 | 288 | protected function send_export_file_large( $query_buffer_size ) { |
| 281 | 289 | $i = 0; |
| 282 | 290 | $sql = $this->statement . ' limit ' . $query_buffer_size; |
| 283 | 291 | |
| 284 | - $this->rows = $this->wpdadb->get_results( $sql, 'ARRAY_A' ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 292 | + $this->rows = $this->wpdadb->get_results( $sql, 'ARRAY_A' ); | |
| 285 | 293 | $this->row_count = $this->wpdadb->num_rows; |
| 286 | 294 | |
| 287 | 295 | $this->header(); |
| 288 | 296 | |
| @@ -293,9 +301,9 @@ | ||
| 293 | 301 | |
| 294 | 302 | $i++; |
| 295 | 303 | |
| 296 | 304 | $sql = $this->statement . ' limit ' . $query_buffer_size . ' offset ' . ($i*$query_buffer_size); |
| 297 | - $this->rows = $this->wpdadb->get_results( $sql, 'ARRAY_A' ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 305 | + $this->rows = $this->wpdadb->get_results( $sql, 'ARRAY_A' ); | |
| 298 | 306 | $this->row_count += $this->wpdadb->num_rows; |
| 299 | 307 | } |
| 300 | 308 | |
| 301 | 309 | $this->footer(); |
| @@ -310,9 +318,9 @@ | ||
| 310 | 318 | * |
| 311 | 319 | * @since 2.0.13 |
| 312 | 320 | */ |
| 313 | 321 | protected function send_export_file() { |
| 314 | - $this->rows = $this->wpdadb->get_results( $this->statement, 'ARRAY_A' ); // phpcs:ignore Standard.Category.SniffName.ErrorCode | |
| 322 | + $this->rows = $this->wpdadb->get_results( $this->statement, 'ARRAY_A' ); | |
| 315 | 323 | $this->row_count = $this->wpdadb->num_rows; |
| 316 | 324 | |
| 317 | 325 | $this->header(); |
| 318 | 326 | foreach ( $this->rows as $row ) { |