PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.2.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.2.1
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | classes/Visualizer/Module.php +24 -2 3.1.33.2.1 View file →
@@ -65,8 +65,9 @@
65 65 $this->_plugin = $plugin;
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 + $this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 );
69 70
70 71 }
71 72
72 73 /**
@@ -147,8 +148,17 @@
147 148 return $this;
148 149 }
149 150
150 151 /**
152 + * A wrapper around the actual function _getDataAs. This function is invoked as a filter.
153 + *
154 + * @since 3.2.0
155 + */
156 + public function getDataAs( $final, $chart_id, $type ) {
157 + return $this->_getDataAs( $chart_id, $type );
158 + }
159 +
160 + /**
151 161 * Extracts the data for a chart and prepares it for the given type.
152 162 *
153 163 * @access public
154 164 * @param int $chart_id The chart id.
@@ -158,9 +168,9 @@
158 168 $final = null;
159 169 $success = false;
160 170 if ( $chart_id ) {
161 171 $chart = get_post( $chart_id );
162 - $success = $chart && $chart->post_type == Visualizer_Plugin::CPT_VISUALIZER;
172 + $success = $chart && $chart->post_type === Visualizer_Plugin::CPT_VISUALIZER;
163 173 }
164 174 if ( $success ) {
165 175 $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
166 176 $rows = array();
@@ -222,16 +232,18 @@
222 232 */
223 233 private function _getCSV( $rows, $filename ) {
224 234 $filename .= '.csv';
225 235
236 + $bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF );
226 237 $fp = tmpfile();
227 238 // support for MS Excel
228 - fprintf( $fp, $bom = ( chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF ) ) );
239 + fprintf( $fp, $bom );
229 240 foreach ( $rows as $row ) {
230 241 fputcsv( $fp, $row );
231 242 }
232 243 rewind( $fp );
233 244 $csv = '';
245 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
234 246 while ( ( $array = fgetcsv( $fp ) ) !== false ) {
235 247 if ( strlen( $csv ) > 0 ) {
236 248 $csv .= PHP_EOL;
237 249 }
@@ -241,8 +253,9 @@
241 253
242 254 return array(
243 255 'csv' => $csv,
244 256 'name' => $filename,
257 + 'string' => str_replace( $bom, '', $csv ),
245 258 );
246 259 }
247 260
248 261 /**
@@ -279,8 +292,9 @@
279 292 }
280 293 return array(
281 294 'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ),
282 295 'name' => $filename,
296 + 'raw' => base64_encode( $xlsData ),
283 297 );
284 298 }
285 299
286 300 /**
@@ -310,8 +324,14 @@
310 324
311 325 $table = '<table class="visualizer-print">';
312 326 $index = 0;
313 327 foreach ( $rows as $row ) {
328 + // skip the data type row.
329 + if ( 1 === $index ) {
330 + $index++;
331 + continue;
332 + }
333 +
314 334 $table .= '<tr>';
315 335 foreach ( $row as $col ) {
316 336 if ( $index === 0 ) {
317 337 $table .= '<th>' . $col . '</th>';
@@ -431,8 +451,9 @@
431 451 return $default;
432 452 }
433 453
434 454 if ( ! $wp_filesystem->exists( $dir ) ) {
455 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
435 456 if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
436 457 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
437 458 return $default;
438 459 }
@@ -440,8 +461,9 @@
440 461
441 462 // if file does not exist, copy.
442 463 if ( ! $wp_filesystem->exists( $file ) ) {
443 464 $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
465 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
444 466 if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
445 467 do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
446 468 return $default;
447 469 }