| @@ -137,9 +137,9 @@ | ||
| 137 | 137 | * @uses add_filter() To register filter hook. |
| 138 | 138 | * |
| 139 | 139 | * @access protected |
| 140 | 140 | * @param string $tag The name of the filter to hook the $method to. |
| 141 | - * @param type $method The name of the method to be called when the filter is applied. | |
| 141 | + * @param string $method The name of the method to be called when the filter is applied. | |
| 142 | 142 | * @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. |
| 143 | 143 | * @param int $accepted_args optional. The number of arguments the function accept (default 1). |
| 144 | 144 | * @return Visualizer_Module |
| 145 | 145 | */ |
| @@ -234,9 +234,8 @@ | ||
| 234 | 234 | $title = 'visualizer#' . $chart_id; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | $filename = $title; |
| 238 | - | |
| 239 | 238 | switch ( $type ) { |
| 240 | 239 | case 'csv': |
| 241 | 240 | $final = $this->_getCSV( $rows, $filename, false ); |
| 242 | 241 | break; |
| @@ -323,11 +322,11 @@ | ||
| 323 | 322 | * @param array $rows The array of data. |
| 324 | 323 | * @param string $filename The name of the file to use. |
| 325 | 324 | */ |
| 326 | 325 | private function _getExcel( $rows, $filename ) { |
| 327 | - // PHPExcel did not like sheet names longer than 31 characters and we will assume the same with PhpSpreadsheet | |
| 328 | - $chart = substr( $filename, 0, 30 ); | |
| 329 | - $filename .= '.xlsx'; | |
| 326 | + // OpenSpout allows for long sheet names, but let's keep the same limit for compatibility. | |
| 327 | + $chart = substr( $filename, 0, 30 ); | |
| 328 | + $filename .= '.xlsx'; | |
| 330 | 329 | if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) { |
| 331 | 330 | unset( $rows[1] ); |
| 332 | 331 | $rows = array_values( $rows ); |
| 333 | 332 | $rows = array_map( |
| @@ -338,24 +337,34 @@ | ||
| 338 | 337 | ); |
| 339 | 338 | } |
| 340 | 339 | $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php'; |
| 341 | 340 | if ( is_readable( $vendor_file ) ) { |
| 342 | - include_once( $vendor_file ); | |
| 341 | + include_once $vendor_file; | |
| 343 | 342 | } |
| 344 | - $xlsData = ''; | |
| 345 | - if ( class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) ) { | |
| 346 | - $doc = new PhpOffice\PhpSpreadsheet\Spreadsheet(); | |
| 347 | - $doc->getActiveSheet()->fromArray( $rows, null, 'A1' ); | |
| 348 | - $doc->getActiveSheet()->setTitle( sanitize_title( $chart ) ); | |
| 349 | - $doc = apply_filters( 'visualizer_excel_doc', $doc ); | |
| 350 | - $writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter( $doc, 'Xlsx' ); | |
| 351 | - ob_start(); | |
| 352 | - $writer->save( 'php://output' ); | |
| 353 | - $xlsData = ob_get_contents(); | |
| 354 | - ob_end_clean(); | |
| 343 | + $xlsData = ''; | |
| 344 | + if ( class_exists( 'OpenSpout\Writer\Common\Creator\WriterEntityFactory' ) ) { | |
| 345 | + try { | |
| 346 | + // Use OpenSpout to create the XLSX file in memory. | |
| 347 | + $writer = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createXLSXWriter(); | |
| 348 | + $writer->openToFile( 'php://output' ); // Open to output instead of a file. | |
| 349 | + $writer->getCurrentSheet()->setName( sanitize_title( $chart ) ); | |
| 350 | + | |
| 351 | + // Write rows. | |
| 352 | + foreach ( $rows as $row ) { | |
| 353 | + $rowFromValues = \OpenSpout\Writer\Common\Creator\WriterEntityFactory::createRowFromArray( $row ); | |
| 354 | + $writer->addRow( $rowFromValues ); | |
| 355 | + } | |
| 356 | + | |
| 357 | + ob_start(); | |
| 358 | + $writer->close(); // Saves and closes the file in the output buffer. | |
| 359 | + $xlsData = ob_get_clean(); | |
| 360 | + } catch ( Exception $e ) { | |
| 361 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'OpenSpout writer error: ' . $e->getMessage(), 'error', __FILE__, __LINE__ ); | |
| 362 | + error_log( 'OpenSpout writer error: ' . $e->getMessage() ); | |
| 363 | + } | |
| 355 | 364 | } else { |
| 356 | - do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!', 'error', __FILE__, __LINE__ ); | |
| 357 | - error_log( 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!' ); | |
| 365 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class OpenSpout\Writer\Common\Creator\WriterEntityFactory does not exist!', 'error', __FILE__, __LINE__ ); | |
| 366 | + error_log( 'Class OpenSpout\Writer\Common\Creator\WriterEntityFactory does not exist!' ); | |
| 358 | 367 | } |
| 359 | 368 | return array( |
| 360 | 369 | 'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ), |
| 361 | 370 | 'name' => $filename, |
| @@ -522,8 +531,12 @@ | ||
| 522 | 531 | |
| 523 | 532 | require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
| 524 | 533 | WP_Filesystem(); |
| 525 | 534 | global $wp_filesystem; |
| 535 | + if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base' ) ) { | |
| 536 | + $creds = request_filesystem_credentials( site_url() ); | |
| 537 | + wp_filesystem( $creds ); | |
| 538 | + } | |
| 526 | 539 | |
| 527 | 540 | $multisite_arg = '/'; |
| 528 | 541 | if ( is_multisite() && ! is_main_site() ) { |
| 529 | 542 | $multisite_arg = '/sites/' . get_current_blog_id() . '/'; |
| @@ -733,13 +746,22 @@ | ||
| 733 | 746 | /** |
| 734 | 747 | * Gets the features for the provided license type. |
| 735 | 748 | */ |
| 736 | 749 | public static final function get_features_for_license( $plan ) { |
| 750 | + $is_new_personal = apply_filters( 'visualizer_is_new_personal', false ); | |
| 737 | 751 | switch ( $plan ) { |
| 738 | 752 | case 1: |
| 739 | - return array( 'import-wp', 'db-query', 'import-wc-report' ); | |
| 753 | + $features = array( 'import-wp', 'import-wc-report', 'import-file', 'import-url' ); | |
| 754 | + if ( ! $is_new_personal ) { | |
| 755 | + $features[] = 'db-query'; | |
| 756 | + } | |
| 757 | + return $features; | |
| 740 | 758 | case 2: |
| 741 | - return array( 'schedule-chart', 'chart-permissions' ); | |
| 759 | + $features = array( 'schedule-chart', 'chart-permissions', 'import-chart', 'data-filter-configuration', 'frontend-actions' ); | |
| 760 | + if ( $is_new_personal ) { | |
| 761 | + $features[] = 'db-query'; | |
| 762 | + } | |
| 763 | + return $features; | |
| 742 | 764 | } |
| 743 | 765 | } |
| 744 | 766 | |
| 745 | 767 | /** |