From 620327d9700a9ab2ff615caa73dc5d6f5936a4ad Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Thu, 9 Aug 2018 18:13:03 +0530 Subject: [PATCH 01/12] Add ability to add user specific javascript customization #294 --- classes/Visualizer/Module/Admin.php | 2 ++ classes/Visualizer/Module/Chart.php | 2 ++ classes/Visualizer/Module/Frontend.php | 3 ++- js/customization.js | 17 +++++++++++++++++ js/render.js | 10 +++++++--- 5 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 js/customization.js diff --git a/classes/Visualizer/Module/Admin.php b/classes/Visualizer/Module/Admin.php index 02a60bcb..021bfe0a 100644 --- a/classes/Visualizer/Module/Admin.php +++ b/classes/Visualizer/Module/Admin.php @@ -410,10 +410,12 @@ public function enqueueLibraryScripts( $suffix ) { ); wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); + wp_enqueue_script( 'visualizer-customization', VISUALIZER_ABSURL . 'js/customization.js', array(), null, true ); wp_enqueue_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi-old', 'visualizer-library', + 'visualizer-customization', ), Visualizer_Plugin::VERSION, true ); } diff --git a/classes/Visualizer/Module/Chart.php b/classes/Visualizer/Module/Chart.php index 505eeffa..c71f5958 100644 --- a/classes/Visualizer/Module/Chart.php +++ b/classes/Visualizer/Module/Chart.php @@ -244,11 +244,13 @@ public function renderChartPages() { wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true ); wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); + wp_register_script( 'visualizer-customization', VISUALIZER_ABSURL . 'js/customization.js', array(), null, true ); wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi-old', 'google-jsapi-new', 'visualizer-frame', + 'visualizer-customization', ), Visualizer_Plugin::VERSION, true ); wp_register_script( diff --git a/classes/Visualizer/Module/Frontend.php b/classes/Visualizer/Module/Frontend.php index 10d95fff..36c4afcb 100644 --- a/classes/Visualizer/Module/Frontend.php +++ b/classes/Visualizer/Module/Frontend.php @@ -157,7 +157,8 @@ public function perform_action( WP_REST_Request $params ) { public function enqueueScripts() { wp_register_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); wp_register_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true ); - wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery' ), Visualizer_Plugin::VERSION, true ); + wp_register_script( 'visualizer-customization', VISUALIZER_ABSURL . 'js/customization.js', array(), null, true ); + wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery', 'visualizer-customization' ), Visualizer_Plugin::VERSION, true ); wp_register_script( 'visualizer-clipboardjs', VISUALIZER_ABSURL . 'js/lib/clipboardjs/clipboard.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION ); do_action( 'visualizer_pro_frontend_load_resources' ); diff --git a/js/customization.js b/js/customization.js new file mode 100644 index 00000000..e149649e --- /dev/null +++ b/js/customization.js @@ -0,0 +1,17 @@ +// user specific customizations +(function ($) { + $(document).ready(function(){ + $('body').on('visualizer:format:chart', function(event, data){ + customize_format(data.id, data.data, data.column); + }); + }); + + function customize_format($id, $data, $column) { +/* example add green/red arrows to the specified column of the specified chart + if($id === 359 && $column === 1) { + var formatter = new google.visualization.ArrowFormat(); + formatter.format($data, $column); + } +*/ + } +})(jQuery); \ No newline at end of file diff --git a/js/render.js b/js/render.js index a7d30d2d..bb290f37 100644 --- a/js/render.js +++ b/js/render.js @@ -186,7 +186,7 @@ var __visualizer_chart_images = []; case 'table': for(i in settings.series){ i = parseInt(i); - v.format_data(table, series[i + 1].type, settings.series[i].format, i + 1); + v.format_data(id, table, series[i + 1].type, settings.series[i].format, i + 1); } break; default: @@ -194,7 +194,7 @@ var __visualizer_chart_images = []; if (!series[i + 1]) { continue; } - v.format_data(table, series[i + 1].type, settings.series[i].format, i + 1); + v.format_data(id, table, series[i + 1].type, settings.series[i].format, i + 1); } break; } @@ -217,7 +217,7 @@ var __visualizer_chart_images = []; render.draw(table, settings); }; - v.format_data = function(table, type, format, index) { + v.format_data = function(id, table, type, format, index) { if (!format || format === '') { return; } @@ -237,6 +237,10 @@ var __visualizer_chart_images = []; if (formatter) { formatter.format(table, index); } + + var arr = id.split('-'); + jQuery('body').trigger('visualizer:format:chart', {id: parseInt(arr[1]), data: table, column: index}); + }; v.override = function(settings) { From 1bb1df4a7a5c45036f8f1468d413aa45da4ba676 Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Fri, 10 Aug 2018 09:58:29 +0530 Subject: [PATCH 02/12] pie chart as well --- js/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/render.js b/js/render.js index bb290f37..c2ac74c4 100644 --- a/js/render.js +++ b/js/render.js @@ -199,7 +199,7 @@ var __visualizer_chart_images = []; break; } } else if (chart.type === 'pie' && settings.format && settings.format !== '') { - v.format_data(table, 'number', settings.format, 1); + v.format_data(id, table, 'number', settings.format, 1); } v.override(settings); From 6a67da486cd96c180fa89d7b0d5b479b1fd5f275 Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Wed, 22 Aug 2018 20:49:45 +0530 Subject: [PATCH 03/12] Scheduled charts cannot be viewed on the front end once they get updated at their scheduled time #296 --- classes/Visualizer/Module/Frontend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Visualizer/Module/Frontend.php b/classes/Visualizer/Module/Frontend.php index 10d95fff..2230b31e 100644 --- a/classes/Visualizer/Module/Frontend.php +++ b/classes/Visualizer/Module/Frontend.php @@ -228,7 +228,7 @@ public function renderChart( $atts ) { } // handle data filter hooks - $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type ); + $data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type ); if ( ! empty( $atts['data'] ) ) { $data = apply_filters( $atts['data'], $data, $chart->ID, $type ); } From 41c808d70683c060df0abcec76e9d4a0b1e0541f Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Mon, 10 Sep 2018 09:43:10 +0100 Subject: [PATCH 04/12] Scheduled charts: add filter to enable users to change schedule of charts #298 --- classes/Visualizer/Render/Page/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Visualizer/Render/Page/Data.php b/classes/Visualizer/Render/Page/Data.php index 8e284724..825e1d6d 100644 --- a/classes/Visualizer/Render/Page/Data.php +++ b/classes/Visualizer/Render/Page/Data.php @@ -135,12 +135,12 @@ class="visualizer-input visualizer-remote-url"> class="visualizer-select"> chart->ID, Visualizer_Plugin::CF_CHART_SCHEDULE, true ); - $schedules = array( + $schedules = apply_filters( 'visualizer_chart_schedules', array( '1' => __( 'Each hour', 'visualizer' ), '12' => __( 'Each 12 hours', 'visualizer' ), '24' => __( 'Each day', 'visualizer' ), '36' => __( 'Each 3 days', 'visualizer' ), - ); + ) ); foreach ( $schedules as $num => $name ) { $extra = $num == $hours ? 'selected' : ''; ?> From 66ec5d559c00916ea7ae78ba4139fa2adb627c6e Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Mon, 10 Sep 2018 10:10:46 +0100 Subject: [PATCH 05/12] grunt --- classes/Visualizer/Render/Page/Data.php | 14 ++++++++------ phpcs.xml | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/classes/Visualizer/Render/Page/Data.php b/classes/Visualizer/Render/Page/Data.php index 825e1d6d..43b5fc9f 100644 --- a/classes/Visualizer/Render/Page/Data.php +++ b/classes/Visualizer/Render/Page/Data.php @@ -135,12 +135,14 @@ class="visualizer-input visualizer-remote-url"> class="visualizer-select"> chart->ID, Visualizer_Plugin::CF_CHART_SCHEDULE, true ); - $schedules = apply_filters( 'visualizer_chart_schedules', array( - '1' => __( 'Each hour', 'visualizer' ), - '12' => __( 'Each 12 hours', 'visualizer' ), - '24' => __( 'Each day', 'visualizer' ), - '36' => __( 'Each 3 days', 'visualizer' ), - ) ); + $schedules = apply_filters( + 'visualizer_chart_schedules', array( + '1' => __( 'Each hour', 'visualizer' ), + '12' => __( 'Each 12 hours', 'visualizer' ), + '24' => __( 'Each day', 'visualizer' ), + '36' => __( 'Each 3 days', 'visualizer' ), + ) + ); foreach ( $schedules as $num => $name ) { $extra = $num == $hours ? 'selected' : ''; ?> diff --git a/phpcs.xml b/phpcs.xml index 671509dd..4a40fd36 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -31,6 +31,7 @@ + From ff763fa06b92d211f837903bb5242dfc5fe1c6e2 Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Fri, 21 Sep 2018 21:01:29 +0530 Subject: [PATCH 06/12] Line chart with timeofday column does not show properly when edited. #300 --- js/render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/render.js b/js/render.js index 9f8e9d12..0611ed6e 100644 --- a/js/render.js +++ b/js/render.js @@ -118,7 +118,7 @@ var __visualizer_chart_images = []; return; } - if (series[0] && (series[0].type === 'date' || series[0].type === 'datetime')) { + if (series[0] && (series[0].type === 'date' || series[0].type === 'datetime' || series[0].type === 'timeofday')) { axis = false; switch (chart.type) { case 'line': From ad5972d4e75c6083e83c6700059fc63b94827513 Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Fri, 21 Sep 2018 21:15:26 +0530 Subject: [PATCH 07/12] travis failure --- .travis.yml | 2 ++ phpcs.xml | 1 + 2 files changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index a6387ef8..ffa89d09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,3 +72,5 @@ deploy: after_deploy: - chmod +x bin/deploy.sh - ". ./bin/deploy.sh" +after_failure: +- cat "logs/phpcs.log" \ No newline at end of file diff --git a/phpcs.xml b/phpcs.xml index 671509dd..e4a56ffa 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -31,6 +31,7 @@ + From 9c62d5735ca7dbba8977878662d2c277971f5e24 Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Wed, 26 Sep 2018 14:39:08 +0530 Subject: [PATCH 08/12] use file from uploads --- classes/Visualizer/Module.php | 50 ++++++++++++++++++++++++++ classes/Visualizer/Module/Admin.php | 2 +- classes/Visualizer/Module/Chart.php | 2 +- classes/Visualizer/Module/Frontend.php | 2 +- index.php | 13 +++++++ 5 files changed, 66 insertions(+), 3 deletions(-) diff --git a/classes/Visualizer/Module.php b/classes/Visualizer/Module.php index a1bba840..2db9c699 100644 --- a/classes/Visualizer/Module.php +++ b/classes/Visualizer/Module.php @@ -395,4 +395,54 @@ protected function get_language() { return reset( $array ); } + /** + * Gets/creates the JS where user-specific customizations can be/have been added. + */ + protected function get_user_customization_js() { + // use this as the JS file in case we are not able to create the file in uploads. + $default = VISUALIZER_ABSURL . 'js/customization.js'; + + $uploads = wp_get_upload_dir(); + $specific = $uploads['baseurl'] . '/visualizer/customization.js'; + + // for testing on user sites (before we send them the correctly customized file). + if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) { + return $default; + } + + require_once( ABSPATH . 'wp-admin/includes/file.php' ); + WP_Filesystem(); + global $wp_filesystem; + + $dir = $wp_filesystem->wp_content_dir() . 'uploads/visualizer'; + $file = $wp_filesystem->wp_content_dir() . 'uploads/visualizer/customization.js'; + + if ( $wp_filesystem->is_readable( $file ) ) { + return $specific; + } + + if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) { + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ ); + return $default; + } + + if ( ! $wp_filesystem->exists( $dir ) ) { + if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) { + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ ); + return $default; + } + } + + // if file does not exist, copy. + if ( ! $wp_filesystem->exists( $file ) ) { + $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' ); + if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) { + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ ); + return $default; + } + } + + return $specific; + } + } diff --git a/classes/Visualizer/Module/Admin.php b/classes/Visualizer/Module/Admin.php index 021bfe0a..649368bb 100644 --- a/classes/Visualizer/Module/Admin.php +++ b/classes/Visualizer/Module/Admin.php @@ -410,7 +410,7 @@ public function enqueueLibraryScripts( $suffix ) { ); wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); - wp_enqueue_script( 'visualizer-customization', VISUALIZER_ABSURL . 'js/customization.js', array(), null, true ); + wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); wp_enqueue_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi-old', diff --git a/classes/Visualizer/Module/Chart.php b/classes/Visualizer/Module/Chart.php index c71f5958..62b02b9b 100644 --- a/classes/Visualizer/Module/Chart.php +++ b/classes/Visualizer/Module/Chart.php @@ -244,7 +244,7 @@ public function renderChartPages() { wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true ); wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); - wp_register_script( 'visualizer-customization', VISUALIZER_ABSURL . 'js/customization.js', array(), null, true ); + wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'google-jsapi-old', diff --git a/classes/Visualizer/Module/Frontend.php b/classes/Visualizer/Module/Frontend.php index 36c4afcb..c13d22d1 100644 --- a/classes/Visualizer/Module/Frontend.php +++ b/classes/Visualizer/Module/Frontend.php @@ -157,7 +157,7 @@ public function perform_action( WP_REST_Request $params ) { public function enqueueScripts() { wp_register_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); wp_register_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true ); - wp_register_script( 'visualizer-customization', VISUALIZER_ABSURL . 'js/customization.js', array(), null, true ); + wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery', 'visualizer-customization' ), Visualizer_Plugin::VERSION, true ); wp_register_script( 'visualizer-clipboardjs', VISUALIZER_ABSURL . 'js/lib/clipboardjs/clipboard.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION ); diff --git a/index.php b/index.php index a16e0be4..16844f74 100644 --- a/index.php +++ b/index.php @@ -69,6 +69,9 @@ function visualizer_launch() { define( 'VISUALIZER_ABSURL', plugins_url( '/', __FILE__ ) ); define( 'VISUALIZER_ABSPATH', dirname( __FILE__ ) ); define( 'VISUALIZER_REST_VERSION', 1 ); + // if the below is true, then the js/customization.js in the plugin folder will be used instead of the one in the uploads folder (if it exists). + define( 'VISUALIZER_TEST_JS_CUSTOMIZATION', false ); + if ( ! defined( 'VISUALIZER_CSV_DELIMITER' ) ) { define( 'VISUALIZER_CSV_DELIMITER', ',' ); } @@ -126,3 +129,13 @@ function visualizer_register_parrot( $plugins ) { spl_autoload_register( 'visualizer_autoloader' ); // launch the plugin visualizer_launch(); + + +/* uncomment only for local/testing */ +//add_action( 'themeisle_log_event', 'visualizer_themeisle_log_event', 10, 5 ); +function visualizer_themeisle_log_event( $name, $msg, $type, $file, $line ) { + if ( $name !== Visualizer_Plugin::NAME ) { + return; + } + error_log( sprintf( '%s: %s in %s on %s', $type, $msg, $file, $line ) ); +} From 6ffed4675f49a9170fe40aef58480b5848adfa34 Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Wed, 26 Sep 2018 15:00:24 +0530 Subject: [PATCH 09/12] grunt --- classes/Visualizer/Module.php | 12 +++--- classes/Visualizer/Module/Admin.php | 38 ++++++++++++++----- classes/Visualizer/Module/Chart.php | 50 +++++++++++++++++++------ classes/Visualizer/Module/Frontend.php | 10 +++-- classes/Visualizer/Module/Setup.php | 3 +- classes/Visualizer/Render/Library.php | 9 +++-- classes/Visualizer/Render/Page/Data.php | 17 ++++++--- classes/Visualizer/Render/Sidebar.php | 3 +- index.php | 10 ----- phpcs.xml | 2 + 10 files changed, 103 insertions(+), 51 deletions(-) diff --git a/classes/Visualizer/Module.php b/classes/Visualizer/Module.php index 2db9c699..183ba5bf 100644 --- a/classes/Visualizer/Module.php +++ b/classes/Visualizer/Module.php @@ -400,10 +400,10 @@ protected function get_language() { */ protected function get_user_customization_js() { // use this as the JS file in case we are not able to create the file in uploads. - $default = VISUALIZER_ABSURL . 'js/customization.js'; + $default = VISUALIZER_ABSURL . 'js/customization.js'; - $uploads = wp_get_upload_dir(); - $specific = $uploads['baseurl'] . '/visualizer/customization.js'; + $uploads = wp_get_upload_dir(); + $specific = $uploads['baseurl'] . '/visualizer/customization.js'; // for testing on user sites (before we send them the correctly customized file). if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) { @@ -414,8 +414,8 @@ protected function get_user_customization_js() { WP_Filesystem(); global $wp_filesystem; - $dir = $wp_filesystem->wp_content_dir() . 'uploads/visualizer'; - $file = $wp_filesystem->wp_content_dir() . 'uploads/visualizer/customization.js'; + $dir = $wp_filesystem->wp_content_dir() . 'uploads/visualizer'; + $file = $wp_filesystem->wp_content_dir() . 'uploads/visualizer/customization.js'; if ( $wp_filesystem->is_readable( $file ) ) { return $specific; @@ -435,7 +435,7 @@ protected function get_user_customization_js() { // if file does not exist, copy. if ( ! $wp_filesystem->exists( $file ) ) { - $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' ); + $src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' ); if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) { do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ ); return $default; diff --git a/classes/Visualizer/Module/Admin.php b/classes/Visualizer/Module/Admin.php index 649368bb..d8a664f5 100644 --- a/classes/Visualizer/Module/Admin.php +++ b/classes/Visualizer/Module/Admin.php @@ -220,7 +220,9 @@ public function enqueueMediaScripts() { wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true ); wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true ); wp_localize_script( - 'visualizer-media-view', 'visualizer', array( + 'visualizer-media-view', + 'visualizer', + array( 'i10n' => array( 'insert' => __( 'Insert', 'visualizer' ), ), @@ -286,7 +288,8 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra } $types = array_merge( - $additional, array( + $additional, + array( 'pie' => array( 'name' => esc_html__( 'Pie', 'visualizer' ), 'enabled' => true, @@ -403,20 +406,28 @@ public function enqueueLibraryScripts( $suffix ) { $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' ); wp_enqueue_media(); wp_enqueue_script( - 'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array( + 'visualizer-library', + VISUALIZER_ABSURL . 'js/library.js', + array( 'jquery', 'media-views', - ), Visualizer_Plugin::VERSION, true + ), + Visualizer_Plugin::VERSION, + true ); wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true ); wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); wp_enqueue_script( - 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( + 'visualizer-render', + VISUALIZER_ABSURL . 'js/render.js', + array( 'google-jsapi-old', 'visualizer-library', 'visualizer-customization', - ), Visualizer_Plugin::VERSION, true + ), + Visualizer_Plugin::VERSION, + true ); } } @@ -461,7 +472,10 @@ public function registerAdminMenu() { public function renderLibraryPage() { // get current page $page = filter_input( - INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array( + INPUT_GET, + 'vpage', + FILTER_VALIDATE_INT, + array( 'options' => array( 'min_range' => 1, 'default' => 1, @@ -527,7 +541,9 @@ public function renderLibraryPage() { // enqueue charts array $ajaxurl = admin_url( 'admin-ajax.php' ); wp_localize_script( - 'visualizer-library', 'visualizer', array( + 'visualizer-library', + 'visualizer', + array( 'language' => $this->get_language(), 'map_api_key' => get_option( 'visualizer-map-api-key' ), 'charts' => $charts, @@ -538,13 +554,15 @@ public function renderLibraryPage() { 'action' => Visualizer_Plugin::ACTION_CREATE_CHART, 'library' => 'yes', 'type' => isset( $_GET['type'] ) ? $_GET['type'] : '', - ), $ajaxurl + ), + $ajaxurl ), 'edit' => add_query_arg( array( 'action' => Visualizer_Plugin::ACTION_EDIT_CHART, 'library' => 'yes', - ), $ajaxurl + ), + $ajaxurl ), ), ) diff --git a/classes/Visualizer/Module/Chart.php b/classes/Visualizer/Module/Chart.php index 62b02b9b..261fa3e6 100644 --- a/classes/Visualizer/Module/Chart.php +++ b/classes/Visualizer/Module/Chart.php @@ -72,7 +72,10 @@ public function getCharts() { 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, 'posts_per_page' => 9, 'paged' => filter_input( - INPUT_GET, 'page', FILTER_VALIDATE_INT, array( + INPUT_GET, + 'page', + FILTER_VALIDATE_INT, + array( 'options' => array( 'min_range' => 1, 'default' => 1, @@ -171,7 +174,10 @@ public function deleteChart() { $capable = current_user_can( 'delete_posts' ); if ( $nonce && $capable ) { $chart_id = filter_input( - $input_method, 'chart', FILTER_VALIDATE_INT, array( + $input_method, + 'chart', + FILTER_VALIDATE_INT, + array( 'options' => array( 'min_range' => 1, ), @@ -227,7 +233,9 @@ public function renderChartPages() { add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); add_post_meta( - $chart_id, Visualizer_Plugin::CF_SETTINGS, array( + $chart_id, + Visualizer_Plugin::CF_SETTINGS, + array( 'focusTarget' => 'datum', ) ); @@ -246,18 +254,26 @@ public function renderChartPages() { wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true ); wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); wp_register_script( - 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( + 'visualizer-render', + VISUALIZER_ABSURL . 'js/render.js', + array( 'google-jsapi-old', 'google-jsapi-new', 'visualizer-frame', 'visualizer-customization', - ), Visualizer_Plugin::VERSION, true + ), + Visualizer_Plugin::VERSION, + true ); wp_register_script( - 'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array( + 'visualizer-preview', + VISUALIZER_ABSURL . 'js/preview.js', + array( 'wp-color-picker', 'visualizer-render', - ), Visualizer_Plugin::VERSION, true + ), + Visualizer_Plugin::VERSION, + true ); // added by Ash/Upwork if ( VISUALIZER_PRO ) { @@ -346,7 +362,9 @@ private function _handleDataAndSettingsPage() { wp_enqueue_script( 'visualizer-preview' ); wp_enqueue_script( 'visualizer-render' ); wp_localize_script( - 'visualizer-render', 'visualizer', array( + 'visualizer-render', + 'visualizer', + array( 'l10n' => array( 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), 'loading' => esc_html__( 'Loading...', 'visualizer' ), @@ -527,7 +545,10 @@ public function cloneChart() { $capable = current_user_can( 'edit_posts' ); if ( $nonce && $capable ) { $chart_id = filter_input( - INPUT_GET, 'chart', FILTER_VALIDATE_INT, array( + INPUT_GET, + 'chart', + FILTER_VALIDATE_INT, + array( 'options' => array( 'min_range' => 1, ), @@ -559,7 +580,8 @@ public function cloneChart() { array( 'page' => 'visualizer', 'type' => filter_input( INPUT_GET, 'type' ), - ), admin_url( 'upload.php' ) + ), + admin_url( 'upload.php' ) ); } } @@ -579,7 +601,9 @@ public function exportData() { $capable = current_user_can( 'edit_posts' ); if ( $capable ) { $chart_id = isset( $_GET['chart'] ) ? filter_var( - $_GET['chart'], FILTER_VALIDATE_INT, array( + $_GET['chart'], + FILTER_VALIDATE_INT, + array( 'options' => array( 'min_range' => 1, ), @@ -612,7 +636,9 @@ private function _handleDataPage() { wp_enqueue_style( 'visualizer-frame' ); wp_enqueue_script( 'visualizer-render' ); wp_localize_script( - 'visualizer-render', 'visualizer', array( + 'visualizer-render', + 'visualizer', + array( 'l10n' => array( 'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ), 'loading' => esc_html__( 'Loading...', 'visualizer' ), diff --git a/classes/Visualizer/Module/Frontend.php b/classes/Visualizer/Module/Frontend.php index c13d22d1..1f590bae 100644 --- a/classes/Visualizer/Module/Frontend.php +++ b/classes/Visualizer/Module/Frontend.php @@ -99,7 +99,8 @@ function endpoint_register() { */ private function get_actions() { return apply_filters( - 'visualizer_action_buttons', array( + 'visualizer_action_buttons', + array( 'print' => __( 'Print', 'visualizer' ), 'csv' => __( 'CSV', 'visualizer' ), 'xls' => __( 'Excel', 'visualizer' ), @@ -186,7 +187,8 @@ public function renderChart( $atts ) { 'series' => false, // series filter hook 'data' => false, // data filter hook 'settings' => false, // data filter hook - ), $atts + ), + $atts ); // if empty id or chart does not exists, then return empty string @@ -254,7 +256,9 @@ public function renderChart( $atts ) { // enqueue visualizer render and update render localizations wp_enqueue_script( 'visualizer-render' ); wp_localize_script( - 'visualizer-render', 'visualizer', array( + 'visualizer-render', + 'visualizer', + array( 'charts' => $this->_charts, 'language' => $this->get_language(), 'map_api_key' => get_option( 'visualizer-map-api-key' ), diff --git a/classes/Visualizer/Module/Setup.php b/classes/Visualizer/Module/Setup.php index 083425b3..9df9e16f 100644 --- a/classes/Visualizer/Module/Setup.php +++ b/classes/Visualizer/Module/Setup.php @@ -107,7 +107,8 @@ public function getChartCountsByTypeAndMeta( $meta_keys = array() ) { */ public function setupCustomPostTypes() { register_post_type( - Visualizer_Plugin::CPT_VISUALIZER, array( + Visualizer_Plugin::CPT_VISUALIZER, + array( 'label' => 'Visualizer Charts', 'public' => false, 'supports' => array( 'revisions' ), diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index 301c8fb7..f54011cf 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -174,7 +174,8 @@ private function _renderChartBox( $placeholder_id, $chart_id ) { 'action' => Visualizer_Plugin::ACTION_DELETE_CHART, 'nonce' => wp_create_nonce(), 'chart' => $chart_id, - ), $ajax_url + ), + $ajax_url ); $clone_url = add_query_arg( array( @@ -182,14 +183,16 @@ private function _renderChartBox( $placeholder_id, $chart_id ) { 'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_CLONE_CHART ), 'chart' => $chart_id, 'type' => $this->type, - ), $ajax_url + ), + $ajax_url ); $export_link = add_query_arg( array( 'action' => Visualizer_Plugin::ACTION_EXPORT_DATA, 'chart' => $chart_id, 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION ), - ), admin_url( 'admin-ajax.php' ) + ), + admin_url( 'admin-ajax.php' ) ); echo '
', esc_html( $title ), '
'; echo '
'; diff --git a/classes/Visualizer/Render/Page/Data.php b/classes/Visualizer/Render/Page/Data.php index 8e284724..eabd2ba5 100644 --- a/classes/Visualizer/Render/Page/Data.php +++ b/classes/Visualizer/Render/Page/Data.php @@ -64,7 +64,8 @@ protected function _renderSidebarContent() { 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA, 'nonce' => wp_create_nonce(), 'chart' => $this->chart->ID, - ), admin_url( 'admin-ajax.php' ) + ), + admin_url( 'admin-ajax.php' ) ); ?> @@ -173,7 +174,8 @@ class="dashicons dashicons-lock"> array( 'action' => ( VISUALIZER_PRO ) ? Visualizer_Pro::ACTION_FETCH_DATA : '', 'nonce' => wp_create_nonce(), - ), admin_url( 'admin-ajax.php' ) + ), + admin_url( 'admin-ajax.php' ) ); $query_args_charts = array( 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, @@ -297,7 +299,8 @@ private function getPermissionsLink( $id ) { array( 'nonce' => wp_create_nonce(), 'tab' => 'permissions', - ), remove_query_arg( 'tab', $_SERVER['REQUEST_URI'] ) + ), + remove_query_arg( 'tab', $_SERVER['REQUEST_URI'] ) ); ?> " method="post"> @@ -320,7 +323,9 @@ private function permissionsSidebar() { } Visualizer_Render_Sidebar::_renderGroupStart( esc_html__( 'Who can see this chart?', 'visualizer' ) . '', '', apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' ) + class="dashicons dashicons-lock">', + '', + apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' ) ); Visualizer_Render_Sidebar::_renderSectionStart(); Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can view the chart on the front-end.', 'visualizer' ) ); @@ -362,7 +367,9 @@ class="dashicons dashicons-lock">', '', apply_filters( 'visualizer_pro_up Visualizer_Render_Sidebar::_renderGroupStart( esc_html__( 'Who can edit this chart?', 'visualizer' ) . '', '', apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' ) + class="dashicons dashicons-lock">', + '', + apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' ) ); Visualizer_Render_Sidebar::_renderSectionStart(); Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can edit the chart on the front-end.', 'visualizer' ) ); diff --git a/classes/Visualizer/Render/Sidebar.php b/classes/Visualizer/Render/Sidebar.php index e5302344..dc5ad1bc 100644 --- a/classes/Visualizer/Render/Sidebar.php +++ b/classes/Visualizer/Render/Sidebar.php @@ -183,7 +183,8 @@ protected function _renderAdvancedSettings() { 'manual', $this->manual, sprintf( - esc_html__( 'One per line in valid JSON (key:value) format e.g. %s', 'visualizer' ), '
' . $example . '' + esc_html__( 'One per line in valid JSON (key:value) format e.g. %s', 'visualizer' ), + '
' . $example . '' ), '', array( 'rows' => 5 ) diff --git a/index.php b/index.php index 16844f74..3add2b6e 100644 --- a/index.php +++ b/index.php @@ -129,13 +129,3 @@ function visualizer_register_parrot( $plugins ) { spl_autoload_register( 'visualizer_autoloader' ); // launch the plugin visualizer_launch(); - - -/* uncomment only for local/testing */ -//add_action( 'themeisle_log_event', 'visualizer_themeisle_log_event', 10, 5 ); -function visualizer_themeisle_log_event( $name, $msg, $type, $file, $line ) { - if ( $name !== Visualizer_Plugin::NAME ) { - return; - } - error_log( sprintf( '%s: %s in %s on %s', $type, $msg, $file, $line ) ); -} diff --git a/phpcs.xml b/phpcs.xml index 671509dd..4f3de996 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -31,6 +31,8 @@ + + From e74339709c256c6dfd69135e5629557cc89732aa Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Thu, 4 Oct 2018 14:37:39 +0530 Subject: [PATCH 10/12] bug including the chart in admin. #213 --- classes/Visualizer/Module/Frontend.php | 1 + index.php | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/Visualizer/Module/Frontend.php b/classes/Visualizer/Module/Frontend.php index 1f590bae..b102b3ee 100644 --- a/classes/Visualizer/Module/Frontend.php +++ b/classes/Visualizer/Module/Frontend.php @@ -54,6 +54,7 @@ public function __construct( Visualizer_Plugin $plugin ) { parent::__construct( $plugin ); $this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' ); + $this->_addAction( 'visualizer_enqueue_scripts', 'enqueueScripts' ); $this->_addFilter( 'visualizer_get_language', 'getLanguage' ); $this->_addShortcode( 'visualizer', 'renderChart' ); diff --git a/index.php b/index.php index 3add2b6e..1bc8e699 100644 --- a/index.php +++ b/index.php @@ -93,10 +93,9 @@ function visualizer_launch() { $plugin->setModule( Visualizer_Module_Admin::NAME ); } - if ( ! is_admin() || defined( 'WP_TESTS_DOMAIN' ) ) { - // set frontend modules - $plugin->setModule( Visualizer_Module_Frontend::NAME ); - } + // set frontend modules + $plugin->setModule( Visualizer_Module_Frontend::NAME ); + $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload_52.php'; if ( is_readable( $vendor_file ) ) { include_once( $vendor_file ); From 8109029b374b92133ff644583d56f7be289547d0 Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Thu, 4 Oct 2018 14:44:26 +0530 Subject: [PATCH 11/12] grunt --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 1bc8e699..d5673d77 100644 --- a/index.php +++ b/index.php @@ -95,7 +95,7 @@ function visualizer_launch() { // set frontend modules $plugin->setModule( Visualizer_Module_Frontend::NAME ); - + $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload_52.php'; if ( is_readable( $vendor_file ) ) { include_once( $vendor_file ); From 6e9edca79234ff9fd7dca3dbf50ae9517ce4b09e Mon Sep 17 00:00:00 2001 From: Ashish Ravi Date: Thu, 11 Oct 2018 09:55:42 +0530 Subject: [PATCH 12/12] bump version --- classes/Visualizer/Plugin.php | 2 +- css/media.css | 2 +- index.php | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/Visualizer/Plugin.php b/classes/Visualizer/Plugin.php index f9c71d8d..b201709b 100644 --- a/classes/Visualizer/Plugin.php +++ b/classes/Visualizer/Plugin.php @@ -28,7 +28,7 @@ class Visualizer_Plugin { const NAME = 'visualizer'; - const VERSION = '3.0.11'; + const VERSION = '3.0.12'; // custom post types const CPT_VISUALIZER = 'visualizer'; diff --git a/css/media.css b/css/media.css index 2bd48195..43f29379 100644 --- a/css/media.css +++ b/css/media.css @@ -1,5 +1,5 @@ /* - Version: 3.0.11 + Version: 3.0.12 */ #visualizer-library-view { padding: 30px 10px 10px 30px; diff --git a/index.php b/index.php index d5673d77..0df009e4 100644 --- a/index.php +++ b/index.php @@ -4,7 +4,7 @@ Plugin Name: Visualizer: Charts and Graphs Lite Plugin URI: https://themeisle.com/plugins/visualizer-charts-and-graphs-lite/ Description: A simple, easy to use and quite powerful tool to create, manage and embed interactive charts into your WordPress posts and pages. The plugin uses Google Visualization API to render charts, which supports cross-browser compatibility (adopting VML for older IE versions) and cross-platform portability to iOS and new Android releases. - Version: 3.0.11 + Version: 3.0.12 Author: Themeisle Author URI: http://themeisle.com License: GPL v2.0 or later diff --git a/package.json b/package.json index a7399928..a6979779 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "visualizer", - "version": "3.0.11", + "version": "3.0.12", "description": "Visualizer Lite", "repository": { "type": "git",