@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | 'search' => null, |
54 | 54 | ); |
55 | 55 | $attrs = shortcode_atts( $defaults, $raw_attrs ); |
56 | - if ( ! isset( $attrs['table'] ) ) { |
|
56 | + if ( ! isset( $attrs[ 'table' ] ) ) { |
|
57 | 57 | $msg = "The 'table' attribute must be set. Attributes found: ["; |
58 | 58 | foreach ( $raw_attrs as $k => $v ) { |
59 | 59 | $msg .= ' ' . htmlentities2( $k ) . ' = "' . htmlentities2( $v ) . '" '; |
@@ -61,19 +61,19 @@ discard block |
||
61 | 61 | $msg .= "]"; |
62 | 62 | return $this->error( $msg ); |
63 | 63 | } |
64 | - $table = $this->db->get_table( $attrs['table'] ); |
|
64 | + $table = $this->db->get_table( $attrs[ 'table' ] ); |
|
65 | 65 | if ( ! $table ) { |
66 | 66 | if ( ! is_user_logged_in() ) { |
67 | 67 | return $this->error( "You are not logged in. " . wp_loginout( get_the_permalink(), false ) ); |
68 | 68 | } |
69 | 69 | return $this->error(); |
70 | 70 | } |
71 | - $format_method = $attrs['format'] . '_format'; |
|
71 | + $format_method = $attrs[ 'format' ] . '_format'; |
|
72 | 72 | if ( is_callable( array( $this, $format_method ) ) ) { |
73 | 73 | wp_enqueue_script( 'tabulate-scripts' ); |
74 | 74 | return $this->$format_method( $table, $attrs, $_REQUEST ); |
75 | 75 | } else { |
76 | - return $this->error( "Format '{$attrs['format']}' not available." ); |
|
76 | + return $this->error( "Format '{$attrs[ 'format' ]}' not available." ); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function record_format( Table $table, $attrs, $query = null ) { |
105 | 105 | // Check for the ident shortcode parameter... |
106 | - if ( isset( $attrs['ident'] ) ) { |
|
107 | - $ident = $attrs['ident']; |
|
106 | + if ( isset( $attrs[ 'ident' ] ) ) { |
|
107 | + $ident = $attrs[ 'ident' ]; |
|
108 | 108 | } |
109 | 109 | // ...or the tablename=ident URL parameter. |
110 | 110 | if ( isset( $query[ $table->get_name() ] ) && is_scalar( $query[ $table->get_name() ] ) ) { |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $template = new Template( 'record/shortcode.html' ); |
140 | 140 | $template->table = $table; |
141 | 141 | $template->record = $table->get_default_record(); |
142 | - $template->return_to = ( isset( $attrs['return_to'] ) ) ? $attrs['return_to'] : get_the_permalink(); |
|
142 | + $template->return_to = ( isset( $attrs[ 'return_to' ] ) ) ? $attrs[ 'return_to' ] : get_the_permalink(); |
|
143 | 143 | return $template->render(); |
144 | 144 | } |
145 | 145 | |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | protected function list_format( Table $table, $attrs ) { |
165 | 165 | $titles = array(); |
166 | 166 | foreach ( $table->get_records() as $rec ) { |
167 | - $titles[] = $rec->get_title(); |
|
167 | + $titles[ ] = $rec->get_title(); |
|
168 | 168 | } |
169 | - $glue = ( ! empty( $attrs['glue'] ) ) ? $attrs['glue'] : ', '; |
|
169 | + $glue = ( ! empty( $attrs[ 'glue' ] ) ) ? $attrs[ 'glue' ] : ', '; |
|
170 | 170 | return '<span class="tabulate list-format">' . join( $glue, $titles ) . '</span>'; |
171 | 171 | } |
172 | 172 | |
@@ -181,19 +181,19 @@ discard block |
||
181 | 181 | protected function table_format( Table $table, $attrs, $query = null ) { |
182 | 182 | // Filters. |
183 | 183 | // Apply filters from the URL query parameters. |
184 | - if ( isset( $query['table'] ) && $query['table'] === $table->get_name() ) { |
|
185 | - $query_filters = (isset( $query['filter'] )) ? $query['filter'] : array(); |
|
184 | + if ( isset( $query[ 'table' ] ) && $query[ 'table' ] === $table->get_name() ) { |
|
185 | + $query_filters = ( isset( $query[ 'filter' ] ) ) ? $query[ 'filter' ] : array(); |
|
186 | 186 | $table->add_filters( $query_filters ); |
187 | 187 | } |
188 | 188 | |
189 | 189 | // Pagination. |
190 | 190 | $page_num = 1; |
191 | - if ( isset( $query['tabulate_p'] ) && is_numeric( $query['tabulate_p'] ) ) { |
|
192 | - $page_num = abs( $query['tabulate_p'] ); |
|
191 | + if ( isset( $query[ 'tabulate_p' ] ) && is_numeric( $query[ 'tabulate_p' ] ) ) { |
|
192 | + $page_num = abs( $query[ 'tabulate_p' ] ); |
|
193 | 193 | } |
194 | 194 | $table->set_current_page_num( $page_num ); |
195 | - if ( isset( $query['tabulate_psize'] ) ) { |
|
196 | - $table->set_records_per_page( $query['tabulate_psize'] ); |
|
195 | + if ( isset( $query[ 'tabulate_psize' ] ) ) { |
|
196 | + $table->set_records_per_page( $query[ 'tabulate_psize' ] ); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | // Construct the HTML. |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | $template->records = $table->get_records(); |
204 | 204 | |
205 | 205 | // Add the search form if required. |
206 | - $template->search = ! empty( $attrs['search'] ); |
|
206 | + $template->search = ! empty( $attrs[ 'search' ] ); |
|
207 | 207 | $template->form_action = get_the_permalink(); |
208 | 208 | |
209 | 209 | // Return completed HTML output. |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | self::ANON_ROLE => 'Anonymous User', |
68 | 68 | ); |
69 | 69 | foreach ( wp_roles()->roles as $role_name => $role ) { |
70 | - $roles[ $role_name ] = $role['name']; |
|
70 | + $roles[ $role_name ] = $role[ 'name' ]; |
|
71 | 71 | } |
72 | 72 | return $roles; |
73 | 73 | } |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | $cap = substr( $cap_full_name, strlen( TABULATE_SLUG ) + 1 ); |
123 | 123 | |
124 | 124 | // Set up basic data. |
125 | - $table_name = ( $args[2] ) ? $args[2] : false; |
|
125 | + $table_name = ( $args[ 2 ] ) ? $args[ 2 ] : false; |
|
126 | 126 | $grants = new self(); |
127 | 127 | |
128 | 128 | // Users with 'promote_users' capability can do everything. |
129 | - if ( isset( $all_capabilities['promote_users'] ) ) { |
|
129 | + if ( isset( $all_capabilities[ 'promote_users' ] ) ) { |
|
130 | 130 | $all_capabilities[ $cap_full_name ] = true; |
131 | 131 | } |
132 | 132 |
@@ -81,15 +81,15 @@ discard block |
||
81 | 81 | * @throws \Exception On upload error or if the file isn't a CSV. |
82 | 82 | */ |
83 | 83 | private function save_file( $uploaded ) { |
84 | - if ( isset( $uploaded['error'] ) ) { |
|
85 | - throw new \Exception( $uploaded['error'] ); |
|
84 | + if ( isset( $uploaded[ 'error' ] ) ) { |
|
85 | + throw new \Exception( $uploaded[ 'error' ] ); |
|
86 | 86 | } |
87 | - if ( 'text/csv' !== $uploaded['type'] ) { |
|
88 | - unlink( $uploaded['file'] ); |
|
87 | + if ( 'text/csv' !== $uploaded[ 'type' ] ) { |
|
88 | + unlink( $uploaded[ 'file' ] ); |
|
89 | 89 | throw new \Exception( 'Only CSV files can be imported.' ); |
90 | 90 | } |
91 | 91 | $this->hash = uniqid( TABULATE_SLUG ); |
92 | - rename( $uploaded['file'], get_temp_dir() . '/' . $this->hash ); |
|
92 | + rename( $uploaded[ 'file' ], get_temp_dir() . '/' . $this->hash ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | $this->data = array(); |
113 | 113 | $lines = $this->filesystem->get_contents_array( $file_path ); |
114 | 114 | foreach ( $lines as $line ) { |
115 | - $this->data[] = str_getcsv( $line ); |
|
115 | + $this->data[ ] = str_getcsv( $line ); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Extract headers. |
119 | - $this->headers = $this->data[0]; |
|
120 | - unset( $this->data[0] ); |
|
119 | + $this->headers = $this->data[ 0 ]; |
|
120 | + unset( $this->data[ 0 ] ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -196,36 +196,36 @@ discard block |
||
196 | 196 | $column = $table->get_column( $db_column_name ); |
197 | 197 | // Required, is not an update, has no default, and is empty. |
198 | 198 | if ( $column->is_required() && ! $pk_set && ! $column->get_default() && empty( $value ) ) { |
199 | - $col_errors[] = 'Required but empty'; |
|
199 | + $col_errors[ ] = 'Required but empty'; |
|
200 | 200 | } |
201 | 201 | // Already exists, and is not an update. |
202 | 202 | if ( $column->is_unique() && ! $pk_set && $this->value_exists( $table, $column, $value ) ) { |
203 | - $col_errors[] = "Unique value already present: '$value'"; |
|
203 | + $col_errors[ ] = "Unique value already present: '$value'"; |
|
204 | 204 | } |
205 | 205 | // Too long (if the column has a size and the value is greater than this). |
206 | 206 | if ( ! $column->is_foreign_key() && ! $column->is_boolean() |
207 | 207 | && $column->get_size() > 0 |
208 | 208 | && strlen( $value ) > $column->get_size() ) { |
209 | - $col_errors[] = 'Value (' . $value . ') too long (maximum length of ' . $column->get_size() . ')'; |
|
209 | + $col_errors[ ] = 'Value (' . $value . ') too long (maximum length of ' . $column->get_size() . ')'; |
|
210 | 210 | } |
211 | 211 | // Invalid foreign key value. |
212 | 212 | if ( ! empty( $value ) && $column->is_foreign_key() ) { |
213 | 213 | $err = $this->validate_foreign_key( $column, $value ); |
214 | 214 | if ( $err ) { |
215 | - $col_errors[] = $err; |
|
215 | + $col_errors[ ] = $err; |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | // Dates. |
219 | 219 | if ( 'date' === $column->get_type() && ! empty( $value ) && 1 !== preg_match( '/\d{4}-\d{2}-\d{2}/', $value ) ) { |
220 | - $col_errors[] = 'Value (' . $value . ') not in date format'; |
|
220 | + $col_errors[ ] = 'Value (' . $value . ') not in date format'; |
|
221 | 221 | } |
222 | 222 | if ( 'year' === $column->get_type() && ! empty( $value ) && ( $value < 1901 || $value > 2155 ) ) { |
223 | - $col_errors[] = 'Year values must be between 1901 and 2155 (' . $value . ' given)'; |
|
223 | + $col_errors[ ] = 'Year values must be between 1901 and 2155 (' . $value . ' given)'; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | if ( count( $col_errors ) > 0 ) { |
227 | 227 | // Construct error details array. |
228 | - $errors[] = array( |
|
228 | + $errors[ ] = array( |
|
229 | 229 | 'column_name' => $this->headers[ $col_num ], |
230 | 230 | 'column_number' => $col_num, |
231 | 231 | 'field_name' => $column->get_name(), |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param string|boolean $download_name The name of the file, for the user to download. |
64 | 64 | */ |
65 | 65 | protected function send_file( $ext, $mime, $content, $download_name = false ) { |
66 | - $download_name = ($download_name ?: date( 'Y-m-d' ) ) . '.' . $ext; |
|
66 | + $download_name = ( $download_name ?: date( 'Y-m-d' ) ) . '.' . $ext; |
|
67 | 67 | header( 'Content-Encoding: UTF-8' ); |
68 | 68 | header( 'Content-type: ' . $mime . '; charset=UTF-8' ); |
69 | 69 | header( 'Content-Disposition: attachment; filename="' . $download_name . '"' ); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param string $action The action name. |
78 | 78 | */ |
79 | 79 | public function verify_nonce( $action ) { |
80 | - $nonce = wp_verify_nonce( $_REQUEST['_wpnonce'], $action ); |
|
80 | + $nonce = wp_verify_nonce( $_REQUEST[ '_wpnonce' ], $action ); |
|
81 | 81 | if ( ! $nonce ) { |
82 | 82 | wp_die(); |
83 | 83 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | } |
208 | 208 | // Validate the value. |
209 | 209 | $empty_value_allowed = ( strpos( $operator, 'empty' ) === false && ! empty( $value ) ); |
210 | - $valid_value = (strpos( $operator, 'empty' ) !== false) || $empty_value_allowed; |
|
210 | + $valid_value = ( strpos( $operator, 'empty' ) !== false ) || $empty_value_allowed; |
|
211 | 211 | if ( ! $valid_operator ) { |
212 | 212 | // translators: Error message shown when a filter is passed an invalid value. |
213 | 213 | $msg = __( '"%s" is not a valid value.', 'tabulate' ); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | } |
216 | 216 | // Save the filter for later application (see Table::apply_filters()). |
217 | 217 | if ( $valid_columm && $valid_operator && $valid_value ) { |
218 | - $this->filters[] = array( |
|
218 | + $this->filters[ ] = array( |
|
219 | 219 | 'column' => $column, |
220 | 220 | 'operator' => $operator, |
221 | 221 | 'value' => $value, |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public function add_filters( $filters ) { |
233 | 233 | foreach ( $filters as $filter ) { |
234 | - $column = (isset( $filter['column'] )) ? $filter['column'] : false; |
|
235 | - $operator = (isset( $filter['operator'] )) ? $filter['operator'] : false; |
|
236 | - $value = (isset( $filter['value'] )) ? $filter['value'] : false; |
|
234 | + $column = ( isset( $filter[ 'column' ] ) ) ? $filter[ 'column' ] : false; |
|
235 | + $operator = ( isset( $filter[ 'operator' ] ) ) ? $filter[ 'operator' ] : false; |
|
236 | + $value = ( isset( $filter[ 'value' ] ) ) ? $filter[ 'value' ] : false; |
|
237 | 237 | $this->add_filter( $column, $operator, $value ); |
238 | 238 | } |
239 | 239 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | // Add an empty default filter to start with. |
251 | 251 | $title_col = $this->get_title_column(); |
252 | 252 | $first_filter = ( $title_col ) ? $title_col->get_name() : ''; |
253 | - $out[] = array( |
|
253 | + $out[ ] = array( |
|
254 | 254 | 'column' => $first_filter, |
255 | 255 | 'operator' => 'like', |
256 | 256 | 'value' => '', |
@@ -286,49 +286,49 @@ discard block |
||
286 | 286 | $where_clause = ''; |
287 | 287 | $join_clause = ''; |
288 | 288 | foreach ( $this->filters as $filter_idx => $filter ) { |
289 | - $f_column = $filter['column']; |
|
290 | - $param_name = $filter['column'] . $param_num; |
|
289 | + $f_column = $filter[ 'column' ]; |
|
290 | + $param_name = $filter[ 'column' ] . $param_num; |
|
291 | 291 | |
292 | 292 | // Filters on foreign keys need to work on the FKs title column. |
293 | 293 | $column = $this->columns[ $f_column ]; |
294 | - if ( $column->is_foreign_key() && ! $filter['force'] ) { |
|
294 | + if ( $column->is_foreign_key() && ! $filter[ 'force' ] ) { |
|
295 | 295 | $join = $this->join_on( $column ); |
296 | - $f_column = $join['column_alias']; |
|
297 | - $join_clause .= $join['join_clause']; |
|
296 | + $f_column = $join[ 'column_alias' ]; |
|
297 | + $join_clause .= $join[ 'join_clause' ]; |
|
298 | 298 | } else { |
299 | 299 | // The result of join_on() above is quoted, so this must also be. |
300 | 300 | $f_column = "`" . $this->get_name() . "`.`$f_column`"; |
301 | 301 | } |
302 | 302 | |
303 | - if ( 'like' === $filter['operator'] || 'not like' === $filter['operator'] ) { |
|
303 | + if ( 'like' === $filter[ 'operator' ] || 'not like' === $filter[ 'operator' ] ) { |
|
304 | 304 | // LIKE or NOT LIKE. |
305 | - $where_clause .= " AND CONVERT($f_column, CHAR) " . strtoupper( $filter['operator'] ) . " %s "; |
|
306 | - $params[ $param_name ] = '%' . trim( $filter['value'] ) . '%'; |
|
307 | - } elseif ( '=' === $filter['operator'] || '!=' === $filter['operator'] ) { |
|
305 | + $where_clause .= " AND CONVERT($f_column, CHAR) " . strtoupper( $filter[ 'operator' ] ) . " %s "; |
|
306 | + $params[ $param_name ] = '%' . trim( $filter[ 'value' ] ) . '%'; |
|
307 | + } elseif ( '=' === $filter[ 'operator' ] || '!=' === $filter[ 'operator' ] ) { |
|
308 | 308 | // Equals or does-not-equal. |
309 | - $where_clause .= " AND $f_column " . $filter['operator'] . " %s "; |
|
310 | - $params[ $param_name ] = trim( $filter['value'] ); |
|
311 | - } elseif ( 'empty' === $filter['operator'] ) { |
|
309 | + $where_clause .= " AND $f_column " . $filter[ 'operator' ] . " %s "; |
|
310 | + $params[ $param_name ] = trim( $filter[ 'value' ] ); |
|
311 | + } elseif ( 'empty' === $filter[ 'operator' ] ) { |
|
312 | 312 | // IS EMPTY. |
313 | 313 | $where_clause .= " AND ($f_column IS NULL OR $f_column = '')"; |
314 | - } elseif ( 'not empty' === $filter['operator'] ) { |
|
314 | + } elseif ( 'not empty' === $filter[ 'operator' ] ) { |
|
315 | 315 | // IS NOT EMPTY. |
316 | 316 | $where_clause .= " AND ($f_column IS NOT NULL AND $f_column != '')"; |
317 | - } elseif ( 'in' === $filter['operator'] || 'not in' === $filter['operator'] ) { |
|
317 | + } elseif ( 'in' === $filter[ 'operator' ] || 'not in' === $filter[ 'operator' ] ) { |
|
318 | 318 | // IN or NOT IN. |
319 | 319 | $placeholders = array(); |
320 | - foreach ( Util::split_newline( $filter['value'] ) as $vid => $val ) { |
|
321 | - $placeholders[] = "%s"; |
|
320 | + foreach ( Util::split_newline( $filter[ 'value' ] ) as $vid => $val ) { |
|
321 | + $placeholders[ ] = "%s"; |
|
322 | 322 | $params[ $param_name . '_' . $vid ] = $val; |
323 | 323 | // Save the separated filter values for later. |
324 | - $this->filters[ $filter_idx ]['values'][] = $val; |
|
324 | + $this->filters[ $filter_idx ][ 'values' ][ ] = $val; |
|
325 | 325 | } |
326 | - $negate = ( 'not in' === $filter['operator'] ) ? 'NOT' : ''; |
|
326 | + $negate = ( 'not in' === $filter[ 'operator' ] ) ? 'NOT' : ''; |
|
327 | 327 | $where_clause .= " AND ($f_column $negate IN (" . join( ", ", $placeholders ) . "))"; |
328 | 328 | } else { |
329 | 329 | // Other operators. They're already validated in self::addFilter(). |
330 | - $where_clause .= " AND ($f_column " . $filter['operator'] . " %s)"; |
|
331 | - $params[ $param_name ] = trim( $filter['value'] ); |
|
330 | + $where_clause .= " AND ($f_column " . $filter[ 'operator' ] . " %s)"; |
|
331 | + $params[ $param_name ] = trim( $filter[ 'value' ] ); |
|
332 | 332 | } // End if(). |
333 | 333 | |
334 | 334 | $param_num++; |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | $order_by = $this->get_column( $this->get_order_by() ); |
445 | 445 | if ( $order_by ) { |
446 | 446 | $order_by_join = $this->join_on( $order_by ); |
447 | - $sql .= $order_by_join['join_clause'] . ' ORDER BY ' . $order_by_join['column_alias'] . ' ' . $this->get_order_dir(); |
|
447 | + $sql .= $order_by_join[ 'join_clause' ] . ' ORDER BY ' . $order_by_join[ 'column_alias' ] . ' ' . $this->get_order_dir(); |
|
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | $records_per_page = $this->get_records_per_page(); |
456 | 456 | $sql .= ' LIMIT ' . $records_per_page; |
457 | 457 | if ( $this->get_current_page_num() > 1 ) { |
458 | - $sql .= ' OFFSET ' . ($records_per_page * ($this->get_current_page_num() - 1)); |
|
458 | + $sql .= ' OFFSET ' . ( $records_per_page * ( $this->get_current_page_num() - 1 ) ); |
|
459 | 459 | } |
460 | 460 | } |
461 | 461 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | |
468 | 468 | $records = array(); |
469 | 469 | foreach ( $rows as $row ) { |
470 | - $records[] = new Record( $this, $row ); |
|
470 | + $records[ ] = new Record( $this, $row ); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | if ( $save_sql ) { |
@@ -542,9 +542,9 @@ discard block |
||
542 | 542 | $table_name = $this->get_name(); |
543 | 543 | foreach ( $this->get_columns() as $col_name => $col ) { |
544 | 544 | if ( 'point' === $col->get_type() ) { |
545 | - $select[] = "AsText(`$table_name`.`$col_name`) AS `$col_name`"; |
|
545 | + $select[ ] = "AsText(`$table_name`.`$col_name`) AS `$col_name`"; |
|
546 | 546 | } else { |
547 | - $select[] = "`$table_name`.`$col_name`"; |
|
547 | + $select[ ] = "`$table_name`.`$col_name`"; |
|
548 | 548 | } |
549 | 549 | } |
550 | 550 | return join( ', ', $select ); |
@@ -697,17 +697,17 @@ discard block |
||
697 | 697 | foreach ( $this->columns as $col_name => $col ) { |
698 | 698 | if ( $col->is_foreign_key() ) { |
699 | 699 | $col_join = $this->join_on( $col ); |
700 | - $column_name = $col_join['column_alias']; |
|
701 | - $join_clause .= $col_join['join_clause']; |
|
700 | + $column_name = $col_join[ 'column_alias' ]; |
|
701 | + $join_clause .= $col_join[ 'join_clause' ]; |
|
702 | 702 | } elseif ( 'point' === $col->get_type() ) { |
703 | - $columns[] = "IF(`$this->name`.`$col_name` IS NOT NULL, AsText(`$this->name`.`$col_name`), '') AS `$col_name`"; |
|
703 | + $columns[ ] = "IF(`$this->name`.`$col_name` IS NOT NULL, AsText(`$this->name`.`$col_name`), '') AS `$col_name`"; |
|
704 | 704 | } else { |
705 | 705 | $column_name = "`$this->name`.`$col_name`"; |
706 | 706 | } |
707 | 707 | if ( 'point' !== $col->get_type() && isset( $column_name ) ) { |
708 | - $columns[] = "REPLACE(IFNULL($column_name, ''),CONCAT(CHAR(13),CHAR(10)),CHAR(10))"; // 13 = \r and 10 = \n |
|
708 | + $columns[ ] = "REPLACE(IFNULL($column_name, ''),CONCAT(CHAR(13),CHAR(10)),CHAR(10))"; // 13 = \r and 10 = \n |
|
709 | 709 | } |
710 | - $column_headers[] = $col->get_title(); |
|
710 | + $column_headers[ ] = $col->get_title(); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | // Build basic SELECT statement. |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | $sql = $this->get_defining_sql(); |
849 | 849 | $comment_pattern = '/.*\)(?:.*COMMENT[\w=]*\'(.*)\')?/si'; |
850 | 850 | preg_match( $comment_pattern, $sql, $matches ); |
851 | - $this->comment = ( isset( $matches[1] ) ) ? $matches[1] : ''; |
|
851 | + $this->comment = ( isset( $matches[ 1 ] ) ) ? $matches[ 1 ] : ''; |
|
852 | 852 | $this->comment = str_replace( "''", "'", $this->comment ); |
853 | 853 | } |
854 | 854 | if ( empty( $this->comment ) && $this->is_view() ) { |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | $cols = array(); |
867 | 867 | foreach ( $this->get_columns() as $column ) { |
868 | 868 | if ( $column->is_unique() ) { |
869 | - $cols[] = $column; |
|
869 | + $cols[ ] = $column; |
|
870 | 870 | } |
871 | 871 | } |
872 | 872 | return $cols; |
@@ -943,8 +943,8 @@ discard block |
||
943 | 943 | $defining_sql = $this->get_defining_sql(); |
944 | 944 | $fk_pattern = '|FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)`|'; |
945 | 945 | preg_match_all( $fk_pattern, $defining_sql, $matches ); |
946 | - if ( isset( $matches[1] ) && count( $matches[1] ) > 0 ) { |
|
947 | - foreach ( array_combine( $matches[1], $matches[2] ) as $col_name => $tab_name ) { |
|
946 | + if ( isset( $matches[ 1 ] ) && count( $matches[ 1 ] ) > 0 ) { |
|
947 | + foreach ( array_combine( $matches[ 1 ], $matches[ 2 ] ) as $col_name => $tab_name ) { |
|
948 | 948 | $this->referenced_table_names[ $col_name ] = $tab_name; |
949 | 949 | } |
950 | 950 | } |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | $json = new Services_JSON(); |
1049 | 1049 | $metadata = array(); |
1050 | 1050 | foreach ( $this->get_columns() as $column ) { |
1051 | - $metadata[] = array( |
|
1051 | + $metadata[ ] = array( |
|
1052 | 1052 | 'name' => $column->get_name(), |
1053 | 1053 | ); |
1054 | 1054 | } |
@@ -1116,7 +1116,7 @@ discard block |
||
1116 | 1116 | */ |
1117 | 1117 | public function save_record( $data, $pk_value = null ) { |
1118 | 1118 | // Changeset only created here if not already in progress. |
1119 | - $changeset_comment = isset( $data['changeset_comment'] ) ? $data['changeset_comment'] : null; |
|
1119 | + $changeset_comment = isset( $data[ 'changeset_comment' ] ) ? $data[ 'changeset_comment' ] : null; |
|
1120 | 1120 | $change_tracker = new ChangeTracker( $this->get_database()->get_wpdb(), $changeset_comment ); |
1121 | 1121 | |
1122 | 1122 | $columns = $this->get_columns(); |
@@ -1172,7 +1172,7 @@ discard block |
||
1172 | 1172 | |
1173 | 1173 | } elseif ( $column->is_numeric() ) { |
1174 | 1174 | // Numeric values. |
1175 | - $sql_values[ $field ] = (float) $value; |
|
1175 | + $sql_values[ $field ] = ( float ) $value; |
|
1176 | 1176 | |
1177 | 1177 | } else { |
1178 | 1178 | // Everything else. |
@@ -1190,7 +1190,7 @@ discard block |
||
1190 | 1190 | // Can probably be removed when https://core.trac.wordpress.org/ticket/15158 is resolved. |
1191 | 1191 | $set_items = array(); |
1192 | 1192 | foreach ( $sql_values as $field => $escd_datum ) { |
1193 | - $set_items[] = "`$field` = $escd_datum"; |
|
1193 | + $set_items[ ] = "`$field` = $escd_datum"; |
|
1194 | 1194 | } |
1195 | 1195 | $set_clause = 'SET ' . join( ', ', $set_items ); |
1196 | 1196 | |
@@ -1210,7 +1210,7 @@ discard block |
||
1210 | 1210 | $where_clause = $this->database->get_wpdb()->prepare( "WHERE `$pk_name` = %s", $pk_value ); |
1211 | 1211 | $sql = 'UPDATE ' . $this->get_name() . " $set_clause $where_clause"; |
1212 | 1212 | $this->get_database()->query( $sql, null, 'Unable to update a record' ); |
1213 | - $new_pk_value = (isset( $data[ $pk_name ] ) ) ? $data[ $pk_name ] : $pk_value; |
|
1213 | + $new_pk_value = ( isset( $data[ $pk_name ] ) ) ? $data[ $pk_name ] : $pk_value; |
|
1214 | 1214 | |
1215 | 1215 | } else { |
1216 | 1216 | /* |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | /** |
670 | 670 | * Get a count of the number of pages in the currently filtered record set. |
671 | 671 | * |
672 | - * @return integer The page count. |
|
672 | + * @return double The page count. |
|
673 | 673 | */ |
674 | 674 | public function get_page_count() { |
675 | 675 | return ceil( $this->count_records() / $this->get_records_per_page() ); |
@@ -987,7 +987,7 @@ discard block |
||
987 | 987 | /** |
988 | 988 | * Get a list of the names of the foreign keys in this table. |
989 | 989 | * |
990 | - * @return string[] Names of foreign key columns in this table. |
|
990 | + * @return integer[] Names of foreign key columns in this table. |
|
991 | 991 | */ |
992 | 992 | public function get_foreign_key_names() { |
993 | 993 | return array_keys( $this->get_referenced_tables( false ) ); |
@@ -1251,7 +1251,7 @@ discard block |
||
1251 | 1251 | * Get a fully-qualified URL to a Back End page for this table. |
1252 | 1252 | * |
1253 | 1253 | * @param string $action Which action to use ('index', 'import', etc.). |
1254 | - * @param string[]|boolean $extra_params Other query string parameters to add. |
|
1254 | + * @param null|false $extra_params Other query string parameters to add. |
|
1255 | 1255 | * @param string $controller Which controller to use ('table', 'record', etc.). |
1256 | 1256 | * @return string The full URL. |
1257 | 1257 | */ |
@@ -49,28 +49,28 @@ discard block |
||
49 | 49 | * @return string |
50 | 50 | */ |
51 | 51 | public function index( $args ) { |
52 | - $table = $this->get_table( $args['table'] ); |
|
52 | + $table = $this->get_table( $args[ 'table' ] ); |
|
53 | 53 | if ( ! $table instanceof Table ) { |
54 | 54 | return $table; |
55 | 55 | } |
56 | 56 | |
57 | 57 | // Pagination. |
58 | - $page_num = (isset( $args['p'] ) && is_numeric( $args['p'] ) ) ? abs( $args['p'] ) : 1; |
|
58 | + $page_num = ( isset( $args[ 'p' ] ) && is_numeric( $args[ 'p' ] ) ) ? abs( $args[ 'p' ] ) : 1; |
|
59 | 59 | $table->set_current_page_num( $page_num ); |
60 | - if ( isset( $args['psize'] ) ) { |
|
61 | - $table->set_records_per_page( $args['psize'] ); |
|
60 | + if ( isset( $args[ 'psize' ] ) ) { |
|
61 | + $table->set_records_per_page( $args[ 'psize' ] ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | // Ordering. |
65 | - if ( isset( $args['order_by'] ) ) { |
|
66 | - $table->set_order_by( $args['order_by'] ); |
|
65 | + if ( isset( $args[ 'order_by' ] ) ) { |
|
66 | + $table->set_order_by( $args[ 'order_by' ] ); |
|
67 | 67 | } |
68 | - if ( isset( $args['order_dir'] ) ) { |
|
69 | - $table->set_order_dir( $args['order_dir'] ); |
|
68 | + if ( isset( $args[ 'order_dir' ] ) ) { |
|
69 | + $table->set_order_dir( $args[ 'order_dir' ] ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | // Filters. |
73 | - $filter_param = (isset( $args['filter'] )) ? $args['filter'] : array(); |
|
73 | + $filter_param = ( isset( $args[ 'filter' ] ) ) ? $args[ 'filter' ] : array(); |
|
74 | 74 | $table->add_filters( $filter_param ); |
75 | 75 | |
76 | 76 | // Give it all to the template. |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $template->stage = 'choose_file'; |
123 | 123 | |
124 | 124 | // First make sure the user is allowed to import data into this table. |
125 | - $table = $this->get_table( $args['table'] ); |
|
125 | + $table = $this->get_table( $args[ 'table' ] ); |
|
126 | 126 | $template->record = $table->get_default_record(); |
127 | 127 | $template->action = 'import'; |
128 | 128 | $template->table = $table; |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
139 | 139 | $template->form_action = $table->get_url( 'import' ); |
140 | 140 | try { |
141 | - $hash = isset( $_GET['hash'] ) ? $_GET['hash'] : false; |
|
141 | + $hash = isset( $_GET[ 'hash' ] ) ? $_GET[ 'hash' ] : false; |
|
142 | 142 | $uploaded = false; |
143 | - if ( isset( $_FILES['file'] ) ) { |
|
143 | + if ( isset( $_FILES[ 'file' ] ) ) { |
|
144 | 144 | check_admin_referer( 'import-upload' ); |
145 | - $uploaded = wp_handle_upload( $_FILES['file'], array( |
|
145 | + $uploaded = wp_handle_upload( $_FILES[ 'file' ], array( |
|
146 | 146 | 'action' => $template->action, |
147 | 147 | ) ); |
148 | 148 | } |
@@ -157,28 +157,28 @@ discard block |
||
157 | 157 | */ |
158 | 158 | if ( $csv_file->loaded() ) { |
159 | 159 | $template->file = $csv_file; |
160 | - $template->stage = $template->stages[1]; |
|
160 | + $template->stage = $template->stages[ 1 ]; |
|
161 | 161 | $template->form_action .= "&hash=" . $csv_file->hash; |
162 | 162 | } |
163 | 163 | |
164 | 164 | /* |
165 | 165 | * Stage 3 of 4: Previewing. |
166 | 166 | */ |
167 | - if ( $csv_file->loaded() && isset( $_POST['preview'] ) ) { |
|
167 | + if ( $csv_file->loaded() && isset( $_POST[ 'preview' ] ) ) { |
|
168 | 168 | check_admin_referer( 'import-preview' ); |
169 | - $template->stage = $template->stages[2]; |
|
170 | - $template->columns = wp_json_encode( $_POST['columns'] ); |
|
169 | + $template->stage = $template->stages[ 2 ]; |
|
170 | + $template->columns = wp_json_encode( $_POST[ 'columns' ] ); |
|
171 | 171 | $errors = array(); |
172 | 172 | // Make sure all required columns are selected. |
173 | 173 | foreach ( $table->get_columns() as $col ) { |
174 | 174 | // Handle missing columns separately; other column errors are |
175 | 175 | // done in the CSV class. Missing columns don't matter if importing |
176 | 176 | // existing records. |
177 | - $is_missing = empty( $_POST['columns'][ $col->get_name() ] ); |
|
177 | + $is_missing = empty( $_POST[ 'columns' ][ $col->get_name() ] ); |
|
178 | 178 | $pk = $table->get_pk_column(); |
179 | - $pk_present = $pk && isset( $_POST['columns'][ $pk->get_name() ] ); |
|
179 | + $pk_present = $pk && isset( $_POST[ 'columns' ][ $pk->get_name() ] ); |
|
180 | 180 | if ( ! $pk_present && $col->is_required() && $is_missing ) { |
181 | - $errors[] = array( |
|
181 | + $errors[ ] = array( |
|
182 | 182 | 'column_name' => '', |
183 | 183 | 'column_number' => '', |
184 | 184 | 'field_name' => $col->get_name(), |
@@ -187,17 +187,17 @@ discard block |
||
187 | 187 | ); |
188 | 188 | } |
189 | 189 | } |
190 | - $template->errors = empty( $errors ) ? $csv_file->match_fields( $table, wp_unslash( $_POST['columns'] ) ) : $errors; |
|
190 | + $template->errors = empty( $errors ) ? $csv_file->match_fields( $table, wp_unslash( $_POST[ 'columns' ] ) ) : $errors; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /* |
194 | 194 | * Stage 4 of 4: Import. |
195 | 195 | */ |
196 | - if ( $csv_file->loaded() && isset( $_POST['import'] ) ) { |
|
196 | + if ( $csv_file->loaded() && isset( $_POST[ 'import' ] ) ) { |
|
197 | 197 | check_admin_referer( 'import-finish' ); |
198 | - $template->stage = $template->stages[3]; |
|
198 | + $template->stage = $template->stages[ 3 ]; |
|
199 | 199 | $this->wpdb->query( 'BEGIN' ); |
200 | - $column_map = json_decode( wp_unslash( $_POST['columns'] ), true ); |
|
200 | + $column_map = json_decode( wp_unslash( $_POST[ 'columns' ] ), true ); |
|
201 | 201 | $result = $csv_file->import_data( $table, $column_map ); |
202 | 202 | $this->wpdb->query( 'COMMIT' ); |
203 | 203 | $template->add_notice( 'updated', 'Import complete; ' . $result . ' rows imported.' ); |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function calendar( $args ) { |
216 | 216 | // @todo Validate args. |
217 | - $year_num = (isset( $args['year'] )) ? $args['year'] : date( 'Y' ); |
|
218 | - $month_num = (isset( $args['month'] )) ? $args['month'] : date( 'm' ); |
|
217 | + $year_num = ( isset( $args[ 'year' ] ) ) ? $args[ 'year' ] : date( 'Y' ); |
|
218 | + $month_num = ( isset( $args[ 'month' ] ) ) ? $args[ 'month' ] : date( 'm' ); |
|
219 | 219 | |
220 | 220 | $template = new \WordPress\Tabulate\Template( 'calendar.html' ); |
221 | - $table = $this->get_table( $args['table'] ); |
|
221 | + $table = $this->get_table( $args[ 'table' ] ); |
|
222 | 222 | |
223 | 223 | $template->table = $table; |
224 | 224 | $template->action = 'calendar'; |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $records[ $date_val ] = array(); |
242 | 242 | } |
243 | 243 | // Add this record to the day's list. |
244 | - $records[ $date_val ][] = $rec; |
|
244 | + $records[ $date_val ][ ] = $rec; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | // $records is grouped by date, with each item in a single date being |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | */ |
261 | 261 | public function export( $args ) { |
262 | 262 | // Get table. |
263 | - $table = $this->get_table( $args['table'] ); |
|
263 | + $table = $this->get_table( $args[ 'table' ] ); |
|
264 | 264 | |
265 | 265 | // Filter and export. |
266 | - $filter_param = ( isset( $args['filter'] )) ? $args['filter'] : array(); |
|
266 | + $filter_param = ( isset( $args[ 'filter' ] ) ) ? $args[ 'filter' ] : array(); |
|
267 | 267 | $table->add_filters( $filter_param ); |
268 | 268 | $filename = $table->export(); |
269 | 269 | |
@@ -284,11 +284,11 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public function notfound( $args ) { |
286 | 286 | // Get table. |
287 | - $table = $this->get_table( $args['table'] ); |
|
287 | + $table = $this->get_table( $args[ 'table' ] ); |
|
288 | 288 | |
289 | 289 | // Get the values from the request, or give up. |
290 | - $filter_id = isset( $args['notfound'] ) ? $args['notfound'] : false; |
|
291 | - $values_string = isset( $args['filter'][ $filter_id ]['value'] ) ? $args['filter'][ $filter_id ]['value'] : false; |
|
290 | + $filter_id = isset( $args[ 'notfound' ] ) ? $args[ 'notfound' ] : false; |
|
291 | + $values_string = isset( $args[ 'filter' ][ $filter_id ][ 'value' ] ) ? $args[ 'filter' ][ $filter_id ][ 'value' ] : false; |
|
292 | 292 | if ( ! $table instanceof Table || ! $values_string ) { |
293 | 293 | return; |
294 | 294 | } |
@@ -323,12 +323,12 @@ discard block |
||
323 | 323 | * @return string |
324 | 324 | */ |
325 | 325 | public function timeline( $args ) { |
326 | - $table = $this->get_table( $args['table'] ); |
|
326 | + $table = $this->get_table( $args[ 'table' ] ); |
|
327 | 327 | $template = new \WordPress\Tabulate\Template( 'timeline.html' ); |
328 | 328 | $template->action = 'timeline'; |
329 | 329 | $template->table = $table; |
330 | - $start_date_arg = (isset( $args['start_date'] )) ? $args['start_date'] : date( 'Y-m-d' ); |
|
331 | - $end_date_arg = (isset( $args['end_date'] )) ? $args['end_date'] : date( 'Y-m-d' ); |
|
330 | + $start_date_arg = ( isset( $args[ 'start_date' ] ) ) ? $args[ 'start_date' ] : date( 'Y-m-d' ); |
|
331 | + $end_date_arg = ( isset( $args[ 'end_date' ] ) ) ? $args[ 'end_date' ] : date( 'Y-m-d' ); |
|
332 | 332 | $start_date = new \DateTime( $start_date_arg ); |
333 | 333 | $end_date = new \DateTime( $end_date_arg ); |
334 | 334 | if ( $start_date->diff( $end_date, true )->d < 7 ) { |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | if ( ! isset( $data[ $record->get_title() ] ) ) { |
345 | 345 | $data[ $record->get_title() ] = array(); |
346 | 346 | } |
347 | - $data[ $record->get_title() ][] = $record; |
|
347 | + $data[ $record->get_title() ][ ] = $record; |
|
348 | 348 | } |
349 | 349 | $template->data = $data; |
350 | 350 | return $template->render(); |
@@ -11,7 +11,6 @@ |
||
11 | 11 | use WordPress\Tabulate\DB\ChangeTracker; |
12 | 12 | use WordPress\Tabulate\DB\Exception as TabulateException; |
13 | 13 | use WordPress\Tabulate\DB\Reports; |
14 | -use WordPress\Tabulate\DB\Table; |
|
15 | 14 | use WP_Admin_Bar; |
16 | 15 | use WP_Filesystem_Base; |
17 | 16 | use wpdb; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | // Home page (also change the first submenu item's title). |
92 | 92 | add_menu_page( 'Tabulate', 'Tabulate', 'read', TABULATE_SLUG, $dispatch_callback ); |
93 | - $page_title = ( isset( $_GET['table'] ) ) ? Text::titlecase( $_GET['table'] ) : 'Tabulate'; |
|
93 | + $page_title = ( isset( $_GET[ 'table' ] ) ) ? Text::titlecase( $_GET[ 'table' ] ) : 'Tabulate'; |
|
94 | 94 | add_submenu_page( TABULATE_SLUG, $page_title, 'Overview', 'read', TABULATE_SLUG, $dispatch_callback ); |
95 | 95 | |
96 | 96 | // Add submenu pages. |
@@ -147,17 +147,17 @@ discard block |
||
147 | 147 | |
148 | 148 | // Only dispatch when it's our page. |
149 | 149 | $slug_lenth = strlen( TABULATE_SLUG ); |
150 | - if ( ! isset( $request['page'] ) || substr( $request['page'], 0, $slug_lenth ) !== TABULATE_SLUG ) { |
|
150 | + if ( ! isset( $request[ 'page' ] ) || substr( $request[ 'page' ], 0, $slug_lenth ) !== TABULATE_SLUG ) { |
|
151 | 151 | return; |
152 | 152 | } |
153 | 153 | |
154 | 154 | // Discern the controller name, based on an explicit request parameter, or |
155 | 155 | // the trailing part of the page slug (i.e. after 'tabulate_'). |
156 | 156 | $controller_name = 'home'; |
157 | - if ( isset( $request['controller'] ) && strlen( $request['controller'] ) > 0 ) { |
|
158 | - $controller_name = $request['controller']; |
|
159 | - } elseif ( isset( $request['page'] ) && strlen( $request['page'] ) > $slug_lenth ) { |
|
160 | - $controller_name = substr( $request['page'], $slug_lenth + 1 ); |
|
157 | + if ( isset( $request[ 'controller' ] ) && strlen( $request[ 'controller' ] ) > 0 ) { |
|
158 | + $controller_name = $request[ 'controller' ]; |
|
159 | + } elseif ( isset( $request[ 'page' ] ) && strlen( $request[ 'page' ] ) > $slug_lenth ) { |
|
160 | + $controller_name = substr( $request[ 'page' ], $slug_lenth + 1 ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Create the controller and run the action. |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | } |
168 | 168 | $controller = new $controller_classname( $this->wpdb ); |
169 | 169 | $controller->set_filesystem( $this->filesystem ); |
170 | - $action = ! empty( $request['action'] ) ? $request['action'] : 'index'; |
|
171 | - unset( $request['page'], $request['controller'], $request['action'] ); |
|
170 | + $action = ! empty( $request[ 'action' ] ) ? $request[ 'action' ] : 'index'; |
|
171 | + unset( $request[ 'page' ], $request[ 'controller' ], $request[ 'action' ] ); |
|
172 | 172 | try { |
173 | 173 | $this->output = $controller->$action( $request ); |
174 | 174 | } catch ( Exception $e ) { |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $script_url = plugins_url( TABULATE_SLUG ) . '/assets/scripts.js'; |
216 | 216 | $deps = array( 'jquery-ui-autocomplete', 'tabulate-omnivore', 'tabulate-maskedinput', 'tabulate-timepicker' ); |
217 | 217 | if ( Util::is_plugin_active( 'rest-api/plugin.php' ) ) { |
218 | - $deps[] = 'wp-api'; |
|
218 | + $deps[ ] = 'wp-api'; |
|
219 | 219 | } |
220 | 220 | wp_enqueue_script( 'tabulate-scripts', $script_url, $deps, TABULATE_VERSION, true ); |
221 | 221 |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | $db = new Database( $this->wpdb ); |
34 | 34 | $template->action = 'structure'; |
35 | 35 | $template->tables = $db->get_tables(); |
36 | - if ( isset( $args['table'] ) ) { |
|
37 | - $template->table = $db->get_table( $args['table'] ); |
|
36 | + if ( isset( $args[ 'table' ] ) ) { |
|
37 | + $template->table = $db->get_table( $args[ 'table' ] ); |
|
38 | 38 | $template->record = $template->table->get_default_record(); |
39 | 39 | } |
40 | 40 | $template->xtypes = Column::get_xtypes(); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function newtable( $args ) { |
50 | 50 | // Create table. |
51 | 51 | $db = new Database( $this->wpdb ); |
52 | - $table = $db->create_table( $args['new_table_name'] ); |
|
52 | + $table = $db->create_table( $args[ 'new_table_name' ] ); |
|
53 | 53 | |
54 | 54 | // Redirect user with message. |
55 | 55 | $template = new Template( 'table/schema.html' ); |
@@ -65,49 +65,49 @@ discard block |
||
65 | 65 | * @param string[] $args The request arguments. |
66 | 66 | */ |
67 | 67 | public function save( $args ) { |
68 | - if ( ! isset( $args['table'] ) || ! current_user_can( 'promote_users' ) ) { |
|
68 | + if ( ! isset( $args[ 'table' ] ) || ! current_user_can( 'promote_users' ) ) { |
|
69 | 69 | $url = admin_url( 'admin.php?page=tabulate' ); |
70 | 70 | wp_safe_redirect( $url ); |
71 | 71 | exit; |
72 | 72 | } |
73 | 73 | $db = new Database( $this->wpdb ); |
74 | - $table = $db->get_table( $args['table'] ); |
|
75 | - if ( isset( $args['delete'] ) ) { |
|
74 | + $table = $db->get_table( $args[ 'table' ] ); |
|
75 | + if ( isset( $args[ 'delete' ] ) ) { |
|
76 | 76 | wp_safe_redirect( $table->get_url( 'delete', null, 'schema' ) ); |
77 | 77 | exit; |
78 | 78 | } |
79 | 79 | |
80 | 80 | // Rename. |
81 | - $new_name = $args['table']; |
|
82 | - if ( $table instanceof Table && ! empty( $args['new_name'] ) ) { |
|
83 | - $table->rename( $args['new_name'] ); |
|
81 | + $new_name = $args[ 'table' ]; |
|
82 | + if ( $table instanceof Table && ! empty( $args[ 'new_name' ] ) ) { |
|
83 | + $table->rename( $args[ 'new_name' ] ); |
|
84 | 84 | $new_name = $table->get_name(); |
85 | 85 | } |
86 | 86 | |
87 | 87 | // Set comment. |
88 | - if ( isset( $args['new_comment'] ) ) { |
|
89 | - $table->set_comment( $args['new_comment'] ); |
|
88 | + if ( isset( $args[ 'new_comment' ] ) ) { |
|
89 | + $table->set_comment( $args[ 'new_comment' ] ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | // Update columns. |
93 | 93 | $previous_column_name = ''; |
94 | - foreach ( $args['columns'] as $col_info ) { |
|
94 | + foreach ( $args[ 'columns' ] as $col_info ) { |
|
95 | 95 | // Validate inputs. |
96 | - $old_col_name = isset( $col_info['old_name'] ) ? $col_info['old_name'] : null; |
|
97 | - $new_col_name = isset( $col_info['new_name'] ) ? $col_info['new_name'] : null; |
|
98 | - $xtype = isset( $col_info['xtype'] ) ? $col_info['xtype'] : null; |
|
99 | - $size = isset( $col_info['size'] ) ? wp_unslash( $col_info['size'] ) : null; |
|
100 | - $nullable = isset( $col_info['nullable'] ); |
|
101 | - $default = isset( $col_info['default'] ) ? $col_info['default'] : null; |
|
102 | - $auto_increment = isset( $args['auto_increment'] ) && $args['auto_increment'] === $old_col_name; |
|
103 | - $unique = isset( $col_info['unique'] ); |
|
104 | - $comment = isset( $col_info['comment'] ) ? $col_info['comment'] : null; |
|
105 | - $target_table = isset( $col_info['target_table'] ) ? $db->get_table( $col_info['target_table'] ) : null; |
|
96 | + $old_col_name = isset( $col_info[ 'old_name' ] ) ? $col_info[ 'old_name' ] : null; |
|
97 | + $new_col_name = isset( $col_info[ 'new_name' ] ) ? $col_info[ 'new_name' ] : null; |
|
98 | + $xtype = isset( $col_info[ 'xtype' ] ) ? $col_info[ 'xtype' ] : null; |
|
99 | + $size = isset( $col_info[ 'size' ] ) ? wp_unslash( $col_info[ 'size' ] ) : null; |
|
100 | + $nullable = isset( $col_info[ 'nullable' ] ); |
|
101 | + $default = isset( $col_info[ 'default' ] ) ? $col_info[ 'default' ] : null; |
|
102 | + $auto_increment = isset( $args[ 'auto_increment' ] ) && $args[ 'auto_increment' ] === $old_col_name; |
|
103 | + $unique = isset( $col_info[ 'unique' ] ); |
|
104 | + $comment = isset( $col_info[ 'comment' ] ) ? $col_info[ 'comment' ] : null; |
|
105 | + $target_table = isset( $col_info[ 'target_table' ] ) ? $db->get_table( $col_info[ 'target_table' ] ) : null; |
|
106 | 106 | |
107 | 107 | // Change existing or insert new column. |
108 | 108 | $altered = false; |
109 | 109 | if ( $old_col_name ) { |
110 | - $col = $table->get_column( $col_info['old_name'] ); |
|
110 | + $col = $table->get_column( $col_info[ 'old_name' ] ); |
|
111 | 111 | if ( $col instanceof Column ) { |
112 | 112 | $col->alter( $new_col_name, $xtype, $size, $nullable, $default, $auto_increment, $unique, $comment, $target_table, $previous_column_name ); |
113 | 113 | $altered = true; |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | public function delete( $args ) { |
138 | 138 | $template = new Template( 'table/delete.html' ); |
139 | 139 | $db = new Database( $this->wpdb ); |
140 | - $table = $db->get_table( $args['table'] ); |
|
140 | + $table = $db->get_table( $args[ 'table' ] ); |
|
141 | 141 | |
142 | 142 | // Ask for confirmation. |
143 | - if ( ! isset( $args['confirm_deletion'] ) ) { |
|
143 | + if ( ! isset( $args[ 'confirm_deletion' ] ) ) { |
|
144 | 144 | $template->table = $table; |
145 | 145 | return $template->render(); |
146 | 146 | } |