Skip to content

Commit 1bfea09

Browse files
Merge pull request #2 from Codeinwp/development
Development
2 parents 5193bff + e04dfc1 commit 1bfea09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2389
-249
lines changed

.travis.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
language: php
2-
php:
3-
- '7.1'
4-
- '7.0'
5-
- '5.6'
6-
- '5.5'
7-
- '5.4'
82
sudo: false
93
matrix:
104
fast_finish: true
115
include:
12-
- php: '5.6'
13-
install: true
14-
before_script: chmod +x bin/wraith.sh
15-
env: TEST_SUITE=Wraith_Visual_Regression_Testing WRAITH_FAIL=5
16-
script: "./bin/wraith.sh"
17-
- php: '5.3'
18-
dist: precise
6+
- php: 7.2
7+
- php: 7.1
8+
- php: 7.0
9+
- php: '5.6'
10+
install: true
11+
before_script: chmod +x bin/wraith.sh
12+
env: TEST_SUITE=Wraith_Visual_Regression_Testing WRAITH_FAIL=5
13+
script: "./bin/wraith.sh"
14+
- php: 5.5
15+
env: WP_VERSION=5.1
16+
- php: 5.4
17+
env: WP_VERSION=5.1
18+
- php: 5.3
19+
env: WP_VERSION=5.1
20+
dist: precise
1921
allow_failures:
2022
- env: TEST_SUITE=Wraith_Visual_Regression_Testing WRAITH_FAIL=5
2123
branches:

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11

2+
### v3.2.0 - 2019-05-03
3+
**Changes:**
4+
* Add support for charts in AMP requests
5+
* Add support to show charts from JSON/REST endpoints
6+
* Fix loading of Google Visualization javascript files
7+
* Add simple editors for editing chart data
8+
* Tested up to WP 5.2
9+
10+
### v3.1.3 - 2019-02-24
11+
**Changes:**
12+
* Fix issue with changing column settings of the last column in table chart
13+
* Add support for query language to get subset of data from Google Spreadsheet
14+
* Fix conflict with jquery 3.3.x
15+
* Migrated PHPExcel to PhpSpreadsheet
16+
* Front end action 'print' should print the chart and fall back to printing the data
17+
* Fix issue with table chart not showing in IE
18+
* Fix issue with multiple instances of same chart not showing
19+
* Fix issue with date type column does not work with Combo charts
20+
* Tested with WP 5.1
21+
22+
### v3.1.2 - 2018-12-06
23+
**Changes:**
24+
* Fix bug "Warning: A non-numeric value encountered"
25+
* Tested with WP 5.0
26+
227
### v3.1.1 - 2018-12-05
328
**Changes:**
429
* Fix issue with Gutenberg support

