PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 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 All 45 releases
← All changes | classes/class-render.php +15 -44 3.3.3 → 3.4 View file →
@@ -7,8 +7,10 @@
7 7 * @author Tobias Bäthge
8 8 * @since 1.0.0
9 9 */
10 10
11 +declare(strict_types=1);
12 +
11 13 // Prohibit direct script loading.
12 14 defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
13 15
14 16 /**
@@ -195,10 +197,12 @@
195 197 */
196 198 protected function _prepare_render_data(): void {
197 199 $orig_table = $this->table;
198 200
199 - $num_rows = count( $this->table['data'] );
200 - $num_columns = ( $num_rows > 0 ) ? count( $this->table['data'][0] ) : 0;
201 + $counts = array(
202 + 'rows' => count( $this->table['data'] ),
203 + );
204 + $counts['columns'] = ( $counts['rows'] > 0 ) ? count( $this->table['data'][0] ) : 0;
201 205
202 206 // Evaluate show/hide_rows/columns parameters.
203 207 $actions = array( 'show', 'hide' );
204 208 $elements = array( 'rows', 'columns' );
@@ -203,56 +207,23 @@
203 207 $actions = array( 'show', 'hide' );
204 208 $elements = array( 'rows', 'columns' );
205 209 foreach ( $actions as $action ) {
206 210 foreach ( $elements as $element ) {
207 - if ( empty( $this->render_options[ "{$action}_{$element}" ] ) ) {
208 - $this->render_options[ "{$action}_{$element}" ] = array();
211 + $action_element = "{$action}_{$element}";
212 +
213 + if ( empty( $this->render_options[ $action_element ] ) ) {
214 + $this->render_options[ $action_element ] = array();
209 215 continue;
210 216 }
211 217
212 - // Add all rows/columns to array if "all" value set for one of the four parameters.
213 - if ( 'all' === $this->render_options[ "{$action}_{$element}" ] ) {
214 - $this->render_options[ "{$action}_{$element}" ] = range( 0, ${'num_' . $element} - 1 );
218 + // Add all rows/columns to array if a parameter is set to "all".
219 + if ( 'all' === $this->render_options[ $action_element ] ) {
220 + $this->render_options[ $action_element ] = range( 0, $counts[ $element ] - 1 );
215 221 continue;
216 222 }
217 223
218 - // We have a list of rows/columns (possibly with ranges in it).
219 - $this->render_options[ "{$action}_{$element}" ] = explode( ',', $this->render_options[ "{$action}_{$element}" ] );
220 - // Support for ranges like 3-6 or A-BA.
221 - $range_cells = array();
222 - foreach ( $this->render_options[ "{$action}_{$element}" ] as $key => $value ) {
223 - $range_dash = strpos( $value, '-' );
224 - if ( false !== $range_dash ) {
225 - unset( $this->render_options[ "{$action}_{$element}" ][ $key ] );
226 - $start = trim( substr( $value, 0, $range_dash ) );
227 - if ( ! is_numeric( $start ) ) {
228 - $start = TablePress::letter_to_number( $start );
229 - }
230 - $end = trim( substr( $value, $range_dash + 1 ) );
231 - if ( ! is_numeric( $end ) ) {
232 - $end = TablePress::letter_to_number( $end );
233 - }
234 - $current_range = range( $start, $end );
235 - $range_cells = array_merge( $range_cells, $current_range );
236 - }
237 - }
238 - $this->render_options[ "{$action}_{$element}" ] = array_merge( $this->render_options[ "{$action}_{$element}" ], $range_cells );
239 -
240 - /*
241 - * Parse single letters and change from regular numbering to zero-based numbering,
242 - * as rows/columns are indexed from 0 internally, but from 1 externally.
243 - */
244 - foreach ( $this->render_options[ "{$action}_{$element}" ] as $key => $value ) {
245 - $value = trim( $value );
246 - if ( ! is_numeric( $value ) ) {
247 - $value = TablePress::letter_to_number( $value );
248 - }
249 - $this->render_options[ "{$action}_{$element}" ][ $key ] = (int) $value - 1;
250 - }
251 -
252 - // Remove duplicate entries and sort the array.
253 - $this->render_options[ "{$action}_{$element}" ] = array_unique( $this->render_options[ "{$action}_{$element}" ] );
254 - sort( $this->render_options[ "{$action}_{$element}" ], SORT_NUMERIC );
224 + // Convert the list to a unique, sorted, and zero-based array of integers.
225 + $this->render_options[ $action_element ] = TablePress::convert_row_column_list_to_array( $this->render_options[ $action_element ], 1, $counts[ $element ], array( 'zero-based' => true ) );
255 226 }
256 227 }
257 228
258 229 // Load information about hidden rows and columns.