From 24c69be1aec8ff463bf8521cb57b65d0009277a0 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Thu, 9 May 2024 21:02:58 +0300 Subject: [PATCH 01/11] build: added renew/activate license notice --- js/library.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/js/library.js b/js/library.js index 5164dbb6..9f34be3d 100644 --- a/js/library.js +++ b/js/library.js @@ -33,6 +33,79 @@ }); })(wp.media.view); +function createPopup() { + if ( visualizer.is_pro ) { + return; + } + + var popup = document.createElement('div'); + + + popup.style.display = 'none'; + popup.style.position = 'fixed'; + popup.style.top = '50%'; + popup.style.left = '50%'; + popup.style.transform = 'translate(-50%, -50%)'; + popup.style.backgroundColor = '#fff'; + popup.style.padding = '20px'; + popup.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.2)'; + popup.style.zIndex = '1000'; + + + var heading = document.createElement('h2'); + heading.textContent = 'Alert'; + heading.style.color = 'red'; + heading.style.textAlign = 'left'; + heading.style.marginBottom = '10px'; + popup.appendChild(heading); + + + var message = document.createElement('p'); + 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.'; + message.style.wordWrap = 'break-word'; + message.style.width = '250px'; + popup.appendChild(message); + + + var buttonsContainer = document.createElement('div'); + buttonsContainer.style.display = 'grid'; + buttonsContainer.style.gridTemplateColumns = '1fr'; // Single column layout + buttonsContainer.style.gap = '10px'; + buttonsContainer.style.textAlign = 'center'; + buttonsContainer.style.marginTop = '20px'; + + + var link1 = document.createElement('a'); + link1.href = 'https://store.themeisle.com/'; + link1.target = '_blank'; + var button1 = document.createElement('button'); + button1.textContent = 'Renew License'; + button1.style.padding = '10px 20px'; + button1.style.cursor = 'pointer'; + button1.style.backgroundColor = 'blue'; + button1.style.color = 'white'; + link1.appendChild(button1); + buttonsContainer.appendChild(link1); + + + var link2 = document.createElement('a'); + link2.href = '/wp-admin/options-general.php#visualizer_pro_license'; + var button2 = document.createElement('button'); + button2.textContent = 'Activate License'; + button2.style.padding = '10px 20px'; + button2.style.cursor = 'pointer'; + button2.style.backgroundColor = 'green'; + button2.style.color = 'white'; + link2.appendChild(button2); + buttonsContainer.appendChild(link2); + + popup.appendChild(buttonsContainer); + + document.body.appendChild(popup); + + popup.style.display = 'block'; +} + (function ($, vmv, vu) { var resizeTimeout; @@ -164,6 +237,7 @@ }); $(".visualizer-chart-image").on("click", function () { + createPopup(); $('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}}); return false; }); @@ -185,4 +259,4 @@ }); $('.visualizer-chart:not(.visualizer-chart-display), .visualizer-library-pagination').fadeIn(500); }); -})(jQuery, visualizer.media.view, visualizer.urls); \ No newline at end of file +})(jQuery, visualizer.media.view, visualizer.urls); From 4743e29f88cdcda0b57bd9be31bc76434b9d9fbe Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Fri, 10 May 2024 14:00:58 +0300 Subject: [PATCH 02/11] chore: style changes for renew notice --- js/library.js | 98 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 13 deletions(-) diff --git a/js/library.js b/js/library.js index 9f34be3d..133bf18a 100644 --- a/js/library.js +++ b/js/library.js @@ -34,27 +34,48 @@ })(wp.media.view); function createPopup() { - if ( visualizer.is_pro ) { - return; - } + + var link = document.createElement('link'); + link.rel = 'stylesheet'; + link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css'; + document.head.appendChild(link); var popup = document.createElement('div'); + var closeIcon = document.createElement('i'); + closeIcon.classList.add('dashicons', 'dashicons-no', 'close-icon'); + closeIcon.addEventListener('click', function() { + popup.style.display = 'none'; + }); + closeIcon.style.position = 'absolute'; + closeIcon.style.top = '10px'; + closeIcon.style.right = '10px'; + closeIcon.style.cursor = 'pointer'; + closeIcon.style.color = '#333'; + closeIcon.classList.add('fas', 'fa-times', 'close-icon'); + popup.appendChild(closeIcon); popup.style.display = 'none'; + popup.style.position = 'fixed'; popup.style.top = '50%'; popup.style.left = '50%'; popup.style.transform = 'translate(-50%, -50%)'; popup.style.backgroundColor = '#fff'; + popup.style.zIndex = '1000'; + popup.style.backgroundColor = '#fff'; popup.style.padding = '20px'; - popup.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.2)'; + popup.style.border = '1px solid #ccc'; + popup.style.borderRadius = '8px'; + popup.style.boxShadow = '0 2px 4px rgba(0,0,0,0.1)'; popup.style.zIndex = '1000'; + popup.style.maxWidth = '400px'; + popup.style.fontWeight = 'bold'; + popup.style.marginBottom = '20px'; - - var heading = document.createElement('h2'); - heading.textContent = 'Alert'; - heading.style.color = 'red'; + var heading = document.createElement('h1'); + heading.textContent = 'Alert!'; + heading.style.color = '#d32f2f'; heading.style.textAlign = 'left'; heading.style.marginBottom = '10px'; popup.appendChild(heading); @@ -79,11 +100,22 @@ function createPopup() { link1.href = 'https://store.themeisle.com/'; link1.target = '_blank'; var button1 = document.createElement('button'); - button1.textContent = 'Renew License'; + button1.innerHTML = ' Renew License'; // Add shopping cart icon button1.style.padding = '10px 20px'; button1.style.cursor = 'pointer'; - button1.style.backgroundColor = 'blue'; + button1.style.backgroundColor = '#008CBA'; button1.style.color = 'white'; + button1.style.border = 'none'; + button1.style.textAlign = 'center'; + button1.style.textDecoration = 'none'; + button1.style.display = 'inline-block'; + button1.style.fontSize = '16px'; + button1.style.width = '200px'; + button1.style.height = '50px'; + button1.style.borderRadius = '4px'; + button1.style.transition = 'background-color 0.3s'; + button1.style.fontWeight = 'bold'; + button1.style.marginTop = '10px'; link1.appendChild(button1); buttonsContainer.appendChild(link1); @@ -91,11 +123,22 @@ function createPopup() { var link2 = document.createElement('a'); link2.href = '/wp-admin/options-general.php#visualizer_pro_license'; var button2 = document.createElement('button'); - button2.textContent = 'Activate License'; + button2.innerHTML = ' Activate License'; button2.style.padding = '10px 20px'; button2.style.cursor = 'pointer'; - button2.style.backgroundColor = 'green'; + button2.style.backgroundColor = '#4CAF50'; button2.style.color = 'white'; + button2.style.border = 'none'; + button2.style.textAlign = 'center'; + button2.style.textDecoration = 'none'; + button2.style.display = 'inline-block'; + button2.style.fontSize = '16px'; + button2.style.width = '200px'; + button2.style.height = '50px'; + button2.style.borderRadius = '4px'; + button2.style.transition = 'background-color 0.3s'; + button2.style.fontWeight = 'bold'; + button2.style.marginTop = '10px'; link2.appendChild(button2); buttonsContainer.appendChild(link2); @@ -150,6 +193,14 @@ function createPopup() { }); $('.visualizer-chart-shortcode').click(function (e) { + + if ( ! visualizer.is_pro ) { + createPopup(); + e.preventDefault(); + e.stopPropagation(); + return; + } + var range, selection; if (window.getSelection && document.createRange) { @@ -200,6 +251,12 @@ function createPopup() { }); $('.visualizer-chart-edit').click(function () { + + if ( ! visualizer.is_pro ) { + createPopup(); + return; + } + var wnd = window; var view = new vmv.Chart( { action: vu.edit.indexOf('&chart') != -1 ? vu.edit : vu.edit + '&chart=' + $(this).attr('data-chart') @@ -214,8 +271,20 @@ function createPopup() { return false; }); + $(".visualizer-chart-clone").on("click", function ( event ) { + if ( ! visualizer.is_pro ) { + createPopup(); + event.preventDefault(); + } + }); $(".visualizer-chart-export").on("click", function () { + + if ( ! visualizer.is_pro ) { + createPopup(); + return; + } + $.ajax({ url: $(this).attr("data-chart"), method: "get", @@ -237,7 +306,10 @@ function createPopup() { }); $(".visualizer-chart-image").on("click", function () { - createPopup(); + if ( ! visualizer.is_pro ) { + createPopup(); + return; + } $('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}}); return false; }); From 6cee5e5f9b21f1232df409fca80fa8958dead6cb Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Fri, 10 May 2024 14:16:12 +0300 Subject: [PATCH 03/11] chore: added pro_user variable to charts backend page --- classes/Visualizer/Module/Admin.php | 1 + js/library.js | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/classes/Visualizer/Module/Admin.php b/classes/Visualizer/Module/Admin.php index 5b09cc56..b50bd3d8 100644 --- a/classes/Visualizer/Module/Admin.php +++ b/classes/Visualizer/Module/Admin.php @@ -1037,6 +1037,7 @@ public function renderLibraryPage() { 'copied' => __( 'The shortcode has been copied to your clipboard. Hit Ctrl-V/Cmd-V to paste it.', 'visualizer' ), 'conflict' => __( 'We have detected a potential conflict with another component that prevents Visualizer from functioning properly. Please disable any of the following components if they are activated on your instance: Modern Events Calendar plugin, Acronix plugin. In case the aforementioned components are not activated or you continue to see this error message, please disable all other plugins and enable them one by one to find out the component that is causing the conflict.', 'visualizer' ), ), + 'is_pro_user' => Visualizer_Module::is_pro(), ) ); // render library page diff --git a/js/library.js b/js/library.js index 133bf18a..29cdb900 100644 --- a/js/library.js +++ b/js/library.js @@ -194,7 +194,7 @@ function createPopup() { $('.visualizer-chart-shortcode').click(function (e) { - if ( ! visualizer.is_pro ) { + if ( ! visualizer.is_pro_user ) { createPopup(); e.preventDefault(); e.stopPropagation(); @@ -252,7 +252,7 @@ function createPopup() { $('.visualizer-chart-edit').click(function () { - if ( ! visualizer.is_pro ) { + if ( ! visualizer.is_pro_user ) { createPopup(); return; } @@ -272,7 +272,7 @@ function createPopup() { return false; }); $(".visualizer-chart-clone").on("click", function ( event ) { - if ( ! visualizer.is_pro ) { + if ( ! visualizer.is_pro_user ) { createPopup(); event.preventDefault(); } @@ -280,7 +280,7 @@ function createPopup() { $(".visualizer-chart-export").on("click", function () { - if ( ! visualizer.is_pro ) { + if ( ! visualizer.is_pro_user ) { createPopup(); return; } @@ -306,7 +306,7 @@ function createPopup() { }); $(".visualizer-chart-image").on("click", function () { - if ( ! visualizer.is_pro ) { + if ( ! visualizer.is_pro_user ) { createPopup(); return; } From 971dc95228b37236c6f0fce34bc0dee369784407 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Fri, 10 May 2024 14:34:37 +0300 Subject: [PATCH 04/11] chore: added overlay for renew notice --- js/library.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/library.js b/js/library.js index 29cdb900..c0d00f09 100644 --- a/js/library.js +++ b/js/library.js @@ -35,6 +35,17 @@ function createPopup() { + var overlay = document.createElement('div'); + overlay.id = 'overlay-visualizer'; + overlay.style.position = 'fixed'; + overlay.style.top = '0'; + overlay.style.left = '0'; + overlay.style.width = '100%'; + overlay.style.height = '100%'; + overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; + overlay.style.zIndex = '999'; + document.body.appendChild(overlay); + var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css'; @@ -45,6 +56,7 @@ function createPopup() { var closeIcon = document.createElement('i'); closeIcon.classList.add('dashicons', 'dashicons-no', 'close-icon'); closeIcon.addEventListener('click', function() { + document.body.removeChild(overlay); popup.style.display = 'none'; }); closeIcon.style.position = 'absolute'; From 666ba8b60f526cd1d89444071aa70366ca2a5083 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Fri, 10 May 2024 15:09:23 +0300 Subject: [PATCH 05/11] restrict renew notice to pro charts --- classes/Visualizer/Render/Library.php | 19 ++++++++++++++----- js/library.js | 10 +++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index 70d7a429..5ea25eea 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -337,6 +337,15 @@ private function _renderChartBox( $placeholder_id, $chart_id, $with_filter = fal admin_url( 'admin-ajax.php' ) ) ); + $chart_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); + + $types = apply_filters( 'visualizer_pro_chart_types', [] ); + + $pro_class =''; + + if ( ! empty( $chart_type ) && isset( $types[ $chart_type ] ) ) { + $pro_class = 'is_pro'; + } $chart_status = array( 'date' => get_the_modified_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $chart_id ), 'error' => get_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, true ), 'icon' => 'dashicons-yes-alt', 'title' => 'A-OK!' ); if ( ! empty( $chart_status['error'] ) ) { @@ -358,13 +367,13 @@ private function _renderChartBox( $placeholder_id, $chart_id, $with_filter = fal echo ''; From 71437dcce721f210565a60ccf9541088227cdf21 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Fri, 10 May 2024 21:45:02 +0300 Subject: [PATCH 11/11] lint code --- classes/Visualizer/Render/Library.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index dcfe2079..84bf5b18 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -346,7 +346,7 @@ private function _renderChartBox( $placeholder_id, $chart_id, $with_filter = fal $pro_class = ''; - if ( ! empty( $chart_type ) && in_array( $chart_type, $types) ) { + if ( ! empty( $chart_type ) && in_array( $chart_type, $types, true ) ) { $pro_class = 'viz-is-pro-chart'; } @@ -378,7 +378,6 @@ private function _renderChartBox( $placeholder_id, $chart_id, $with_filter = fal echo '' . esc_attr__( 'Duplicate', 'visualizer' ) . ''; echo '' . esc_attr__( 'Edit', 'visualizer' ) . ''; echo ''; - error_log($chart_id); do_action( 'visualizer_chart_languages', $chart_id ); echo '
(' . $chart_id . '): ' . $chart_status['date'] . '
'; echo '';