Skip to content

Commit 5f00c83

Browse files
Merge pull request #304 from Codeinwp/development
Added filter to enable users to change schedule of charts. Fixed bug with line chart with timeofday column. Fixed bug with scheduled charts that sometimes did not show updated data. Javascript can be customized on a per user basis that will not be wiped out on update.
2 parents 7088096 + 4dd54f3 commit 5f00c83

File tree

16 files changed

+200
-55
lines changed

16 files changed

+200
-55
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ deploy:
7272
after_deploy:
7373
- chmod +x bin/deploy.sh
7474
- ". ./bin/deploy.sh"
75+
after_failure:
76+
- cat "logs/phpcs.log"

classes/Visualizer/Module.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,54 @@ protected function get_language() {
395395
return reset( $array );
396396
}
397397

398+
/**
399+
* Gets/creates the JS where user-specific customizations can be/have been added.
400+
*/
401+
protected function get_user_customization_js() {
402+
// use this as the JS file in case we are not able to create the file in uploads.
403+
$default = VISUALIZER_ABSURL . 'js/customization.js';
404+
405+
$uploads = wp_get_upload_dir();
406+
$specific = $uploads['baseurl'] . '/visualizer/customization.js';
407+
408+
// for testing on user sites (before we send them the correctly customized file).
409+
if ( VISUALIZER_TEST_JS_CUSTOMIZATION ) {
410+
return $default;
411+
}
412+
413+
require_once( ABSPATH . 'wp-admin/includes/file.php' );
414+
WP_Filesystem();
415+
global $wp_filesystem;
416+
417+
$dir = $wp_filesystem->wp_content_dir() . 'uploads/visualizer';
418+
$file = $wp_filesystem->wp_content_dir() . 'uploads/visualizer/customization.js';
419+
420+
if ( $wp_filesystem->is_readable( $file ) ) {
421+
return $specific;
422+
}
423+
424+
if ( $wp_filesystem->exists( $file ) && ! $wp_filesystem->is_readable( $file ) ) {
425+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to read file %s', $file ), 'error', __FILE__, __LINE__ );
426+
return $default;
427+
}
428+
429+
if ( ! $wp_filesystem->exists( $dir ) ) {
430+
if ( ( $done = $wp_filesystem->mkdir( $dir ) ) === false ) {
431+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to create directory %s', $dir ), 'error', __FILE__, __LINE__ );
432+
return $default;
433+
}
434+
}
435+
436+
// if file does not exist, copy.
437+
if ( ! $wp_filesystem->exists( $file ) ) {
438+
$src = str_replace( ABSPATH, $wp_filesystem->abspath(), VISUALIZER_ABSPATH . '/js/customization.js' );
439+
if ( ( $done = $wp_filesystem->copy( $src, $file ) ) === false ) {
440+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Unable to copy file %s to %s', $src, $file ), 'error', __FILE__, __LINE__ );
441+
return $default;
442+
}
443+
}
444+
445+
return $specific;
446+
}
447+
398448
}

