| @@ -66,10 +66,10 @@ | ||
| 66 | 66 | |
| 67 | 67 | $this->_addFilter( Visualizer_Plugin::FILTER_UNDO_REVISIONS, 'undoRevisions', 10, 2 ); |
| 68 | 68 | $this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 ); |
| 69 | 69 | $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 ); |
| 70 | - $this->_addAction( 'pre_get_posts', 'PreGetPosts' ); | |
| 71 | - register_shutdown_function( array( $this, 'onShutdown' ) ); | |
| 70 | + register_shutdown_function( array($this, 'onShutdown') ); | |
| 71 | + | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * Register a shutdown hook to catch fatal errors. |
| @@ -79,9 +79,9 @@ | ||
| 79 | 79 | * @access public |
| 80 | 80 | */ |
| 81 | 81 | public function onShutdown() { |
| 82 | 82 | $error = error_get_last(); |
| 83 | - if ( $error && $error['type'] === E_ERROR && false !== strpos( $error['file'], 'Visualizer/' ) ) { | |
| 83 | + if ( $error['type'] === E_ERROR && false !== strpos( $error['file'], 'Visualizer/' ) ) { | |
| 84 | 84 | do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Critical error %s', print_r( $error, true ) ), 'error', __FILE__, __LINE__ ); |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| @@ -112,18 +112,18 @@ | ||
| 112 | 112 | * @access public |
| 113 | 113 | * @param string $tag The name of the AJAX action to which the $method is hooked. |
| 114 | 114 | * @param string $method Optional. The name of the method to be called. If the name of the method is not provided, tag name will be used as method name. |
| 115 | 115 | * @param bool $methodClass The root of the method. |
| 116 | - * @param boolean $logged_in Optional. Determines if we should register hook for logged in users. | |
| 117 | - * @param boolean $logged_out Optional. Determines if we should register hook for not logged in users. | |
| 116 | + * @param boolean $private Optional. Determines if we should register hook for logged in users. | |
| 117 | + * @param boolean $public Optional. Determines if we should register hook for not logged in users. | |
| 118 | 118 | * @return Visualizer_Module |
| 119 | 119 | */ |
| 120 | - protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $logged_in = true, $logged_out = false ) { | |
| 121 | - if ( $logged_in ) { | |
| 120 | + protected function _addAjaxAction( $tag, $method = '', $methodClass = null, $private = true, $public = false ) { | |
| 121 | + if ( $private ) { | |
| 122 | 122 | $this->_addAction( 'wp_ajax_' . $tag, $method, $methodClass ); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ( $logged_out ) { | |
| 125 | + if ( $public ) { | |
| 126 | 126 | $this->_addAction( 'wp_ajax_nopriv_' . $tag, $method, $methodClass ); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return $this; |
| @@ -136,9 +136,9 @@ | ||
| 136 | 136 | * @uses add_filter() To register filter hook. |
| 137 | 137 | * |
| 138 | 138 | * @access protected |
| 139 | 139 | * @param string $tag The name of the filter to hook the $method to. |
| 140 | - * @param string $method The name of the method to be called when the filter is applied. | |
| 140 | + * @param type $method The name of the method to be called when the filter is applied. | |
| 141 | 141 | * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. |
| 142 | 142 | * @param int $accepted_args optional. The number of arguments the function accept (default 1). |
| 143 | 143 | * @return Visualizer_Module |
| 144 | 144 | */ |
| @@ -167,9 +167,9 @@ | ||
| 167 | 167 | * A wrapper around the actual function _getDataAs. This function is invoked as a filter. |
| 168 | 168 | * |
| 169 | 169 | * @since 3.2.0 |
| 170 | 170 | */ |
| 171 | - public function getDataAs( $data, $chart_id, $type ) { | |
| 171 | + public function getDataAs( $final, $chart_id, $type ) { | |
| 172 | 172 | return $this->_getDataAs( $chart_id, $type ); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
| @@ -233,8 +233,9 @@ | ||
| 233 | 233 | $title = 'visualizer#' . $chart_id; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | $filename = $title; |
| 237 | + | |
| 237 | 238 | switch ( $type ) { |
| 238 | 239 | case 'csv': |
| 239 | 240 | $final = $this->_getCSV( $rows, $filename, false ); |
| 240 | 241 | break; |
| @@ -246,11 +247,8 @@ | ||
| 246 | 247 | break; |
| 247 | 248 | case 'print': |
| 248 | 249 | $final = $this->_getHTML( $rows ); |
| 249 | 250 | break; |
| 250 | - case 'image': | |
| 251 | - $final = $this->_getImage( $chart ); | |
| 252 | - break; | |
| 253 | 251 | } |
| 254 | 252 | } |
| 255 | 253 | return $final; |
| 256 | 254 | } |
| @@ -266,23 +264,9 @@ | ||
| 266 | 264 | private function _getCSV( $rows, $filename, $enclose ) { |
| 267 | 265 | $filename .= '.csv'; |
| 268 | 266 | |
| 269 | 267 | $bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF ); |
| 270 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 271 | - $fp = function_exists( 'tmpfile' ) ? @tmpfile() : null; | |
| 272 | - if ( ! $fp ) { | |
| 273 | - if ( ! function_exists( 'wp_tempnam' ) ) { | |
| 274 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 275 | - } | |
| 276 | - $fp = fopen( wp_tempnam(), 'w+' ); | |
| 277 | - } | |
| 278 | - if ( ! $fp ) { | |
| 279 | - return array( 'csv' => '', 'name' => $filename, 'string' => '' ); | |
| 280 | - } | |
| 281 | - if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) { | |
| 282 | - unset( $rows[1] ); | |
| 283 | - $rows = array_values( $rows ); | |
| 284 | - } | |
| 268 | + $fp = tmpfile(); | |
| 285 | 269 | // support for MS Excel |
| 286 | 270 | fprintf( $fp, $bom ); |
| 287 | 271 | foreach ( $rows as $row ) { |
| 288 | 272 | fputcsv( $fp, $row ); |
| @@ -288,10 +272,10 @@ | ||
| 288 | 272 | fputcsv( $fp, $row ); |
| 289 | 273 | } |
| 290 | 274 | rewind( $fp ); |
| 291 | 275 | $csv = ''; |
| 292 | - $array = fgetcsv( $fp ); | |
| 293 | - while ( $array !== false ) { | |
| 276 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition | |
| 277 | + while ( ( $array = fgetcsv( $fp ) ) !== false ) { | |
| 294 | 278 | if ( strlen( $csv ) > 0 ) { |
| 295 | 279 | $csv .= PHP_EOL; |
| 296 | 280 | } |
| 297 | 281 | // if enclosure is required, check every item of this line |
| @@ -305,10 +289,9 @@ | ||
| 305 | 289 | $temp_array[] = $item; |
| 306 | 290 | } |
| 307 | 291 | $array = $temp_array; |
| 308 | 292 | } |
| 309 | - $csv .= implode( ',', $array ); | |
| 310 | - $array = fgetcsv( $fp ); | |
| 293 | + $csv .= implode( ',', $array ); | |
| 311 | 294 | } |
| 312 | 295 | fclose( $fp ); |
| 313 | 296 | |
| 314 | 297 | return array( |
| @@ -325,49 +308,31 @@ | ||
| 325 | 308 | * @param array $rows The array of data. |
| 326 | 309 | * @param string $filename The name of the file to use. |
| 327 | 310 | */ |
| 328 | 311 | private function _getExcel( $rows, $filename ) { |
| 329 | - // OpenSpout allows for long sheet names, but let's keep the same limit for compatibility. | |
| 330 | - $chart = substr( $filename, 0, 30 ); | |
| 331 | - $filename .= '.xlsx'; | |
| 332 | - if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) { | |
| 333 | - unset( $rows[1] ); | |
| 334 | - $rows = array_values( $rows ); | |
| 335 | - $rows = array_map( | |
| 336 | - function ( $r ) { | |
| 337 | - return array_map( 'strval', $r ); | |
| 338 | - }, | |
| 339 | - $rows | |
| 340 | - ); | |
| 341 | - } | |
| 312 | + // PHPExcel did not like sheet names longer than 31 characters and we will assume the same with PhpSpreadsheet | |
| 313 | + $chart = substr( $filename, 0, 30 ); | |
| 314 | + $filename .= '.xlsx'; | |
| 315 | + | |
| 342 | 316 | $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php'; |
| 343 | 317 | if ( is_readable( $vendor_file ) ) { |
| 344 | - include_once $vendor_file; | |
| 318 | + include_once( $vendor_file ); | |
| 345 | 319 | } |
| 346 | - $xlsData = ''; | |
| 347 | - if ( class_exists( 'OpenSpout\Writer\Common\Creator\WriterEntityFactory' ) ) { | |
| 348 | - try { | |
| 349 | - // Use OpenSpout to create the XLSX file in memory. | |
| 350 | - $writer = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createXLSXWriter(); | |
| 351 | - $writer->openToFile( 'php://output' ); // Open to output instead of a file. | |
| 352 | - $writer->getCurrentSheet()->setName( sanitize_title( $chart ) ); | |
| 353 | 320 | |
| 354 | - // Write rows. | |
| 355 | - foreach ( $rows as $row ) { | |
| 356 | - $rowFromValues = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( $row ); | |
| 357 | - $writer->addRow( $rowFromValues ); | |
| 358 | - } | |
| 359 | - | |
| 360 | - ob_start(); | |
| 361 | - $writer->close(); // Saves and closes the file in the output buffer. | |
| 362 | - $xlsData = ob_get_clean(); | |
| 363 | - } catch ( Exception $e ) { | |
| 364 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'OpenSpout writer error: ' . $e->getMessage(), 'error', __FILE__, __LINE__ ); | |
| 365 | - error_log( 'OpenSpout writer error: ' . $e->getMessage() ); | |
| 366 | - } | |
| 321 | + $xlsData = ''; | |
| 322 | + if ( class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) ) { | |
| 323 | + $doc = new PhpOffice\PhpSpreadsheet\Spreadsheet(); | |
| 324 | + $doc->getActiveSheet()->fromArray( $rows, null, 'A1' ); | |
| 325 | + $doc->getActiveSheet()->setTitle( sanitize_title( $chart ) ); | |
| 326 | + $doc = apply_filters( 'visualizer_excel_doc', $doc ); | |
| 327 | + $writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter( $doc, 'Xlsx' ); | |
| 328 | + ob_start(); | |
| 329 | + $writer->save( 'php://output' ); | |
| 330 | + $xlsData = ob_get_contents(); | |
| 331 | + ob_end_clean(); | |
| 367 | 332 | } else { |
| 368 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class OpenSpout\Writer\Common\Creator\WriterEntityFactory does not exist!', 'error', __FILE__, __LINE__ ); | |
| 369 | - error_log( 'Class OpenSpout\Writer\Common\Creator\WriterEntityFactory does not exist!' ); | |
| 333 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!', 'error', __FILE__, __LINE__ ); | |
| 334 | + error_log( 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!' ); | |
| 370 | 335 | } |
| 371 | 336 | return array( |
| 372 | 337 | 'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ), |
| 373 | 338 | 'name' => $filename, |
| @@ -404,9 +369,9 @@ | ||
| 404 | 369 | $index = 0; |
| 405 | 370 | foreach ( $rows as $row ) { |
| 406 | 371 | // skip the data type row. |
| 407 | 372 | if ( 1 === $index ) { |
| 408 | - ++$index; | |
| 373 | + $index++; | |
| 409 | 374 | continue; |
| 410 | 375 | } |
| 411 | 376 | |
| 412 | 377 | $table .= '<tr>'; |
| @@ -417,9 +382,9 @@ | ||
| 417 | 382 | $table .= '<td>' . $col . '</td>'; |
| 418 | 383 | } |
| 419 | 384 | } |
| 420 | 385 | $table .= '</tr>'; |
| 421 | - ++$index; | |
| 386 | + $index++; | |
| 422 | 387 | } |
| 423 | 388 | $table .= '</table>'; |
| 424 | 389 | |
| 425 | 390 | $html .= apply_filters( 'visualizer_print_table', $table ) . ' |
| @@ -432,11 +397,11 @@ | ||
| 432 | 397 | |
| 433 | 398 | /** |
| 434 | 399 | * Disable revisions temporarily for visualizer post type. |
| 435 | 400 | */ |
| 436 | - final protected function disableRevisionsTemporarily() { | |
| 401 | + protected final function disableRevisionsTemporarily() { | |
| 437 | 402 | add_filter( |
| 438 | - 'wp_revisions_to_keep', function ( $num, $post ) { | |
| 403 | + 'wp_revisions_to_keep', function( $num, $post ) { | |
| 439 | 404 | if ( $post->post_type === Visualizer_Plugin::CPT_VISUALIZER ) { |
| 440 | 405 | return 0; |
| 441 | 406 | } |
| 442 | 407 | return $num; |
| @@ -448,9 +413,9 @@ | ||
| 448 | 413 | * Undo revisions for the chart, and if necessary, restore the earliest version. |
| 449 | 414 | * |
| 450 | 415 | * @return bool If any revisions were found. |
| 451 | 416 | */ |
| 452 | - final public function undoRevisions( $chart_id, $restore = false ) { | |
| 417 | + public final function undoRevisions( $chart_id, $restore = false ) { | |
| 453 | 418 | do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ ); |
| 454 | 419 | if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) { |
| 455 | 420 | return false; |
| 456 | 421 | } |
| @@ -480,19 +445,14 @@ | ||
| 480 | 445 | |
| 481 | 446 | /** |
| 482 | 447 | * If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing. |
| 483 | 448 | */ |
| 484 | - final public function handleExistingRevisions( $chart_id, $chart ) { | |
| 449 | + public final function handleExistingRevisions( $chart_id, $chart ) { | |
| 485 | 450 | |
| 486 | 451 | do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ ); |
| 487 | 452 | if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) { |
| 488 | 453 | return $chart_id; |
| 489 | 454 | } |
| 490 | - // AI Builder (D3) charts use their own publish flow — skip the classic revision-restore | |
| 491 | - // mechanism, which would otherwise overwrite the saved title and settings. | |
| 492 | - if ( 'd3' === get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true ) ) { | |
| 493 | - return $chart; | |
| 494 | - } | |
| 495 | 455 | // undo revisions. |
| 496 | 456 | $revisions_found = $this->undoRevisions( $chart_id, true ); |
| 497 | 457 | |
| 498 | 458 | // create revision for the edit action. |
| @@ -536,55 +496,48 @@ | ||
| 536 | 496 | if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) { |
| 537 | 497 | return $default; |
| 538 | 498 | } |
| 539 | 499 | |
| 540 | - try { | |
| 541 | - require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 542 | - WP_Filesystem(); | |
| 543 | - global $wp_filesystem; | |
| 544 | - if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) { | |
| 545 | - return $default; | |
| 546 | - } | |
| 500 | + require_once( ABSPATH . 'wp-admin/includes/file.php' ); | |
| 501 | + WP_Filesystem(); | |
| 502 | + global $wp_filesystem; | |
| 547 | 503 | |
| 548 | - $multisite_arg = '/'; | |
| 549 | - if ( is_multisite() && ! is_main_site() ) { | |
| 550 | - $multisite_arg = '/sites/' . get_current_blog_id() . '/'; | |
| 551 | - } | |
| 504 | + $multisite_arg = '/'; | |
| 505 | + if ( is_multisite() && ! is_main_site() ) { | |
| 506 | + $multisite_arg = '/sites/' . get_current_blog_id() . '/'; | |
| 507 | + } | |
| 552 | 508 | |
| 553 | - $dir = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer'; | |
| 554 | - $file = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer/customization.js'; | |
| 509 | + $dir = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer'; | |
| 510 | + $file = $wp_filesystem->wp_content_dir() . 'uploads' . $multisite_arg . 'visualizer/customization.js'; | |
| 555 | 511 | |
| 556 | - if ( $wp_filesystem->is_readable( $file ) ) { | |
| 557 | - return $specific; | |
| 558 | - } | |
| 512 | + if ( $wp_filesystem->is_readable( $file ) ) { | |
| 513 | + return $specific; | |
| 514 | + } | |
| 559 | 515 | |
| 560 | - if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) { | |
| 561 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ ); | |
| 516 | + if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) { | |
| 517 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ ); | |
| 518 | + return $default; | |
| 519 | + } | |
| 520 | + | |
| 521 | + if ( ! $wp_filesystem->exists( $dir ) ) { | |
| 522 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found | |
| 523 | + if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) { | |
| 524 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ ); | |
| 562 | 525 | return $default; |
| 563 | 526 | } |
| 527 | + } | |
| 564 | 528 | |
| 565 | - if ( ! $wp_filesystem->exists( $dir ) ) { | |
| 566 | - $done = $wp_filesystem->mkdir( $dir ); | |
| 567 | - if ( $done === false ) { | |
| 568 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ ); | |
| 569 | - return $default; | |
| 570 | - } | |
| 529 | + // if file does not exist, copy. | |
| 530 | + if ( ! $wp_filesystem->exists( $file ) ) { | |
| 531 | + $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' ); | |
| 532 | + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found | |
| 533 | + if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) { | |
| 534 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ ); | |
| 535 | + return $default; | |
| 571 | 536 | } |
| 537 | + } | |
| 572 | 538 | |
| 573 | - // if file does not exist, copy. | |
| 574 | - if ( ! $wp_filesystem->exists( $file ) ) { | |
| 575 | - $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' ); | |
| 576 | - $done = $wp_filesystem->copy( $src, $file ); | |
| 577 | - if ( $done === false ) { | |
| 578 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ ); | |
| 579 | - return $default; | |
| 580 | - } | |
| 581 | - } | |
| 582 | - | |
| 583 | - return $specific; | |
| 584 | - } catch ( \Throwable $e ) { | |
| 585 | - return $default; | |
| 586 | - } | |
| 539 | + return $specific; | |
| 587 | 540 | } |
| 588 | 541 | |
| 589 | 542 | /** |
| 590 | 543 | * Load the class for the given chart's chart type so that its assets can be loaded. |
| @@ -589,18 +542,12 @@ | ||
| 589 | 542 | /** |
| 590 | 543 | * Load the class for the given chart's chart type so that its assets can be loaded. |
| 591 | 544 | */ |
| 592 | 545 | protected function load_chart_type( $chart_id ) { |
| 593 | - // D3/AI charts have no traditional type class — return the library string directly. | |
| 594 | - $lib = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true ); | |
| 595 | - if ( 'd3' === $lib ) { | |
| 596 | - return 'd3'; | |
| 597 | - } | |
| 598 | - | |
| 599 | 546 | $name = $this->load_chart_class_name( $chart_id ); |
| 600 | 547 | $class = null; |
| 601 | 548 | if ( class_exists( $name ) || true === apply_filters( 'visualizer_load_chart', false, $name ) ) { |
| 602 | - $class = new $name(); | |
| 549 | + $class = new $name; | |
| 603 | 550 | } |
| 604 | 551 | |
| 605 | 552 | if ( is_null( $class ) && Visualizer_Module::is_pro() ) { |
| 606 | 553 | // lets see if this type exists in pro. New Lite(3.1.0+) & old Pro(1.8.0-). |
| @@ -638,31 +585,32 @@ | ||
| 638 | 585 | */ |
| 639 | 586 | protected function get_inline_custom_css( $id, $settings ) { |
| 640 | 587 | $css = ''; |
| 641 | 588 | |
| 589 | + $arguments = array( '', $settings ); | |
| 590 | + if ( ! isset( $settings['customcss'] ) ) { | |
| 591 | + return $arguments; | |
| 592 | + } | |
| 593 | + | |
| 642 | 594 | $classes = array(); |
| 643 | 595 | $css = '<style type="text/css" name="visualizer-custom-css" id="customcss-' . $id . '">'; |
| 644 | - if ( ! empty( $settings['customcss'] ) ) { | |
| 645 | - foreach ( $settings['customcss'] as $name => $element ) { | |
| 646 | - $attributes = array(); | |
| 647 | - foreach ( $element as $property => $value ) { | |
| 648 | - $attributes[] = $this->handle_css_property( $property, $value ); | |
| 649 | - } | |
| 650 | - $class_name = $id . $name; | |
| 651 | - $properties = implode( ' !important; ', array_filter( $attributes ) ); | |
| 652 | - if ( ! empty( $properties ) ) { | |
| 653 | - $css .= '.' . $class_name . ' {' . $properties . ' !important;}'; | |
| 654 | - $classes[ $name ] = $class_name; | |
| 655 | - } | |
| 596 | + foreach ( $settings['customcss'] as $name => $element ) { | |
| 597 | + $attributes = array(); | |
| 598 | + foreach ( $element as $property => $value ) { | |
| 599 | + $attributes[] = $this->handle_css_property( $property, $value ); | |
| 656 | 600 | } |
| 657 | - $settings['cssClassNames'] = $classes; | |
| 601 | + $class_name = $id . $name; | |
| 602 | + $properties = implode( ' !important; ', array_filter( $attributes ) ); | |
| 603 | + if ( ! empty( $properties ) ) { | |
| 604 | + $css .= '.' . $class_name . ' {' . $properties . ' !important;}'; | |
| 605 | + $classes[ $name ] = $class_name; | |
| 606 | + } | |
| 658 | 607 | } |
| 608 | + $css .= '</style>'; | |
| 659 | 609 | |
| 660 | - $img_path = VISUALIZER_ABSURL . 'images'; | |
| 661 | - $css .= ".locker,.locker-loader{position:absolute;top:0;left:0;width:100%;height:100%}.locker{z-index:1000;opacity:.8;background-color:#fff;-ms-filter:\"progid:DXImageTransform.Microsoft.Alpha(Opacity=80)\";filter:alpha(opacity=80)}.locker-loader{z-index:1001;background:url($img_path/ajax-loader.gif) no-repeat center center}.dt-button{display:none!important}.visualizer-front-container.visualizer-lazy-render{content-visibility: auto;}.google-visualization-controls-categoryfilter label.google-visualization-controls-label {vertical-align: middle;}.google-visualization-controls-categoryfilter li.goog-inline-block {margin: 0 0.2em;}.google-visualization-controls-categoryfilter li {padding: 0 0.2em;}.visualizer-front-container .dataTables_scrollHeadInner{margin: 0 auto;}"; | |
| 662 | - $css .= '</style>'; | |
| 610 | + $settings['cssClassNames'] = $classes; | |
| 663 | 611 | |
| 664 | - $arguments = array( $css, $settings ); | |
| 612 | + $arguments = array( $css, $settings ); | |
| 665 | 613 | apply_filters_ref_array( 'visualizer_inline_css', array( &$arguments ) ); |
| 666 | 614 | |
| 667 | 615 | return $arguments; |
| 668 | 616 | } |
| @@ -722,29 +670,8 @@ | ||
| 722 | 670 | return $q->found_posts; |
| 723 | 671 | } |
| 724 | 672 | |
| 725 | 673 | /** |
| 726 | - * Checks whether the current user may edit a specific chart. | |
| 727 | - * | |
| 728 | - * @param int $chart_id Chart ID. | |
| 729 | - * @return bool | |
| 730 | - */ | |
| 731 | - public static function can_edit_chart( $chart_id ) { | |
| 732 | - $chart_id = absint( $chart_id ); | |
| 733 | - if ( ! $chart_id ) { | |
| 734 | - return false; | |
| 735 | - } | |
| 736 | - | |
| 737 | - $chart = get_post( $chart_id ); | |
| 738 | - return $chart | |
| 739 | - && Visualizer_Plugin::CPT_VISUALIZER === $chart->post_type | |
| 740 | - && ( | |
| 741 | - current_user_can( 'edit_post', $chart_id ) | |
| 742 | - || ( (int) $chart->post_author === get_current_user_id() && current_user_can( 'edit_posts' ) ) | |
| 743 | - ); | |
| 744 | - } | |
| 745 | - | |
| 746 | - /** | |
| 747 | 674 | * Checks if the PRO version is active. |
| 748 | 675 | * |
| 749 | 676 | * @since 3.3.0 |
| 750 | 677 | */ |
| @@ -780,132 +707,32 @@ | ||
| 780 | 707 | |
| 781 | 708 | /** |
| 782 | 709 | * Gets the features for the provided license type. |
| 783 | 710 | */ |
| 784 | - final public static function get_features_for_license( $plan ) { | |
| 785 | - $is_new_personal = apply_filters( 'visualizer_is_new_personal', false ); | |
| 711 | + public static final function get_features_for_license( $plan ) { | |
| 786 | 712 | switch ( $plan ) { |
| 787 | 713 | case 1: |
| 788 | - $features = array( 'import-wp', 'import-wc-report', 'import-file', 'import-url' ); | |
| 789 | - if ( ! $is_new_personal ) { | |
| 790 | - $features[] = 'db-query'; | |
| 791 | - } | |
| 792 | - return $features; | |
| 714 | + return array( 'import-wp', 'db-query' ); | |
| 793 | 715 | case 2: |
| 794 | - $features = array( 'schedule-chart', 'chart-permissions', 'import-chart', 'data-filter-configuration', 'frontend-actions' ); | |
| 795 | - if ( $is_new_personal ) { | |
| 796 | - $features[] = 'db-query'; | |
| 797 | - } | |
| 798 | - return $features; | |
| 716 | + return array( 'schedule-chart', 'chart-permissions' ); | |
| 799 | 717 | } |
| 800 | 718 | } |
| 801 | 719 | |
| 802 | 720 | /** |
| 803 | - * Safely unserialize chart/source content, blocking PHP object injection. | |
| 804 | - * | |
| 805 | - * Single guarded chokepoint shared by chart/source content sinks so the | |
| 806 | - * allowed_classes guard cannot be dropped from one call site independently. | |
| 807 | - * | |
| 808 | - * @param mixed $content The serialized content (only strings are decoded). | |
| 809 | - * @return mixed The decoded value (array for valid chart data), or false. | |
| 810 | - */ | |
| 811 | - public static function decode_content( $content ) { | |
| 812 | - if ( ! is_string( $content ) ) { | |
| 813 | - return false; | |
| 814 | - } | |
| 815 | - $value = unserialize( trim( $content ), array( 'allowed_classes' => false ) ); | |
| 816 | - if ( self::contains_references( $value ) ) { | |
| 817 | - return false; | |
| 818 | - } | |
| 819 | - return self::strip_incomplete_objects( $value ); | |
| 820 | - } | |
| 821 | - | |
| 822 | - /** | |
| 823 | - * Check decoded arrays for references before recursively processing them. | |
| 824 | - * | |
| 825 | - * Cyclic serialized arrays necessarily contain a reference. Rejecting all | |
| 826 | - * references also prevents shared references from becoming cycles later, | |
| 827 | - * so strip_incomplete_objects() cannot recurse without terminating. | |
| 828 | - * | |
| 829 | - * @param mixed $value The decoded value. | |
| 830 | - * @return bool Whether the value contains an array reference. | |
| 831 | - */ | |
| 832 | - private static function contains_references( $value ) { | |
| 833 | - if ( ! is_array( $value ) ) { | |
| 834 | - return false; | |
| 835 | - } | |
| 836 | - foreach ( array_keys( $value ) as $key ) { | |
| 837 | - if ( null !== ReflectionReference::fromArrayElement( $value, $key ) ) { | |
| 838 | - return true; | |
| 839 | - } | |
| 840 | - if ( is_array( $value[ $key ] ) && self::contains_references( $value[ $key ] ) ) { | |
| 841 | - return true; | |
| 842 | - } | |
| 843 | - } | |
| 844 | - return false; | |
| 845 | - } | |
| 846 | - | |
| 847 | - /** | |
| 848 | - * Remove the __PHP_Incomplete_Class stubs the allowed_classes guard leaves | |
| 849 | - * behind; they crash map_deep() when the decoded value is written back to | |
| 850 | - * post meta. Legitimate chart content is nested arrays/scalars only. | |
| 851 | - * | |
| 852 | - * @param mixed $value The decoded value. | |
| 853 | - * @return mixed The value without object stubs; false for a top-level stub. | |
| 854 | - */ | |
| 855 | - private static function strip_incomplete_objects( $value ) { | |
| 856 | - if ( $value instanceof __PHP_Incomplete_Class ) { | |
| 857 | - return false; | |
| 858 | - } | |
| 859 | - if ( is_array( $value ) ) { | |
| 860 | - foreach ( $value as $key => $item ) { | |
| 861 | - if ( $item instanceof __PHP_Incomplete_Class ) { | |
| 862 | - unset( $value[ $key ] ); | |
| 863 | - } elseif ( is_array( $item ) ) { | |
| 864 | - $value[ $key ] = self::strip_incomplete_objects( $item ); | |
| 865 | - } | |
| 866 | - } | |
| 867 | - } | |
| 868 | - return $value; | |
| 869 | - } | |
| 870 | - | |
| 871 | - /** | |
| 872 | - * Object-injection-safe drop-in for maybe_unserialize(). | |
| 873 | - * | |
| 874 | - * @param mixed $value Raw meta/content value. | |
| 875 | - * @return mixed The decoded value for serialized input, the value unchanged otherwise. | |
| 876 | - */ | |
| 877 | - public static function maybe_decode_content( $value ) { | |
| 878 | - return is_serialized( $value ) ? self::decode_content( $value ) : $value; | |
| 879 | - } | |
| 880 | - | |
| 881 | - /** | |
| 882 | 721 | * Gets the chart content after common manipulations. |
| 883 | 722 | */ |
| 884 | 723 | public static function get_chart_data( $chart, $type, $run_filter = true ) { |
| 885 | 724 | // change HTML entities |
| 886 | - $post_content = html_entity_decode( htmlentities( $chart->post_content ) ); | |
| 887 | - $post_content = preg_replace_callback( | |
| 888 | - '!s:(\d+):"(.*?)";!s', | |
| 889 | - function ( $matches ) { | |
| 890 | - if ( isset( $matches[2] ) ) { | |
| 891 | - return 's:' . strlen( $matches[2] ) . ':"' . $matches[2] . '";'; | |
| 892 | - } | |
| 893 | - }, | |
| 894 | - $post_content | |
| 895 | - ); | |
| 896 | - $data = self::decode_content( $post_content ); | |
| 725 | + $data = unserialize( html_entity_decode( $chart->post_content ) ); | |
| 897 | 726 | $altered = array(); |
| 898 | - if ( ! empty( $data ) ) { | |
| 899 | - foreach ( $data as $index => $array ) { | |
| 900 | - if ( ! is_array( $index ) && is_array( $array ) ) { | |
| 901 | - foreach ( $array as &$datum ) { | |
| 902 | - if ( is_string( $datum ) ) { | |
| 903 | - $datum = stripslashes( $datum ); | |
| 904 | - } | |
| 727 | + foreach ( $data as $index => $array ) { | |
| 728 | + if ( ! is_array( $index ) && is_array( $array ) ) { | |
| 729 | + foreach ( $array as &$datum ) { | |
| 730 | + if ( is_string( $datum ) ) { | |
| 731 | + $datum = stripslashes( $datum ); | |
| 905 | 732 | } |
| 906 | - $altered[ $index ] = $array; | |
| 907 | 733 | } |
| 734 | + $altered[ $index ] = $array; | |
| 908 | 735 | } |
| 909 | 736 | } |
| 910 | 737 | // if something goes wrong and the end result is empty, be safe and use the original data |
| 911 | 738 | if ( empty( $altered ) ) { |
| @@ -914,57 +741,6 @@ | ||
| 914 | 741 | if ( $run_filter ) { |
| 915 | 742 | return apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, $altered, $chart->ID, $type ); |
| 916 | 743 | } |
| 917 | 744 | return $altered; |
| 918 | - } | |
| 919 | - | |
| 920 | - /** | |
| 921 | - * Get chart image. | |
| 922 | - * | |
| 923 | - * @param object $chart Chart data. | |
| 924 | - * @return string | |
| 925 | - */ | |
| 926 | - public function _getImage( $chart = null ) { | |
| 927 | - $image = ''; | |
| 928 | - if ( $chart ) { | |
| 929 | - $chart_image = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ); | |
| 930 | - if ( ! empty( $chart_image ) ) { | |
| 931 | - $image = wp_get_attachment_image( $chart_image, 'full' ); | |
| 932 | - } | |
| 933 | - } | |
| 934 | - return array( | |
| 935 | - 'csv' => $image, | |
| 936 | - ); | |
| 937 | - } | |
| 938 | - | |
| 939 | - /** | |
| 940 | - * Filter chart title if visualizer post type. | |
| 941 | - * | |
| 942 | - * @param object $query WP Query object. | |
| 943 | - * @return void | |
| 944 | - */ | |
| 945 | - public function PreGetPosts( $query ) { | |
| 946 | - if ( ! $query->is_main_query() ) { | |
| 947 | - $post_type = $query->get( 'post_type' ); | |
| 948 | - if ( 'visualizer' === $post_type ) { | |
| 949 | - $this->_addFilter( Visualizer_Plugin::FILTER_CHART_TITLE, 'filterChartTitle', 10, 2 ); | |
| 950 | - } | |
| 951 | - } | |
| 952 | - } | |
| 953 | - | |
| 954 | - /** | |
| 955 | - * Filter chart title. | |
| 956 | - * | |
| 957 | - * @access public | |
| 958 | - * @param string $post_title Post title. | |
| 959 | - * @param int $post_id Post ID. | |
| 960 | - * @return string | |
| 961 | - */ | |
| 962 | - public function filterChartTitle( $post_title, $post_id ) { | |
| 963 | - $post_type = get_post_type( $post_id ); | |
| 964 | - $post_title = trim( $post_title ); | |
| 965 | - if ( 'visualizer' === $post_type && 'Visualization' === $post_title ) { | |
| 966 | - return sprintf( '%s #%d', $post_title, $post_id ); | |
| 967 | - } | |
| 968 | - return $post_title; | |
| 969 | 745 | } |
| 970 | 746 | } |