Skip to content

Commit c619ad4

Browse files
release: fixes
- Fixed Visualizer block widget not loading - Improved the popup rendering - Enhanced security
2 parents b7a08e8 + f131320 commit c619ad4

File tree

11 files changed

+324
-181
lines changed

11 files changed

+324
-181
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
5353
parent::__construct( $plugin );
5454
$this->_addAction( 'load-post.php', 'enqueueMediaScripts' );
5555
$this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' );
56+
$this->_addAction( 'enqueue_block_editor_assets', 'enqueueMediaScripts' );
5657
$this->_addAction( 'admin_footer', 'renderTemplates' );
5758
$this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 0 );
5859
$this->_addAction( 'admin_menu', 'registerAdminMenu' );
@@ -330,7 +331,9 @@ public function feedbackReviewTrigger( $dumb ) {
330331
*/
331332
public function enqueueMediaScripts() {
332333
global $typenow;
333-
if ( post_type_supports( $typenow, 'editor' ) ) {
334+
global $current_screen;
335+
336+
if ( post_type_supports( $typenow, 'editor' ) || $current_screen->id === 'widgets' ) {
334337
wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION );
335338

336339
// Load all the assets for the different libraries we support.
@@ -1019,6 +1022,7 @@ public function renderLibraryPage() {
10191022
}
10201023
// enqueue charts array
10211024
$ajaxurl = admin_url( 'admin-ajax.php' );
1025+
10221026
wp_localize_script(
10231027
'visualizer-library',
10241028
'visualizer',

classes/Visualizer/Module/Chart.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,10 @@ public function getQueryData() {
14311431
wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) );
14321432
}
14331433

1434+
if ( ! Visualizer_Module::is_pro() ) {
1435+
wp_send_json_error( array( 'msg' => __( 'Feature is not available.', 'visualizer' ) ) );
1436+
}
1437+
14341438
$params = wp_parse_args( $_POST['params'] );
14351439
$chart_id = filter_var( $params['chart_id'], FILTER_VALIDATE_INT );
14361440
$query = trim( $params['query'], ';' );
@@ -1452,6 +1456,17 @@ public function getQueryData() {
14521456
public function saveQuery() {
14531457
check_ajax_referer( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION, 'security' );
14541458

1459+
if ( ! current_user_can( 'administrator' ) ) {
1460+
wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) );
1461+
}
1462+
if ( ! is_super_admin() ) {
1463+
wp_send_json_error( array( 'msg' => __( 'Action not allowed for this user.', 'visualizer' ) ) );
1464+
}
1465+
1466+
if ( ! Visualizer_Module::is_pro() ) {
1467+
wp_send_json_error( array( 'msg' => __( 'Feature is not available.', 'visualizer' ) ) );
1468+
}
1469+
14551470
$chart_id = filter_input(
14561471
INPUT_GET,
14571472
'chart',

classes/Visualizer/Plugin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class Visualizer_Plugin {
5757
const ACTION_UPLOAD_DATA = 'visualizer-upload-data';
5858
const ACTION_EXPORT_DATA = 'visualizer-export-data';
5959

60+
const STORE_URL = 'https://store.themeisle.com/';
61+
6062
/**
6163
*Action used for fetching specific users/roles for permissions.
6264
*/

classes/Visualizer/Render/Library.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,55 @@ private function getDisplayForm() {
206206
</form>
207207
</div>';
208208
}
209+
/**
210+
* Renders pro charts blocker.
211+
*
212+
* @access private
213+
*/
214+
private function _renderProPopupBlocker() {
215+
if ( Visualizer_Module::is_pro() ) {
216+
return;
217+
}
218+
$license = get_option( 'visualizer_pro_license_data', 'free' );
219+
$license_key = '';
220+
$download_id = '';
221+
if ( ! empty( $license ) && is_object( $license ) ) {
222+
$license_key = $license->key;
223+
$download_id = $license->download_id;
224+
}
225+
$admin_license_url = admin_url( 'options-general.php#visualizer_pro_license' );
226+
$renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' . $download_id, 'visualizer_license_block' );
227+
echo '
228+
<div class="vizualizer-renew-notice-overlay" id="overlay-visualizer"></div>
229+
<div class="vizualizer-renew-notice-popup">
230+
<h1 class="vizualizer-renew-notice-heading">Alert!</h1>
231+
<p class="vizualizer-renew-notice-message">' . esc_html__( 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.', 'visualizer' ) . '</p>
232+
<div class="vizualizer-renew-notice-buttons-container">
233+
<a href="' . esc_url( $renew_license_url) . '" target="_blank">
234+
<button class="vizualizer-renew-notice-button vizualizer-renew-notice-renew-button">
235+
<span class="dashicons dashicons-cart"></span>' . esc_html__( 'Renew License', 'visualizer' ) . '
236+
</button>
237+
</a>
238+
<a href="' . esc_url( $admin_license_url ) . '">
239+
<button class="vizualizer-renew-notice-button vizualizer-renew-notice-activate-button">
240+
<span class="dashicons dashicons-unlock"></span> ' . esc_html__( 'Activate License', 'visualizer' ) . '
241+
</button>
242+
</a>
243+
<button class="vizualizer-renew-notice-button vizualizer-renew-notice-close-icon" aria-label="Close" onclick="closePopup()">
244+
<i class="dashicons dashicons-no"></i>
245+
</button>
246+
</div>
247+
</div>
248+
<script>
249+
function closePopup() {
250+
var overlay = document.getElementById("overlay-visualizer");
251+
var popup = document.querySelector(".vizualizer-renew-notice-popup");
252+
overlay.style.display = "none";
253+
popup.style.display = "none";
254+
}
255+
</script>';
209256

257+
}
210258
/**
211259
* Renders library content.
212260
*
@@ -215,10 +263,14 @@ private function getDisplayForm() {
215263
* @access private
216264
*/
217265
private function _renderLibrary() {
266+
218267
// Added by Ash/Upwork
219268
$filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
220269
// Added by Ash/Upwork
221270
echo $this->custom_css;
271+
272+
$this->_renderProPopupBlocker();
273+
222274
echo '<div id="visualizer-types" class="visualizer-clearfix">';
223275
echo '<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><symbol id="list-icon" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8C0 12.42 3.58 16 8 16C12.42 16 16 12.42 16 8C16 3.58 12.42 0 8 0ZM7.385 12.66H6.045L2.805 8.12L4.146 6.87L6.715 9.27L11.856 3.339L13.196 4.279L7.385 12.66Z"/></symbol></svg>';
224276
$this->getDisplayForm();

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/library.css

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ div#visualizer-types ul, div#visualizer-types form p {
522522

523523

524524
.vizualizer-renew-notice-overlay {
525+
display: none;
525526
position: fixed;
526527
top: 0;
527528
left: 0;
@@ -532,7 +533,7 @@ div#visualizer-types ul, div#visualizer-types form p {
532533
}
533534

534535
.vizualizer-renew-notice-popup {
535-
display: block;
536+
display: none;
536537
position: fixed;
537538
top: 50%;
538539
left: 50%;
@@ -594,8 +595,17 @@ div#visualizer-types ul, div#visualizer-types form p {
594595

595596
.vizualizer-renew-notice-close-icon {
596597
position: absolute;
597-
top: 10px;
598-
right: 10px;
598+
top: -10px;
599+
right: -70px;
599600
cursor: pointer;
600601
color: #333;
602+
background: none;
603+
border: none;
604+
padding: 0;
605+
outline: none;
606+
/* Reset button styles */
607+
display: inline-block;
608+
font: inherit;
609+
text-align: inherit;
610+
text-decoration: none;
601611
}

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
Plugin Name: Visualizer: Tables and Charts for WordPress
44
Plugin URI: https://themeisle.com/plugins/visualizer-charts-and-graphs/
5-
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.
5+
Description: Effortlessly create and embed responsive charts and tables with Visualizer, a powerful WordPress plugin that enhances data presentation from multiple sources.
66
Version: 3.11.1
77
Author: Themeisle
88
Author URI: http://themeisle.com

js/library.js

Lines changed: 17 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -33,63 +33,13 @@
3333
});
3434
})(wp.media.view);
3535

36-
function createPopupProBlocker() {
37-
38-
var link = document.createElement('link');
39-
link.rel = 'stylesheet';
40-
link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
41-
document.head.appendChild(link);
42-
43-
var overlay = document.createElement('div');
44-
overlay.classList.add('vizualizer-renew-notice-overlay');
45-
overlay.id = 'overlay-visualizer';
46-
document.body.appendChild(overlay);
47-
48-
var popup = document.createElement('div');
49-
popup.classList.add('vizualizer-renew-notice-popup');
50-
51-
var closeIcon = document.createElement('i');
52-
closeIcon.classList.add('fas', 'fa-times', 'vizualizer-renew-notice-close-icon');
53-
closeIcon.addEventListener('click', function() {
54-
document.body.removeChild(overlay);
55-
popup.style.display = 'none';
56-
});
57-
popup.appendChild(closeIcon);
58-
59-
var heading = document.createElement('h1');
60-
heading.textContent = 'Alert!';
61-
heading.classList.add('vizualizer-renew-notice-heading');
62-
popup.appendChild(heading);
63-
64-
var message = document.createElement('p');
65-
message.textContent = 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.';
66-
message.classList.add('vizualizer-renew-notice-message');
67-
popup.appendChild(message);
68-
69-
var buttonsContainer = document.createElement('div');
70-
buttonsContainer.classList.add('vizualizer-renew-notice-buttons-container');
71-
72-
var link1 = document.createElement('a');
73-
link1.href = 'https://store.themeisle.com/';
74-
link1.target = '_blank';
75-
var button1 = document.createElement('button');
76-
button1.innerHTML = '<span class="fas fa-shopping-cart"></span> Renew License';
77-
button1.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-renew-button');
78-
link1.appendChild(button1);
79-
buttonsContainer.appendChild(link1);
80-
81-
var link2 = document.createElement('a');
82-
link2.href = '/wp-admin/options-general.php#visualizer_pro_license';
83-
var button2 = document.createElement('button');
84-
button2.innerHTML = '<span class="fas fa-key"></span> Activate License';
85-
button2.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-activate-button');
86-
link2.appendChild(button2);
87-
buttonsContainer.appendChild(link2);
88-
89-
popup.appendChild(buttonsContainer);
90-
91-
document.body.appendChild(popup);
92-
36+
function createPopupProBlocker( $ , e ) {
37+
if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) {
38+
$("#overlay-visualizer").css("display", "block");
39+
$(".vizualizer-renew-notice-popup").css("display", "block");
40+
return true;
41+
}
42+
return false;
9343
}
9444

9545
(function ($, vmv, vu) {
@@ -135,12 +85,11 @@ function createPopupProBlocker() {
13585
$(this).parent('form').submit();
13686
});
13787

138-
$('.visualizer-chart-shortcode').click(function (e) {
88+
$('.visualizer-chart-shortcode').click(function (event) {
13989

140-
if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) {
141-
createPopupProBlocker();
142-
e.preventDefault();
143-
e.stopPropagation();
90+
if ( createPopupProBlocker( $, event ) ) {
91+
event.preventDefault();
92+
event.stopPropagation();
14493
return;
14594
}
14695

@@ -149,12 +98,12 @@ function createPopupProBlocker() {
14998
if (window.getSelection && document.createRange) {
15099
selection = window.getSelection();
151100
range = document.createRange();
152-
range.selectNodeContents(e.target);
101+
range.selectNodeContents(event.target);
153102
selection.removeAllRanges();
154103
selection.addRange(range);
155104
} else if (document.selection && document.body.createTextRange) {
156105
range = document.body.createTextRange();
157-
range.moveToElementText(e.target);
106+
range.moveToElementText(event.target);
158107
range.select();
159108
}
160109
});
@@ -195,8 +144,7 @@ function createPopupProBlocker() {
195144

196145
$('.visualizer-chart-edit').click(function (event) {
197146

198-
if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
199-
createPopupProBlocker();
147+
if ( createPopupProBlocker( $, event ) ) {
200148
return;
201149
}
202150

@@ -215,16 +163,14 @@ function createPopupProBlocker() {
215163
return false;
216164
});
217165
$(".visualizer-chart-clone").on("click", function ( event ) {
218-
if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
219-
createPopupProBlocker();
166+
if ( createPopupProBlocker( $, event ) ) {
220167
event.preventDefault();
221168
}
222169
});
223170

224171
$(".visualizer-chart-export").on("click", function (event) {
225172

226-
if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
227-
createPopupProBlocker();
173+
if ( createPopupProBlocker( $, event ) ) {
228174
return;
229175
}
230176

@@ -249,8 +195,7 @@ function createPopupProBlocker() {
249195
});
250196

251197
$(".visualizer-chart-image").on("click", function (event) {
252-
if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) {
253-
createPopupProBlocker();
198+
if ( createPopupProBlocker( $, event ) ) {
254199
return;
255200
}
256201
$('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}});

0 commit comments

Comments
 (0)