classes/Visualizer/Module/Admin.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ public function enqueueMediaScripts() {
220220
wp_enqueue_script( 'visualizer-media-controller', VISUALIZER_ABSURL . 'js/media/controller.js', array( 'visualizer-media-collection' ), Visualizer_Plugin::VERSION, true );
221221
wp_enqueue_script( 'visualizer-media-view', VISUALIZER_ABSURL . 'js/media/view.js', array( 'visualizer-media-controller' ), Visualizer_Plugin::VERSION, true );
222222
wp_localize_script(
223-
'visualizer-media-view', 'visualizer', array(
223+
'visualizer-media-view',
224+
'visualizer',
225+
array(
224226
'i10n' => array(
225227
'insert' => __( 'Insert', 'visualizer' ),
226228
),
@@ -286,7 +288,8 @@ public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darra
286288
}
287289

288290
$types = array_merge(
289-
$additional, array(
291+
$additional,
292+
array(
290293
'pie' => array(
291294
'name' => esc_html__( 'Pie', 'visualizer' ),
292295
'enabled' => true,
@@ -403,18 +406,28 @@ public function enqueueLibraryScripts( $suffix ) {
403406
$this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' );
404407
wp_enqueue_media();
405408
wp_enqueue_script(
406-
'visualizer-library', VISUALIZER_ABSURL . 'js/library.js', array(
409+
'visualizer-library',
410+
VISUALIZER_ABSURL . 'js/library.js',
411+
array(
407412
'jquery',
408413
'media-views',
409-
), Visualizer_Plugin::VERSION, true
414+
),
415+
Visualizer_Plugin::VERSION,
416+
true
410417
);
411418
wp_enqueue_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
412419
wp_enqueue_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
420+
wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
413421
wp_enqueue_script(
414-
'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
422+
'visualizer-render',
423+
VISUALIZER_ABSURL . 'js/render.js',
424+
array(
415425
'google-jsapi-old',
416426
'visualizer-library',
417-
), Visualizer_Plugin::VERSION, true
427+
'visualizer-customization',
428+
),
429+
Visualizer_Plugin::VERSION,
430+
true
418431
);
419432
}
420433
}
@@ -459,7 +472,10 @@ public function registerAdminMenu() {
459472
public function renderLibraryPage() {
460473
// get current page
461474
$page = filter_input(
462-
INPUT_GET, 'vpage', FILTER_VALIDATE_INT, array(
475+
INPUT_GET,
476+
'vpage',
477+
FILTER_VALIDATE_INT,
478+
array(
463479
'options' => array(
464480
'min_range' => 1,
465481
'default' => 1,
@@ -525,7 +541,9 @@ public function renderLibraryPage() {
525541
// enqueue charts array
526542
$ajaxurl = admin_url( 'admin-ajax.php' );
527543
wp_localize_script(
528-
'visualizer-library', 'visualizer', array(
544+
'visualizer-library',
545+
'visualizer',
546+
array(
529547
'language' => $this->get_language(),
530548
'map_api_key' => get_option( 'visualizer-map-api-key' ),
531549
'charts' => $charts,
@@ -536,13 +554,15 @@ public function renderLibraryPage() {
536554
'action' => Visualizer_Plugin::ACTION_CREATE_CHART,
537555
'library' => 'yes',
538556
'type' => isset( $_GET['type'] ) ? $_GET['type'] : '',
539-
), $ajaxurl
557+
),
558+
$ajaxurl
540559
),
541560
'edit' => add_query_arg(
542561
array(
543562
'action' => Visualizer_Plugin::ACTION_EDIT_CHART,
544563
'library' => 'yes',
545-
), $ajaxurl
564+
),
565+
$ajaxurl
546566
),
547567
),
548568
)

classes/Visualizer/Module/Chart.php

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ public function getCharts() {
7272
'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
7373
'posts_per_page' => 9,
7474
'paged' => filter_input(
75-
INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
75+
INPUT_GET,
76+
'page',
77+
FILTER_VALIDATE_INT,
78+
array(
7679
'options' => array(
7780
'min_range' => 1,
7881
'default' => 1,
@@ -171,7 +174,10 @@ public function deleteChart() {
171174
$capable = current_user_can( 'delete_posts' );
172175
if ( $nonce && $capable ) {
173176
$chart_id = filter_input(
174-
$input_method, 'chart', FILTER_VALIDATE_INT, array(
177+
$input_method,
178+
'chart',
179+
FILTER_VALIDATE_INT,
180+
array(
175181
'options' => array(
176182
'min_range' => 1,
177183
),
@@ -227,7 +233,9 @@ public function renderChartPages() {
227233
add_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() );
228234
add_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
229235
add_post_meta(
230-
$chart_id, Visualizer_Plugin::CF_SETTINGS, array(
236+
$chart_id,
237+
Visualizer_Plugin::CF_SETTINGS,
238+
array(
231239
'focusTarget' => 'datum',
232240
)
233241
);
@@ -244,18 +252,28 @@ public function renderChartPages() {
244252
wp_register_script( 'visualizer-frame', VISUALIZER_ABSURL . 'js/frame.js', array( 'visualizer-chosen' ), Visualizer_Plugin::VERSION, true );
245253
wp_register_script( 'google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
246254
wp_register_script( 'google-jsapi-old', '//www.google.com/jsapi', array( 'google-jsapi-new' ), null, true );
255+
wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
247256
wp_register_script(
248-
'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array(
257+
'visualizer-render',
258+
VISUALIZER_ABSURL . 'js/render.js',
259+
array(
249260
'google-jsapi-old',
250261
'google-jsapi-new',
251262
'visualizer-frame',
252-
), Visualizer_Plugin::VERSION, true
263+
'visualizer-customization',
264+
),
265+
Visualizer_Plugin::VERSION,
266+
true
253267
);
254268
wp_register_script(
255-
'visualizer-preview', VISUALIZER_ABSURL . 'js/preview.js', array(
269+
'visualizer-preview',
270+
VISUALIZER_ABSURL . 'js/preview.js',
271+
array(
256272
'wp-color-picker',
257273
'visualizer-render',
258-
), Visualizer_Plugin::VERSION, true
274+
),
275+
Visualizer_Plugin::VERSION,
276+
true
259277
);
260278
// added by Ash/Upwork
261279
if ( VISUALIZER_PRO ) {
@@ -344,7 +362,9 @@ private function _handleDataAndSettingsPage() {
344362
wp_enqueue_script( 'visualizer-preview' );
345363
wp_enqueue_script( 'visualizer-render' );
346364
wp_localize_script(
347-
'visualizer-render', 'visualizer', array(
365+
'visualizer-render',
366+
'visualizer',
367+
array(
348368
'l10n' => array(
349369
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
350370
'loading' => esc_html__( 'Loading...', 'visualizer' ),
@@ -538,7 +558,10 @@ public function cloneChart() {
538558
$capable = current_user_can( 'edit_posts' );
539559
if ( $nonce && $capable ) {
540560
$chart_id = filter_input(
541-
INPUT_GET, 'chart', FILTER_VALIDATE_INT, array(
561+
INPUT_GET,
562+
'chart',
563+
FILTER_VALIDATE_INT,
564+
array(
542565
'options' => array(
543566
'min_range' => 1,
544567
),
@@ -570,7 +593,8 @@ public function cloneChart() {
570593
array(
571594
'page' => 'visualizer',
572595
'type' => filter_input( INPUT_GET, 'type' ),
573-
), admin_url( 'upload.php' )
596+
),
597+
admin_url( 'upload.php' )
574598
);
575599
}
576600
}
@@ -590,7 +614,9 @@ public function exportData() {
590614
$capable = current_user_can( 'edit_posts' );
591615
if ( $capable ) {
592616
$chart_id = isset( $_GET['chart'] ) ? filter_var(
593-
$_GET['chart'], FILTER_VALIDATE_INT, array(
617+
$_GET['chart'],
618+
FILTER_VALIDATE_INT,
619+
array(
594620
'options' => array(
595621
'min_range' => 1,
596622
),
@@ -623,7 +649,9 @@ private function _handleDataPage() {
623649
wp_enqueue_style( 'visualizer-frame' );
624650
wp_enqueue_script( 'visualizer-render' );
625651
wp_localize_script(
626-
'visualizer-render', 'visualizer', array(
652+
'visualizer-render',
653+
'visualizer',
654+
array(
627655
'l10n' => array(
628656
'invalid_source' => esc_html__( 'You have entered invalid URL. Please, insert proper URL.', 'visualizer' ),
629657
'loading' => esc_html__( 'Loading...', 'visualizer' ),

classes/Visualizer/Module/Frontend.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
5454
parent::__construct( $plugin );
5555

5656
$this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' );
57+
$this->_addAction( 'visualizer_enqueue_scripts', 'enqueueScripts' );
5758
$this->_addFilter( 'visualizer_get_language', 'getLanguage' );
5859
$this->_addShortcode( 'visualizer', 'renderChart' );
5960

@@ -99,7 +100,8 @@ function endpoint_register() {
99100
*/
100101
private function get_actions() {
101102
return apply_filters(
102-
'visualizer_action_buttons', array(
103+
'visualizer_action_buttons',
104+
array(
103105
'print' => __( 'Print', 'visualizer' ),
104106
'csv' => __( 'CSV', 'visualizer' ),
105107
'xls' => __( 'Excel', 'visualizer' ),
@@ -157,7 +159,8 @@ public function perform_action( WP_REST_Request $params ) {
157159
public function enqueueScripts() {
158160
wp_register_script( 'visualizer-google-jsapi-new', '//www.gstatic.com/charts/loader.js', array(), null, true );
159161
wp_register_script( 'visualizer-google-jsapi-old', '//www.google.com/jsapi', array( 'visualizer-google-jsapi-new' ), null, true );
160-
wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery' ), Visualizer_Plugin::VERSION, true );
162+
wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
163+
wp_register_script( 'visualizer-render', VISUALIZER_ABSURL . 'js/render.js', array( 'visualizer-google-jsapi-old', 'jquery', 'visualizer-customization' ), Visualizer_Plugin::VERSION, true );
161164
wp_register_script( 'visualizer-clipboardjs', VISUALIZER_ABSURL . 'js/lib/clipboardjs/clipboard.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
162165
wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION );
163166
do_action( 'visualizer_pro_frontend_load_resources' );
@@ -185,7 +188,8 @@ public function renderChart( $atts ) {
185188
'series' => false, // series filter hook
186189
'data' => false, // data filter hook
187190
'settings' => false, // data filter hook
188-
), $atts
191+
),
192+
$atts
189193
);
190194

191195
// if empty id or chart does not exists, then return empty string
@@ -228,7 +232,7 @@ public function renderChart( $atts ) {
228232
}
229233

230234
// handle data filter hooks
231-
$data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( $chart->post_content ), $chart->ID, $type );
235+
$data = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA, unserialize( html_entity_decode( $chart->post_content ) ), $chart->ID, $type );
232236
if ( ! empty( $atts['data'] ) ) {
233237
$data = apply_filters( $atts['data'], $data, $chart->ID, $type );
234238
}
@@ -253,7 +257,9 @@ public function renderChart( $atts ) {
253257
// enqueue visualizer render and update render localizations
254258
wp_enqueue_script( 'visualizer-render' );
255259
wp_localize_script(
256-
'visualizer-render', 'visualizer', array(
260+
'visualizer-render',
261+
'visualizer',
262+
array(
257263
'charts' => $this->_charts,
258264
'language' => $this->get_language(),
259265
'map_api_key' => get_option( 'visualizer-map-api-key' ),

classes/Visualizer/Module/Setup.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public function getChartCountsByTypeAndMeta( $meta_keys = array() ) {
107107
*/
108108
public function setupCustomPostTypes() {
109109
register_post_type(
110-
Visualizer_Plugin::CPT_VISUALIZER, array(
110+
Visualizer_Plugin::CPT_VISUALIZER,
111+
array(
111112
'label' => 'Visualizer Charts',
112113
'public' => false,
113114
'supports' => array( 'revisions' ),

classes/Visualizer/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class Visualizer_Plugin {
2929

3030
const NAME = 'visualizer';
31-
const VERSION = '3.0.11';
31+
const VERSION = '3.0.12';
3232

3333
// custom post types
3434
const CPT_VISUALIZER = 'visualizer';

classes/Visualizer/Render/Library.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,25 @@ private function _renderChartBox( $placeholder_id, $chart_id ) {
174174
'action' => Visualizer_Plugin::ACTION_DELETE_CHART,
175175
'nonce' => wp_create_nonce(),
176176
'chart' => $chart_id,
177-
), $ajax_url
177+
),
178+
$ajax_url
178179
);
179180
$clone_url = add_query_arg(
180181
array(
181182
'action' => Visualizer_Plugin::ACTION_CLONE_CHART,
182183
'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_CLONE_CHART ),
183184
'chart' => $chart_id,
184185
'type' => $this->type,
185-
), $ajax_url
186+
),
187+
$ajax_url
186188
);
187189
$export_link = add_query_arg(
188190
array(
189191
'action' => Visualizer_Plugin::ACTION_EXPORT_DATA,
190192
'chart' => $chart_id,
191193
'security' => wp_create_nonce( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION ),
192-
), admin_url( 'admin-ajax.php' )
194+
),
195+
admin_url( 'admin-ajax.php' )
193196
);
194197
echo '<div class="visualizer-chart"><div class="visualizer-chart-title">', esc_html( $title ), '</div>';
195198
echo '<div id="', $placeholder_id, '" class="visualizer-chart-canvas">';

0 commit comments

Comments
 (0)