| @@ -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,14 +211,12 @@ | ||
| 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 | - $datum = trim( strval( $data[ $i ] ) ); | |
| 226 | - $data[ $i ] = in_array( $datum, array( 'true', 'yes', '1' ), true ) ? 'true' : 'false'; | |
| 218 | + $data[ $i ] = ! empty( $data[ $i ] ) ? filter_var( $data[ $i ], FILTER_VALIDATE_BOOLEAN ) : null; | |
| 227 | 219 | break; |
| 228 | 220 | case 'timeofday': |
| 229 | 221 | $date = new DateTime( '1984-03-16T' . $data[ $i ] ); |
| 230 | 222 | if ( $date ) { |
| @@ -243,10 +235,9 @@ | ||
| 243 | 235 | $data[ $i ] = $value->format( 'Y-m-d H:i:s' ); |
| 244 | 236 | } |
| 245 | 237 | break; |
| 246 | 238 | case 'string': |
| 247 | - // if a ' is provided, strip the backslash | |
| 248 | - $data[ $i ] = stripslashes( $this->toUTF8( $data[ $i ] ) ); | |
| 239 | + $data[ $i ] = $this->toUTF8( $data[ $i ] ); | |
| 249 | 240 | break; |
| 250 | 241 | } |
| 251 | 242 | } |
| 252 | 243 | |
| @@ -262,9 +253,9 @@ | ||
| 262 | 253 | * @param string $datum The data to convert. |
| 263 | 254 | * |
| 264 | 255 | * @return string The converted data. |
| 265 | 256 | */ |
| 266 | - final protected function toUTF8( $datum ) { | |
| 257 | + protected final function toUTF8( $datum ) { | |
| 267 | 258 | if ( ! function_exists( 'mb_detect_encoding' ) || mb_detect_encoding( $datum ) !== 'ASCII' ) { |
| 268 | 259 | $datum = \ForceUTF8\Encoding::toUTF8( $datum ); |
| 269 | 260 | } |
| 270 | 261 | return $datum; |
| @@ -279,9 +270,9 @@ | ||
| 279 | 270 | * @param array $data The actual array of data. |
| 280 | 271 | * |
| 281 | 272 | * @return array |
| 282 | 273 | */ |
| 283 | - final public static function get_date_formats_if_exists( $series, $data ) { | |
| 274 | + public static final function get_date_formats_if_exists( $series, $data ) { | |
| 284 | 275 | $date_formats = array(); |
| 285 | 276 | $types = array(); |
| 286 | 277 | $index = 0; |
| 287 | 278 | foreach ( $series as $column ) { |
| @@ -287,9 +278,9 @@ | ||
| 287 | 278 | foreach ( $series as $column ) { |
| 288 | 279 | if ( in_array( $column['type'], array( 'date', 'datetime', 'timeofday' ), true ) ) { |
| 289 | 280 | $types[] = array( 'index' => $index, 'type' => $column['type'] ); |
| 290 | 281 | } |
| 291 | - ++$index; | |
| 282 | + $index++; | |
| 292 | 283 | } |
| 293 | 284 | |
| 294 | 285 | if ( ! $types ) { |
| 295 | 286 | return $date_formats; |
| @@ -335,11 +326,10 @@ | ||
| 335 | 326 | * @param string $type 'date', 'timeofday' or 'datetime'. |
| 336 | 327 | * |
| 337 | 328 | * @return string|null |
| 338 | 329 | */ |
| 339 | - private static function determine_date_format( $value, $type ) { | |
| 330 | + private static final function determine_date_format( $value, $type ) { | |
| 340 | 331 | if ( version_compare( phpversion(), '5.3.0', '<' ) ) { |
| 341 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'PHP version %s not supported', phpversion() ), 'error', __FILE__, __LINE__ ); | |
| 342 | 332 | return null; |
| 343 | 333 | } |
| 344 | 334 | |
| 345 | 335 | $formats = array( |
| @@ -394,84 +384,6 @@ | ||
| 394 | 384 | public function get_error() { |
| 395 | 385 | return $this->_error; |
| 396 | 386 | } |
| 397 | 387 | |
| 398 | - /** | |
| 399 | - * Fetches information from the editable table and parses it to build series and data arrays. | |
| 400 | - * | |
| 401 | - * @since ? | |
| 402 | - * | |
| 403 | - * @access public | |
| 404 | - * @return boolean TRUE on success, otherwise FALSE. | |
| 405 | - */ | |
| 406 | - public function fetchFromEditableTable() { | |
| 407 | - if ( empty( $this->_args ) ) { | |
| 408 | - return false; | |
| 409 | - } | |
| 410 | 388 | |
| 411 | - $this->_fetchSeriesFromEditableTable(); | |
| 412 | - $this->_fetchDataFromEditableTable(); | |
| 413 | - return true; | |
| 414 | - } | |
| 415 | - | |
| 416 | - /** | |
| 417 | - * Fetches series information from the editable table. This is fetched only through the UI and not while refreshing the chart data. | |
| 418 | - * | |
| 419 | - * @since 1.0.0 | |
| 420 | - * | |
| 421 | - * @access private | |
| 422 | - */ | |
| 423 | - private function _fetchSeriesFromEditableTable() { | |
| 424 | - $params = $this->_args; | |
| 425 | - $headers = array_filter( $params['header'] ); | |
| 426 | - $types = array_filter( $params['type'] ); | |
| 427 | - $header_row = $type_row = array(); | |
| 428 | - if ( $headers ) { | |
| 429 | - foreach ( $headers as $header ) { | |
| 430 | - if ( ! empty( $types[ $header ] ) ) { | |
| 431 | - $this->_series[] = array( | |
| 432 | - 'label' => sanitize_text_field( wp_strip_all_tags( $header ) ), | |
| 433 | - 'type' => $types[ $header ], | |
| 434 | - ); | |
| 435 | - } | |
| 436 | - } | |
| 437 | - } | |
| 438 | - | |
| 439 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Series found for %s = %s', print_r( $this->_args, true ), print_r( $this->_series, true ) ), 'debug', __FILE__, __LINE__ ); | |
| 440 | - | |
| 441 | - return true; | |
| 442 | - } | |
| 443 | - | |
| 444 | - | |
| 445 | - /** | |
| 446 | - * Fetches data information from the editable table. | |
| 447 | - * | |
| 448 | - * @since 1.0.0 | |
| 449 | - * | |
| 450 | - * @access private | |
| 451 | - */ | |
| 452 | - private function _fetchDataFromEditableTable() { | |
| 453 | - $headers = wp_list_pluck( $this->_series, 'label' ); | |
| 454 | - $this->fetch(); | |
| 455 | - | |
| 456 | - $data = $this->_data; | |
| 457 | - $this->_data = array(); | |
| 458 | - | |
| 459 | - foreach ( $data as $line ) { | |
| 460 | - $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 ]; | |
| 465 | - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 466 | - if ( in_array( $header, $headers ) ) { | |
| 467 | - $data_row[] = $value; | |
| 468 | - } | |
| 469 | - } | |
| 470 | - $this->_data[] = $this->_normalizeData( $data_row ); | |
| 471 | - } | |
| 472 | - | |
| 473 | - 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 | - | |
| 475 | - return true; | |
| 476 | - } | |
| 477 | 389 | } |