classes/Visualizer/Gutenberg/Block.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Visualizer_Gutenberg_Block {
4646
* Returns an instance of this class.
4747
*/
4848
public static function get_instance() {
49-
if ( null == self::$instance ) {
49+
if ( null === self::$instance ) {
5050
self::$instance = new Visualizer_Gutenberg_Block();
5151
}
5252
return self::$instance;
@@ -86,7 +86,7 @@ public function enqueue_gutenberg_scripts() {
8686
if ( VISUALIZER_PRO ) {
8787
$type = 'pro';
8888
if ( apply_filters( 'visualizer_is_business', false ) ) {
89-
$type = 'business';
89+
$type = 'developer';
9090
}
9191
}
9292

@@ -121,11 +121,13 @@ public function register_block_type() {
121121
* Gutenberg Block Callback Function
122122
*/
123123
public function gutenberg_block_callback( $attr ) {
124-
$id = $attr['id'];
125-
if ( empty( $id ) || $id === 'none' ) {
126-
return ''; // no id = no fun
124+
if ( isset( $attr['id'] ) ) {
125+
$id = $attr['id'];
126+
if ( empty( $id ) || $id === 'none' ) {
127+
return ''; // no id = no fun
128+
}
129+
return '[visualizer id="' . $id . '"]';
127130
}
128-
return '[visualizer id="' . $id . '"]';
129131
}
130132

131133
/**
@@ -295,19 +297,19 @@ public function format_chart_data( $data, $series ) {
295297
continue;
296298
}
297299

298-
if ( $row['type'] == 'number' ) {
300+
if ( $row['type'] === 'number' ) {
299301
foreach ( $data as $o => $col ) {
300302
$data[ $o ][ $i ] = ( is_numeric( $col[ $i ] ) ) ? floatval( $col[ $i ] ) : ( is_numeric( str_replace( ',', '', $col[ $i ] ) ) ? floatval( str_replace( ',', '', $col[ $i ] ) ) : null );
301303
}
302304
}
303305

304-
if ( $row['type'] == 'boolean' ) {
306+
if ( $row['type'] === 'boolean' ) {
305307
foreach ( $data as $o => $col ) {
306308
$data[ $o ][ $i ] = ! empty( $col[ $i ] ) ? filter_validate( $col[ $i ], FILTER_VALIDATE_BOOLEAN ) : null;
307309
}
308310
}
309311

310-
if ( $row['type'] == 'timeofday' ) {
312+
if ( $row['type'] === 'timeofday' ) {
311313
foreach ( $data as $o => $col ) {
312314
$date = new DateTime( '1984-03-16T' . $col[ $i ] );
313315
if ( $date ) {
@@ -321,7 +323,7 @@ public function format_chart_data( $data, $series ) {
321323
}
322324
}
323325

324-
if ( $row['type'] == 'string' ) {
326+
if ( $row['type'] === 'string' ) {
325327
foreach ( $data as $o => $col ) {
326328
$data[ $o ][ $i ] = $this->toUTF8( $col[ $i ] );
327329
}

classes/Visualizer/Module.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
6666

6767
$this->_addFilter( Visualizer_Plugin::FILTER_UNDO_REVISIONS, 'undoRevisions', 10, 2 );
6868
$this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 );
69+
$this->_addFilter( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, 'getDataAs', 10, 3 );
6970

7071
}
7172

@@ -147,6 +148,15 @@ protected function _addShortcode( $tag, $method ) {
147148
return $this;
148149
}
149150

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+
150160
/**
151161
* Extracts the data for a chart and prepares it for the given type.
152162
*
@@ -159,7 +169,7 @@ public function _getDataAs( $chart_id, $type ) {
159169
$success = false;
160170
if ( $chart_id ) {
161171
$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;
163173
}
164174
if ( $success ) {
165175
$settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true );
@@ -223,14 +233,16 @@ public function _getDataAs( $chart_id, $type ) {
223233
private function _getCSV( $rows, $filename ) {
224234
$filename .= '.csv';
225235

236+
$bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF );
226237
$fp = tmpfile();
227238
// support for MS Excel
228-
fprintf( $fp, $bom = ( chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF ) ) );
239+
fprintf( $fp, $bom );
229240
foreach ( $rows as $row ) {
230241
fputcsv( $fp, $row );
231242
}
232243
rewind( $fp );
233244
$csv = '';
245+
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
234246
while ( ( $array = fgetcsv( $fp ) ) !== false ) {
235247
if ( strlen( $csv ) > 0 ) {
236248
$csv .= PHP_EOL;
@@ -242,6 +254,7 @@ private function _getCSV( $rows, $filename ) {
242254
return array(
243255
'csv' => $csv,
244256
'name' => $filename,
257+
'string' => str_replace( $bom, '', $csv ),
245258
);
246259
}
247260

@@ -253,28 +266,34 @@ private function _getCSV( $rows, $filename ) {
253266
* @param string $filename The name of the file to use.
254267
*/
255268
private function _getExcel( $rows, $filename ) {
256-
// PHPExcel does not like sheet names longer than 31 characters.
269+
// PHPExcel did not like sheet names longer than 31 characters and we will assume the same with PhpSpreadsheet
257270
$chart = substr( $filename, 0, 30 );
258271
$filename .= '.xlsx';
259272

273+
$vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php';
274+
if ( is_readable( $vendor_file ) ) {
275+
include_once( $vendor_file );
276+
}
277+
260278
$xlsData = '';
261-
if ( class_exists( 'PHPExcel' ) ) {
262-
$doc = new PHPExcel();
279+
if ( class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) ) {
280+
$doc = new PhpOffice\PhpSpreadsheet\Spreadsheet();
263281
$doc->getActiveSheet()->fromArray( $rows, null, 'A1' );
264282
$doc->getActiveSheet()->setTitle( sanitize_title( $chart ) );
265283
$doc = apply_filters( 'visualizer_excel_doc', $doc );
266-
$writer = PHPExcel_IOFactory::createWriter( $doc, 'Excel2007' );
284+
$writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter( $doc, 'Xlsx' );
267285
ob_start();
268286
$writer->save( 'php://output' );
269287
$xlsData = ob_get_contents();
270288
ob_end_clean();
271289
} else {
272-
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PHPExcel does not exist!', 'error', __FILE__, __LINE__ );
273-
error_log( 'Class PHPExcel does not exist!' );
290+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!', 'error', __FILE__, __LINE__ );
291+
error_log( 'Class PhpOffice\PhpSpreadsheet\Spreadsheet does not exist!' );
274292
}
275293
return array(
276294
'csv' => 'data:application/vnd.ms-excel;base64,' . base64_encode( $xlsData ),
277295
'name' => $filename,
296+
'raw' => base64_encode( $xlsData ),
278297
);
279298
}
280299

@@ -306,6 +325,12 @@ private function _getHTML( $rows ) {
306325
$table = '<table class="visualizer-print">';
307326
$index = 0;
308327
foreach ( $rows as $row ) {
328+
// skip the data type row.
329+
if ( 1 === $index ) {
330+
$index++;
331+
continue;
332+
}
333+
309334
$table .= '<tr>';
310335
foreach ( $row as $col ) {
311336
if ( $index === 0 ) {
@@ -427,6 +452,7 @@ protected function get_user_customization_js() {
427452
}
428453

429454
if ( ! $wp_filesystem->exists( $dir ) ) {
455+
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
430456
if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
431457
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
432458
return $default;
@@ -436,6 +462,7 @@ protected function get_user_customization_js() {
436462
// if file does not exist, copy.
437463
if ( ! $wp_filesystem->exists( $file ) ) {
438464
$src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
465+
// phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
439466
if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
440467
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
441468
return $default;

classes/Visualizer/Module/AMP.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
// +----------------------------------------------------------------------+
3+
// | Copyright 2013 Madpixels (email : [email protected]) |
4+
// +----------------------------------------------------------------------+
5+
// | This program is free software; you can redistribute it and/or modify |
6+
// | it under the terms of the GNU General Public License, version 2, as |
7+
// | published by the Free Software Foundation. |
8+
// | |
9+
// | This program is distributed in the hope that it will be useful, |
10+
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11+
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12+
// | GNU General Public License for more details. |
13+
// | |
14+
// | You should have received a copy of the GNU General Public License |
15+
// | along with this program; if not, write to the Free Software |
16+
// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
17+
// | MA 02110-1301 USA |
18+
// +----------------------------------------------------------------------+
19+
// | Author: Eugene Manuilov <[email protected]> |
20+
// +----------------------------------------------------------------------+
21+
/**
22+
* The module for all AMP stuff.
23+
*
24+
* @category Visualizer
25+
* @package Module
26+
*
27+
* @since 1.0.0
28+
*/
29+
class Visualizer_Module_AMP extends Visualizer_Module {
30+
31+
const NAME = __CLASS__;
32+
33+
/**
34+
* Constructor.
35+
*
36+
* @since 1.0.0
37+
*
38+
* @access public
39+
*
40+
* @param Visualizer_Plugin $plugin The instance of the plugin.
41+
*/
42+
public function __construct( Visualizer_Plugin $plugin ) {
43+
$this->_addFilter( 'amp_post_template_data', 'addToHeader' );
44+
}
45+
46+
/**
47+
* Add the iframe component to the header.
48+
*/
49+
public function addToHeader( $data ) {
50+
$data['amp_component_scripts'] = array_merge(
51+
$data['amp_component_scripts'],
52+
array(
53+
'amp-iframe' => 'https://cdn.ampproject.org/v0/amp-iframe-latest.js',
54+
)
55+
);
56+
return $data;
57+
}
58+
59+
/**
60+
* Is this an AMP request?
61+
*/
62+
public static function is_amp() {
63+
return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
64+
}
65+
66+
/**
67+
* Loads the alterview view of the chart.
68+
*/
69+
public function get_chart( $chart, $data, $series, $settings ) {
70+
$view = apply_filters( 'visualizer_amp_view', null, $chart, $data, $series, $settings );
71+
if ( ! is_null( $view ) ) {
72+
return $view;
73+
}
74+
$output = $this->_getDataAs( $chart->ID, 'print' );
75+
return $output['csv'];
76+
}
77+
78+
}

0 commit comments

Comments
 (0)