| @@ -108,9 +108,9 @@ | ||
| 108 | 108 | * @abstract |
| 109 | 109 | * @access public |
| 110 | 110 | * @return string The name of source. |
| 111 | 111 | */ |
| 112 | - abstract public function getSourceName(); | |
| 112 | + public abstract function getSourceName(); | |
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * Fetches information from source, parses it and builds series and data arrays. |
| 116 | 116 | * |
| @@ -118,9 +118,9 @@ | ||
| 118 | 118 | * |
| 119 | 119 | * @abstract |
| 120 | 120 | * @access public |
| 121 | 121 | */ |
| 122 | - abstract public function fetch(); | |
| 122 | + public abstract function fetch(); | |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Returns series parsed from source. |
| 126 | 126 | * |
| @@ -140,12 +140,9 @@ | ||
| 140 | 140 | * |
| 141 | 141 | * @access public |
| 142 | 142 | * @return string The serialized array of data. |
| 143 | 143 | */ |
| 144 | - public function getData( $fetch_from_editable_table = false ) { | |
| 145 | - if ( $fetch_from_editable_table ) { | |
| 146 | - $this->_fetchDataFromEditableTable(); | |
| 147 | - } | |
| 144 | + public function getData() { | |
| 148 | 145 | return serialize( $this->_data ); |
| 149 | 146 | } |
| 150 | 147 | |
| 151 | 148 | /** |
| @@ -155,12 +152,9 @@ | ||
| 155 | 152 | * |
| 156 | 153 | * @access public |
| 157 | 154 | * @return array |
| 158 | 155 | */ |
| 159 | - public function getRawData( $fetch_from_editable_table = false ) { | |
| 160 | - if ( $fetch_from_editable_table ) { | |
| 161 | - $this->_fetchDataFromEditableTable(); | |
| 162 | - } | |
| 156 | + public function getRawData() { | |
| 163 | 157 | return $this->_data; |
| 164 | 158 | } |
| 165 | 159 | |
| 166 | 160 | /** |
| @@ -217,9 +211,8 @@ | ||
| 217 | 211 | continue; |
| 218 | 212 | } |
| 219 | 213 | switch ( $series['type'] ) { |
| 220 | 214 | case 'number': |
| 221 | - $data[ $i ] = preg_replace( '/[\x{200B}-\x{200D}\x{FEFF}]/u', '', $data[ $i ] ); | |
| 222 | 215 | $data[ $i ] = ( is_numeric( $data[ $i ] ) ) ? floatval( $data[ $i ] ) : ( is_numeric( str_replace( ',', '', $data[ $i ] ) ) ? floatval( str_replace( ',', '', $data[ $i ] ) ) : null ); |
| 223 | 216 | break; |
| 224 | 217 | case 'boolean': |
| 225 | 218 | $datum = trim( strval( $data[ $i ] ) ); |
| @@ -243,10 +236,9 @@ | ||
| 243 | 236 | $data[ $i ] = $value->format( 'Y-m-d H:i:s' ); |
| 244 | 237 | } |
| 245 | 238 | break; |
| 246 | 239 | case 'string': |
| 247 | - // if a ' is provided, strip the backslash | |
| 248 | - $data[ $i ] = stripslashes( $this->toUTF8( $data[ $i ] ) ); | |
| 240 | + $data[ $i ] = $this->toUTF8( $data[ $i ] ); | |
| 249 | 241 | break; |
| 250 | 242 | } |
| 251 | 243 | } |
| 252 | 244 | |
| @@ -262,9 +254,9 @@ | ||
| 262 | 254 | * @param string $datum The data to convert. |
| 263 | 255 | * |
| 264 | 256 | * @return string The converted data. |
| 265 | 257 | */ |
| 266 | - final protected function toUTF8( $datum ) { | |
| 258 | + protected final function toUTF8( $datum ) { | |
| 267 | 259 | if ( ! function_exists( 'mb_detect_encoding' ) || mb_detect_encoding( $datum ) !== 'ASCII' ) { |
| 268 | 260 | $datum = \ForceUTF8\Encoding::toUTF8( $datum ); |
| 269 | 261 | } |
| 270 | 262 | return $datum; |
| @@ -279,9 +271,9 @@ | ||
| 279 | 271 | * @param array $data The actual array of data. |
| 280 | 272 | * |
| 281 | 273 | * @return array |
| 282 | 274 | */ |
| 283 | - final public static function get_date_formats_if_exists( $series, $data ) { | |
| 275 | + public static final function get_date_formats_if_exists( $series, $data ) { | |
| 284 | 276 | $date_formats = array(); |
| 285 | 277 | $types = array(); |
| 286 | 278 | $index = 0; |
| 287 | 279 | foreach ( $series as $column ) { |
| @@ -287,9 +279,9 @@ | ||
| 287 | 279 | foreach ( $series as $column ) { |
| 288 | 280 | if ( in_array( $column['type'], array( 'date', 'datetime', 'timeofday' ), true ) ) { |
| 289 | 281 | $types[] = array( 'index' => $index, 'type' => $column['type'] ); |
| 290 | 282 | } |
| 291 | - ++$index; | |
| 283 | + $index++; | |
| 292 | 284 | } |
| 293 | 285 | |
| 294 | 286 | if ( ! $types ) { |
| 295 | 287 | return $date_formats; |
| @@ -335,9 +327,9 @@ | ||
| 335 | 327 | * @param string $type 'date', 'timeofday' or 'datetime'. |
| 336 | 328 | * |
| 337 | 329 | * @return string|null |
| 338 | 330 | */ |
| 339 | - private static function determine_date_format( $value, $type ) { | |
| 331 | + private static final function determine_date_format( $value, $type ) { | |
| 340 | 332 | if ( version_compare( phpversion(), '5.3.0', '<' ) ) { |
| 341 | 333 | do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'PHP version %s not supported', phpversion() ), 'error', __FILE__, __LINE__ ); |
| 342 | 334 | return null; |
| 343 | 335 | } |
| @@ -428,9 +420,9 @@ | ||
| 428 | 420 | if ( $headers ) { |
| 429 | 421 | foreach ( $headers as $header ) { |
| 430 | 422 | if ( ! empty( $types[ $header ] ) ) { |
| 431 | 423 | $this->_series[] = array( |
| 432 | - 'label' => sanitize_text_field( wp_strip_all_tags( $header ) ), | |
| 424 | + 'label' => $header, | |
| 433 | 425 | 'type' => $types[ $header ], |
| 434 | 426 | ); |
| 435 | 427 | } |
| 436 | 428 | } |
| @@ -449,8 +441,9 @@ | ||
| 449 | 441 | * |
| 450 | 442 | * @access private |
| 451 | 443 | */ |
| 452 | 444 | private function _fetchDataFromEditableTable() { |
| 445 | + $params = $this->_args; | |
| 453 | 446 | $headers = wp_list_pluck( $this->_series, 'label' ); |
| 454 | 447 | $this->fetch(); |
| 455 | 448 | |
| 456 | 449 | $data = $this->_data; |
| @@ -457,12 +450,9 @@ | ||
| 457 | 450 | $this->_data = array(); |
| 458 | 451 | |
| 459 | 452 | foreach ( $data as $line ) { |
| 460 | 453 | $data_row = array(); |
| 461 | - // we have to make sure we are fetching the data in the right order | |
| 462 | - // in case the columns have been reordered | |
| 463 | - foreach ( $headers as $header ) { | |
| 464 | - $value = $line[ $header ]; | |
| 454 | + foreach ( $line as $header => $value ) { | |
| 465 | 455 | // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
| 466 | 456 | if ( in_array( $header, $headers ) ) { |
| 467 | 457 | $data_row[] = $value; |
| 468 | 458 | } |
| @@ -473,5 +463,7 @@ | ||
| 473 | 463 | do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Data found for %s = %s', print_r( $this->_args, true ), print_r( $this->_data, true ) ), 'debug', __FILE__, __LINE__ ); |
| 474 | 464 | |
| 475 | 465 | return true; |
| 476 | 466 | } |
| 467 | + | |
| 468 | + | |
| 477 | 469 | } |