From 5ca809cd3ceeb16530b3ed249ca9c862d71df2de Mon Sep 17 00:00:00 2001 From: etchirag Date: Wed, 11 Dec 2024 09:58:58 +0530 Subject: [PATCH 01/18] Updatd result and email tab with temparory content and new UI --- assets/download-line-blue.png | Bin 0 -> 374 bytes assets/eye-line-blue.png | Bin 0 -> 568 bytes assets/linkedin.png | Bin 0 -> 754 bytes css/qsm-admin.css | 335 +++++++++++++++-- js/qsm-admin.js | 350 ++++++++++++++++-- js/qsm-quiz.js | 6 + mlw_quizmaster2.php | 6 - php/admin/admin-dashboard.php | 4 +- php/admin/functions.php | 72 +++- php/admin/options-page-email-tab.php | 277 ++++++++++++-- php/admin/options-page-questions-tab.php | 10 +- php/admin/options-page-results-page-tab.php | 302 ++++++++++++--- php/admin/options-page-style-tab.php | 4 +- php/admin/options-page-text-tab.php | 4 +- php/admin/quiz-options-page.php | 2 +- php/classes/class-qmn-plugin-helper.php | 3 +- php/classes/class-qmn-quiz-manager.php | 27 +- php/classes/class-qsm-emails.php | 7 + php/classes/class-qsm-fields.php | 4 +- php/classes/class-qsm-install.php | 59 ++- php/classes/class-qsm-results-pages.php | 7 + php/classes/class-qsm-settings.php | 2 + .../qsm-question-type-fill-in-the-blanks.php | 10 +- php/shortcodes.php | 45 +-- php/template-variables.php | 20 +- 25 files changed, 1313 insertions(+), 243 deletions(-) create mode 100644 assets/download-line-blue.png create mode 100644 assets/eye-line-blue.png create mode 100644 assets/linkedin.png diff --git a/assets/download-line-blue.png b/assets/download-line-blue.png new file mode 100644 index 0000000000000000000000000000000000000000..899ff1b55b1e8e3c33ef6ccc18e1c43e615d198a GIT binary patch literal 374 zcmV-+0g3*JP));Y&bQ{sef-YW}=yu^c(Df%mma zF@ad{SHRB=&aHm|7l19GI0L7sY{3Wa0M9^k25?i^PH1A&DbULS?I}ZO;s$Uge*_F7 zpab=yY{LgOwSi;#17Ils;q;__s2-GQyCC1K=sSTrZ~-L1k5-~u-5H=i2}uI4c&W** zfkR*uc-PrIu;D!T#s|o{#}=r{8)#K4g;qn*Y2b9ail<)DSx_;5-V;!E_GQ&F75c`L z8Ufp?jbZ|^VADg6-Z6L&*acqmggsgVZh@;5T+_As3w^ubM_?UznUib`V=YL)F944; UYUfR89smFU07*qoM6N<$f<^F~iU0rr literal 0 HcmV?d00001 diff --git a/assets/eye-line-blue.png b/assets/eye-line-blue.png new file mode 100644 index 0000000000000000000000000000000000000000..655614c75a28870fa7d0c0366fca80142ab47664 GIT binary patch literal 568 zcmV-80>}M{P)u1V4<>bW%?FXIfQi zTn8GWF}*?TgY`Yu)UQXp33v^(0?XcLKTrggfFt^n*gl}&+=ySvv4*(XmRd|a3EcH8 zic7$ZUJ?tN08YhNfxXsLrNp~{v(E24Fe^R?i~>zbXH8<){C)#mu(li6oe~ck$K0NX zZFL;c%@lA@e=2qb*kbNummM4fDRH#E3QQ(9Yf~Z1E^AI7vh_N1GMkj6Jx>*R@+;(E znU!;})s*Ok1YJqOj0y;e-2e{gMX@-0ndEoNF`W_@{r8Ysr`RvxjxX&D@D6wnbcl@s zzs)@d?2+SUO8mtc#rH$?ib+?M7#5bqM#YW-_pN;dd`*et1{Z1Vh=+mg>UGw5*t6T_#?wD82bIKO-+@E6md$(wSX5#w z#v`6Z&OP8T@FOM4lh;qj((3XS-FA&$5F0b+k~JHaW59n~`+pS*(J=M^0000*^{jyP2sViBegp1zk$WKoO)% zvDzgujLyY0Rm@(0s4nXmQp68wS`(b$IeIEh9nTKv9=Ro*?V(gS;0>M4dFVImxCw`iX=Rk$6#>phZ7_k}! zDbACp`TR%U;53LBxzEBtr-Il6e)m`F#u33&0V_6&0|%}w>R*<^&ria_IxNy zfX>4^Y1vbROIIoP=5YIXHPwZA=>uroo^OgZMbJ>bIeh^BU?eFwwP2(Vpsjy|P&B?0 zzZjpT`?Wvi0D`tYX;mz7JE<%4GP4-t!P_Zfam%F}mS$COZc?c&^`HuYH(O_aiJNC* z-%u67$?8I!nhL;|kiq@oDGG8O9Nk?&xhI>rgwg2`Jwul;2L0D*9nL)Tv7ZGX(E?m?pQgsEOz z>aiD~weKBI#{vYxQSJ=-=^6TDs&8{U?FHx``D%&>{6SNk^PB!iDZpIB{HrY(aZ{Y7 z*$l9jgs`qD`1}%}vZE&lb!2 z<8_=4DL`V)RrV>N0I45y{$3vypf_XoQuZns(RPr-={M&M!f{dI>XBJ+900B$nE>o; kN(qc3WhX+fp`(882kAq-3KRmzN&o-=07*qoM6N<$g4TFYn*aa+ literal 0 HcmV?d00001 diff --git a/css/qsm-admin.css b/css/qsm-admin.css index 3163b0547..350646413 100644 --- a/css/qsm-admin.css +++ b/css/qsm-admin.css @@ -480,9 +480,8 @@ span.qsm-quiz-name { border-radius: 5px; background: #fff; border: 1px solid #dfd4d4; - margin: 3px 0 0px 25px; + margin: 3px 0 0px 5px; max-width: 200px; - right: 45px; } .results-page-header, #qsm_emails .qsm-email-header { display: flex; @@ -565,13 +564,10 @@ span.qsm-quiz-name { min-width: auto; width: 100%; border-radius: 5px; - border-color: #555555; + border-color:#8a8a8a; padding-top: 2px; padding-bottom: 2px; } -.results-page-show .mce-path.mce-flow-layout-item.mce-first{ - display: none; -} .results-page-condition .qsm-result-condition-container, .email-condition .qsm-email-condition-container, .qsm-result-condition-mode, .qsm-email-condition-mode { display: flex; flex-wrap: wrap; @@ -590,10 +586,10 @@ span.qsm-quiz-name { } .results-page-content label, .results-page-content p, .qsm-email-content label, .qsm-email-content p { - color: #1E1E1E; + color: #555555; } .qsm-common-svg-image-class { - height: 18px; + height: 16px; padding: 2px; vertical-align: -webkit-baseline-middle; } @@ -2877,7 +2873,7 @@ input#duplicate_questions { flex-wrap: nowrap; border-radius: 5px; margin: 0 5px; - border: 1px solid #1E1E1E; + border: 1px solid #8a8a8a; } .qsm-actions-link-box a:first-child { border-radius: 5px 0 0 5px; @@ -2907,10 +2903,13 @@ input#duplicate_questions { .results-page-when .qsm-new-condition, .qsm-email-when .qsm-new-condition, .results-page-when .qsm-new-condition:active, .qsm-email-when .qsm-new-condition:active, .results-page-when .qsm-new-condition:focus, .qsm-email-when .qsm-new-condition:focus { - width: auto; - padding: 0; - color: #2271B1; + color: #555555; font-size: 14px; + margin-bottom: 5px; + background: #F8F9F9; + padding: 9px 10px; + position: relative; + border-radius: 10px; } .qsm-actions-link-box a span { font-size: 16px; @@ -3521,6 +3520,304 @@ input#duplicate_questions { .option-page-result-page-tab-footer .result-tab-footer-buttons .qsm-show-all-variable-text { margin: 0 10px 0 0; } + +.qsm-result-page-content-buttons button.button, +.results-page-show .wp-media-buttons button.button, +.qsm-email-content .wp-media-buttons button.button, +.qsm-row .right-bar .insert-media, .qsm-common-button-styles { + border: 1px solid #2271B1; + font-weight: 500; +} + + +.results-page-when .qsm-new-condition span, .qsm-email-when .qsm-new-condition span { + font-size: 20px; +} + +.qsm-quiz-result-tab .qsm-edit-result-view-options { + display: grid; + margin: 0 0 20px 0; + grid-template-columns: 1fr 2fr; + grid-gap: 20px; +} + +.qsm-edit-result-view-options label.qsm-edit-result-input-label { + padding-bottom: 5px; + display: inline-block; +} + +.qsm-quiz-result-tab .qsm-result-page-then-box-styles, +.qsm-quiz-email-tab .qsm-email-page-then-box-styles { + margin-bottom: 15px; + background: #F8F9F9; + padding: 20px; + position: relative; + border-radius: 10px; +} + +.qsm-email-page-common-section.qsm-email-page-then-box-styles > div { + margin-top: 0; +} + +.qsm-email-page-common-section.qsm-email-page-then-box-styles > div:not(:last-child) { + margin-bottom: 30px; +} + +.qsm-result-page-template-buttons button.button.qsm-common-button-styles, +.qsm-email-page-template-buttons button.button.qsm-common-button-styles { + width: 100%; + height: 34px; + max-width: 150px; +} + +.qsm-result-page-template-buttons, +.qsm-email-page-template-buttons { + display: flex; + grid-gap: 20px; + padding: 20px 40px; + justify-content: center; +} + +.qsm-result-page-template-options.qsm-result-page-then-box-styles, +.qsm-email-page-template-options.qsm-email-page-then-box-styles { + display: flex; + flex-direction: column; + justify-content: space-between; + min-height: 140px; + padding-bottom: 10px; +} + +.qsm-result-page-template-learn-more, +.qsm-email-page-template-learn-more { + display: grid; + justify-content: center; +} + +.qsm-result-page-template-learn-more a, +.qsm-email-page-template-learn-more a { + color: #1E1E1E; + font-weight: 500; + text-decoration: underline; + text-decoration-color: #2271B1; + text-underline-offset: 3px; + text-decoration-thickness: 1px; +} +.qsm-edit-result-view-options .qsm-edit-result-input-option label { + vertical-align: baseline; + cursor: pointer; +} +.qsm-edit-result-view-options .qsm-edit-result-input-option.active label { + font-weight: 600; +} + +.qsm-result-page-template-container, .qsm-result-my-template-container, +.qsm-email-page-template-container, .qsm-email-my-template-container { + display: grid; + grid-template-columns: repeat(4, 1fr); + gap: 15px; + padding: 0 25px; + min-height: 75vh; + min-width: 75vw; +} + +.qsm-result-page-template-card, +.qsm-email-page-template-card { + display: flex; + flex-direction: column; + align-items: center; + height: auto; + transition: background-color 0.3s ease; + max-width: 230px; +} + +.qsm-result-page-template-card-content, +.qsm-email-page-template-card-content { + transition: background-color 0.3s ease; /* Transition on the child */ +} + +.qsm-result-page-template-card .qsm-result-page-template-card-content:hover, +.qsm-email-page-template-card .qsm-email-page-template-card-content:hover { + background-color: #717171; /* Change background color on hover */ +} + +.qsm-result-page-template-card-content, +.qsm-email-page-template-card-content { + cursor: pointer; + display: flex; + justify-content: center; + align-items: center; + gap: 10px; + height: 230px; + min-width: 230px; + background: #D9D9D9; +} + +.qsm-result-page-template-button, +.qsm-email-page-template-button { + background-color: #FFFFFF; + color: #0056b3; +} + +.qsm-result-page-template-template-name, +.qsm-email-page-template-template-name { + margin: 16px 0; + font-size: 14px; + color: #333; +} + +.qsm-result-page-template-pro, +.qsm-email-page-template-pro { + position: relative; +} + +.qsm-result-page-template-pro::after, +.qsm-email-page-template-pro::after { + content: "PRO"; + position: absolute; + top: 8px; + right: 8%; + background-color: #FFEDF3; + color: white; + font-size: 11px; + font-weight: bold; + padding: 4px 8px; + border-radius: 10px; + color: #BD2457; +} + +#qsm-result-page-templates .qsm-popup__container, +#qsm-email-page-templates .qsm-popup__container { + max-width: initial; + padding: 0; + max-height: 80vh; + border-radius: 0; +} + +#qsm-result-page-templates .qsm-popup__close, +#qsm-email-page-templates .qsm-popup__close { + color: #1E1E1E; + font-weight: 600; +} + +#qsm-result-page-templates .qsm-result-page-template-card-buttons, +#qsm-email-page-templates .qsm-email-page-template-card-buttons { + max-width: 100px; + display: none; +} + +.qsm-result-page-template-card-buttons img.qsm-common-svg-image-class, +.qsm-email-page-template-card-buttons img.qsm-common-svg-image-class { + position: relative; + bottom: 4px; + padding-right: 3px; +} + +.qsm-result-page-template-header-tabs, +.qsm-email-page-template-header-tabs { + display: flex; + justify-content: center; + gap: 20px; +} + +#qsm-result-page-templates .qsm-popup__header, +#qsm-email-page-templates .qsm-popup__header { + display: grid; + grid-template-columns: 1.3fr 2fr; + border-bottom: 1px solid rgba(30, 30, 30, 0.1); + padding: 0 10px; +} + +#qsm-result-page-templates .qsm-popup__header .qsm-result-page-template-header-image, +#qsm-email-page-templates .qsm-popup__header .qsm-email-page-template-header-image { + max-height: 55px; +} + +.qsm-result-page-template-header-tabs .qsm-result-page-tmpl-header-links { + color: #1E1E1E; +} + +.qsm-result-page-template-header-left, +.qsm-email-page-template-header-left { + display: flex; + align-items: center; +} + +h2#qsm-result-page-templates-title, +h2#qsm-email-page-templates-title { + color: #1E1E1E; + font-size: 15px; + font-weight: 400; + padding-top: 4px; +} +.qsm-result-page-template-header-right, +.qsm-email-page-template-header-right { + display: flex; + gap: 20px; + justify-content: space-between; +} + +.qsm-result-page-template-header-tabs .qsm-result-page-tmpl-header-links.active, +.qsm-email-page-template-header-tabs .qsm-email-page-tmpl-header-links.active { + color: #1D4ED8; + font-weight: 500; + text-decoration: underline; + text-decoration-color: #1D4ED8; + text-underline-offset: 10px; +} + + +.qsm-actions-link-box a.qsm-delete-email-button:hover, .qsm-actions-link-box a.qsm-delete-result-button:hover { + background-color: #ffd4d4; +} +.results-page-show .wp-media-buttons, .email-show .wp-media-buttons { + margin-bottom: 10px; +} + +.results-page-show .wp-editor-tabs, .email-show .wp-editor-tabs { + margin-top: 10px; +} + +.results-page-show .qsm-result-page-content-buttons, .email-show .qsm-email-page-content-buttons { + margin-top: 15px; +} + +.qsm-result-page-template-card-buttons button.button, +.qsm-email-page-template-card-buttons button.button { + width: 100px; + border: none; + margin: 2px 0px 3px 0px; +} +button.qsm-result-page-template-preview-button.button img, +button.qsm-email-page-template-preview-button.button img { + height: 18px; +} + +.qsm-preview-result-page-template-container img.qsm-preview-template-image, +.qsm-preview-email-page-template-container img.qsm-preview-template-image { + width: 100%; +} + +#qsm-preview-result-page-templates .qsm-popup__container, +#qsm-preview-email-page-templates .qsm-popup__container { + max-height: 85vh; + max-width: 85vw; + padding: 0; +} + +#qsm-preview-result-page-templates .qsm-popup__container >*, +#qsm-preview-email-page-templates .qsm-popup__container >* { + padding: 15px 20px; +} + +#qsm-preview-result-page-templates .qsm-popup__header, +#qsm-preview-email-page-templates .qsm-popup__header { + border-bottom: 1px solid rgba(30, 30, 30, 0.1); +} + +#qsm-preview-result-page-templates .qsm-popup__content, +#qsm-preview-email-page-templates .qsm-popup__content { + margin: 0; +} @media screen and (min-width: 961px) { .folded .option-page-result-page-tab-footer, .folded .contact-page-tab-footer, @@ -3817,11 +4114,6 @@ button.button.qsm-extra-shortcode-popup span.dashicons.dashicons-shortcode { margin-right: 4px; } -.results-page-show .wp-media-buttons button.button { - border: 1px solid #2271B1; - font-weight: 500; -} - .qsm-quiz-result-tab button.add-new-page, .qsm-quiz-email-tab button.add-new-email { border: 1px solid #2271B1; @@ -3830,7 +4122,7 @@ button.button.qsm-extra-shortcode-popup span.dashicons.dashicons-shortcode { .qsm-extra-shortcode-conditional-button img.qsm-common-svg-image-class { vertical-align: text-top; - padding: 0 1px 0 0; + padding: 1px 1px 0 0; } .contact-form-actions .contact-form-actions-box a.disabled { @@ -3869,9 +4161,6 @@ button.button.qsm-extra-shortcode-popup span.dashicons.dashicons-shortcode { width: calc(100% - 85px); margin-left: 15px; } -.qsm-result-page-content-buttons { - margin-top: 5px; -} .results-page-show .qsm-result-page-content-buttons button.button:not(:first-child) { margin-left: 7px; @@ -3887,12 +4176,12 @@ button.button.qsm-extra-shortcode-popup span.dashicons.dashicons-shortcode { span.qsm-insert-template-variable-text { line-height: 2; margin-left: 7px; - color: #1E1E1E; + color: #555555; } .qsm-quiz-result-tab p.qsm-result-redirect-text { margin-bottom: 5px; - margin-top: 20px; + margin-top: 0; } .qsm_page_mlw_quiz_results .widefat tbody td input[type="checkbox"], diff --git a/js/qsm-admin.js b/js/qsm-admin.js index e0df57c76..c899632c8 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -1186,6 +1186,14 @@ function qsm_is_substring_in_array( text, array ) { $('.multiple-category-notice').show(); }(jQuery)); + +function qsmConvertContentToShortcode( contentToConvert ){ + let updatedContent = contentToConvert + .replace(/\[qsm([^\]]*)\](.*?)\[\/qsm([^\]]*)\]/gs, function(match, attributes, content, closingAttributes) { + return `[qsm${attributes}] ${content}[\/qsm${closingAttributes}] `; + }); + return updatedContent; +} //TinyMCE slash command auto suggest (function ($) { if (jQuery('body').hasClass('admin_page_mlw_quiz_options')) { @@ -1194,18 +1202,9 @@ function qsm_is_substring_in_array( text, array ) { if ( 'undefined' !== typeof tinymce && null !== tinymce && 'undefined' !== typeof qsm_admin_messages && null !== qsm_admin_messages ) { tinymce.PluginManager.add('qsmslashcommands', function(editor) { //Add stylesheet - editor.settings.extended_valid_elements = 'qsmvariabletag'; - editor.settings.custom_elements = '~qsmvariabletag'; - editor.settings.content_style = 'qsmvariabletag { color: #1E1E1E; background: #DCEDFA; margin: 0 3px; padding: 5px 8px; font-family: Arial, Helvetica, sans-serif;font-size: 12px;border-top: 1px solid #fff; line-height: 2.3; } qsmvariabletag:hover{ border: 1px solid #2271B1; background-color: #fff; box-shadow: 0px 4px 4px 0px #00000033; }'; - editor.addButton('qsm_slash_command', { - text: '/ ' +qsm_admin_messages.variables, - tooltip: qsm_admin_messages.insert_variable, - classes: 'qsm-variables-editor-btn', - onclick: function () { - editor.insertContent('/'); - showAutocomplete( editor, true ); - } - }); + editor.settings.extended_valid_elements = 'qsmvariabletag,qsmextrashortcodetag'; + editor.settings.custom_elements = '~qsmvariabletag,~qsmextrashortcodetag'; + editor.settings.content_style = 'qsmvariabletag, qsmextrashortcodetag { color: #1E1E1E; background: #DCEDFA; margin: 0 3px; padding: 5px 8px; font-family: Arial, Helvetica, sans-serif;font-size: 12px;border-top: 1px solid #fff; line-height: 2.3; } qsmvariabletag:hover, qsmextrashortcodetag:hover{ border: 1px solid #2271B1; background-color: #fff; box-shadow: 0px 4px 4px 0px #00000033; }'; //Auto complete commands let commands = []; for (let qsm_var_group in qsm_admin_messages.qsm_variables) { @@ -1295,8 +1294,10 @@ function qsm_is_substring_in_array( text, array ) { for (let i = 0; i <= qsm_search.length; i++) { editor.execCommand('Delete'); } - editor.execCommand('mceInsertContent', false, command.value.replace(/%([^%]+)%/g, '$1 ') ); - + editor.execCommand('mceInsertContent', false, command.value + .replace(/%([^%]+)%/g, '$1 ') + .replace(/\[qsm[^\]]*\](.*?)\[\/qsm[^\]]*\]/gs, '$1 ') + ); autocomplete.remove(); editor.getContainer().setAttribute('qsm_search', ''); editor.qsmShowAutocomplete = false; @@ -1338,7 +1339,8 @@ function qsm_is_substring_in_array( text, array ) { let selection = editor.selection; let range = selection.getRng(); let tagText = range.startContainer.parentNode.textContent; - if ( 'qsmvariabletag' === range.startContainer.parentNode.nodeName.toLowerCase() && range.startOffset === tagText.length ) { + let nodeName = range.startContainer.parentNode.nodeName.toLowerCase(); + if ( (nodeName === 'qsmvariabletag' || nodeName === 'qsmextrashortcodetag') && range.startOffset === tagText.length ) { let newParagraph = editor.dom.create('p'); editor.dom.insertAfter(newParagraph, range.startContainer.parentNode); range.setStartAfter(newParagraph); @@ -1412,9 +1414,12 @@ function qsm_is_substring_in_array( text, array ) { let variables = commands.map(function(item) { return item.value; }); - if (variables.includes(pastedValue)) { + if (variables.includes(pastedValue) || /\[qsm[^\]]*\](.*?)\[\/qsm[^\]]*\]/gs.test(pastedValue)) { event.preventDefault(); - editor.execCommand('mceInsertContent', false, pastedValue.replace(/%([^%]+)%/g, '$1 ') ); + // Replace the variable tags and qsm shortcodes correctly + let updatedContent = pastedValue.replace(/%([^%]+)%/g, '$1 '); // Handle %variable% + updatedContent = qsmConvertContentToShortcode(updatedContent); + editor.execCommand('mceInsertContent', false, updatedContent); } }); @@ -1870,7 +1875,7 @@ var QSMContact; jQuery(this).find('.qsm-condition-collection-count').text(index + 1); }); }, - addEmail: function (conditions, to, subject, content, replyTo, default_mark = false) { + addEmail: function (conditions, to, subject, content, replyTo, default_mark = false) { QSMAdminEmails.total += 1; var template = wp.template('email'); $('#qsm_emails').append(template({ id: QSMAdminEmails.total, to: to, subject: subject, content: content, replyTo: replyTo, default_mark: default_mark })); @@ -1890,7 +1895,7 @@ var QSMContact; tinymce: { plugins: "qsmslashcommands link image lists charmap colorpicker textcolor hr fullscreen wordpress", forced_root_block: '', - toolbar1: 'formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,qsm_slash_command,wp_adv', + toolbar1: 'formatselect,bold,italic,underline,bullist,numlist,blockquote,alignleft,aligncenter,alignright,link,wp_adv', toolbar2: 'strikethrough,hr,forecolor,pastetext,removeformat,charmap,outdent,indent,undo,redo,wp_help,wp_code,fullscreen', }, quicktags: true, @@ -1898,6 +1903,10 @@ var QSMContact; jQuery(document).trigger('qsm_tinyMCE_settings_after', [settings]); wp.editor.initialize('email-template-' + QSMAdminEmails.total, settings); } + const $emailBlock = jQuery(`#email-template-${QSMAdminEmails.total}`).closest('.email-show'); + const $conditionalButton = $emailBlock.find('.qsm-extra-shortcode-conditional-button'); + $emailBlock.find('.wp-media-buttons .insert-media').before($conditionalButton); + QSMAdminEmails.displayEmailEditor( $emailBlock ); jQuery(document).trigger('qsm_after_add_email_block', [conditions, to, subject, content, replyTo, QSMAdminEmails.total]); }, newEmail: function () { @@ -1913,13 +1922,133 @@ var QSMContact; var content = '%QUESTIONS_ANSWERS_EMAIL%'; var replyTo = false; QSMAdminEmails.addEmail(conditions, to, subject, content, replyTo); + }, + displayEmailEditor: function ( $emailBlock ){ + $emailBlock.find('.qsm-email-page-template-options').hide(); + $emailBlock.find('.qsm-email-page-editor-options').show(); + $emailBlock.find('.qsm-email-page-common-section').each(function () { + var section = $(this); + if (section.children().length > 0) { + if (!section.is(':visible')) { + section.show(); + } + } + }); } }; $(function () { QSMAdminEmails.loadEmails(); + jQuery(document).on('click', '.qsm-start-with-template', function (e) { + e.preventDefault(); + jQuery("#qsm-email-page-templates-content").data('email-page', jQuery(this).data('email-page')); + MicroModal.show('qsm-email-page-templates'); + }); + + jQuery(document).on('mouseenter', '.qsm-email-page-template-card-content', function () { + jQuery(this).find('.qsm-email-page-template-card-buttons').show(); + }); + + jQuery(document).on('mouseleave', '.qsm-email-page-template-card-content', function () { + jQuery(this).find('.qsm-email-page-template-card-buttons').hide(); + }); + + jQuery(document).on('click', '.qsm-start-with-canvas', function (e) { + e.preventDefault(); + const $emailBlock = jQuery(this).parents('.email-show'); + console.log($emailBlock) + }); + + jQuery(document).on('click', '.qsm-email-page-template-header .qsm-email-page-tmpl-header-links', function (e) { + jQuery(document).find(".qsm-email-page-tmpl-header-links").removeClass("active"); + jQuery(this).addClass("active"); + jQuery(document).find('.qsm-email-page-template-common').hide(); + jQuery(document).find('.qsm-email-'+jQuery(this).data('tab')+'-template-container').show(); + }); + + jQuery(document).on('click', '.qsm-email-page-template-preview-button', function (e) { + e.preventDefault(); + jQuery('#qsm-preview-email-page-templates-title').html(jQuery(this).parents('.qsm-email-page-template-card').find('.qsm-email-page-template-template-name').html()); + MicroModal.show('qsm-preview-email-page-templates'); + }); + + jQuery(document).on('click', '.qsm-email-page-template-insert-button', function (e) { + var uniqueId = $(this).data('unique-id'); // Get unique_id from the button + var templateName = $(this).closest('.qsm-email-page-template-card').find('.qsm-email-page-template-template-name').text(); // Get template name + var templateType = 'email'; // Default to 'email' for now + var templateContent = qsmEmailsObject.new_tmpl_data[uniqueId]; + var isFree = $(this).closest('.qsm-email-page-template-card').hasClass('qsm-email-page-template-pro') ? 'paid' : 'free'; // Check if it's free or paid + var button = $(this); // Store reference to the button + + // Send AJAX request to insert the template + $.ajax({ + url: ajaxurl, // WordPress AJAX URL + type: 'POST', + data: { + action: 'qsm_insert_quiz_template', + unique_id: uniqueId, + template_name: templateName, + template_type: templateType, + template_content: templateContent, + is_free: isFree + }, + beforeSend: function() { + // Optionally disable the button or show a loading indicator + button.prop('disabled', true); + }, + success: function(response) { + if (response.success) { + // On success, add the template to the list + var newTemplate = ''; + + // Append the newly inserted template to the container + $('.qsm-email-my-template-container').append(newTemplate); + button.closest('.qsm-email-page-template-card').find('.qsm-email-page-template-card-buttons').hide(); + button.html('Inserted'); + button.removeClass('qsm-email-page-template-insert-button'); + + // Wait for 3 seconds, then remove the parent element + setTimeout(function() { + console.log( button.parents('.qsm-email-page-template-card')); + button.parents('.qsm-email-page-template-card').fadeOut('slow', function() { + $(this).remove(); // Remove the element after fade-out animation completes + }); + }, 3000); + qsmEmailsObject.my_tmpl_data[uniqueId] = templateContent; + delete qsmEmailsObject.new_tmpl_data[uniqueId]; + } + }, + complete: function() { + button.prop('disabled', false); // Re-enable the button after AJAX completes + } + }); + }); + + jQuery(document).on('click', '.qsm-email-page-template-use-button', function (e) { + let email_page = jQuery("#qsm-email-page-templates-content").data('email-page'); + let editor = tinymce.get(email_page -1); + let templateValue = qsmEmailsObject.my_tmpl_data[jQuery(this).data('unique-id')]; + let updatedContent = templateValue.replace(/%([^%]+)%/g, '$1 '); // Handle %variable% + updatedContent = qsmConvertContentToShortcode(updatedContent).replace(/\\/g, ''); + editor.setContent(''); + editor.execCommand('mceInsertContent', false, updatedContent); + MicroModal.close('qsm-email-page-templates'); + const $emailBlock = jQuery(`#email-template-`+email_page).closest('.email-show'); + QSMAdminEmails.displayEmailEditor( $emailBlock ); + }); + $('.add-new-email').on('click', function (event) { event.preventDefault(); QSMAdminEmails.newEmail(); + let $lastEmailPage = jQuery(document).find('#qsm_emails').children().last(); + $lastEmailPage.find(".email-show > div:not(.email-content-header):not(.qsm-email-page-template-options)").hide(); + $lastEmailPage.find('.qsm-email-page-template-options').show(); }); jQuery(document).on('click', '.qsm-duplicate-email-template-button', function () { let template = jQuery(this).closest("header").next("main"); @@ -4156,6 +4285,7 @@ var QSM_Quiz_Broadcast_Channel; QSMAdminResults.updateResultConditonCount(jQuery('.results-page-when').eq(i)); }); QSMAdmin.clearAlerts(); + jQuery(document).find('.qsm-result-my-template-container').hide(); }) .fail(QSMAdmin.displayjQueryError); }, @@ -4226,7 +4356,39 @@ var QSM_Quiz_Broadcast_Channel; jQuery(document).trigger('qsm_after_add_result_block', [conditions, page, redirect, QSMAdminResults.total, singlePage]); const $resultsPage = jQuery(`#results-page-${QSMAdminResults.total}`).closest('.results-page-show'); const $conditionalButton = $resultsPage.find('.qsm-extra-shortcode-conditional-button'); - $resultsPage.find('.wp-media-buttons .insert-media').after($conditionalButton); + $resultsPage.find('.wp-media-buttons .insert-media').before($conditionalButton); + if ( + singlePage && + typeof singlePage === 'object' && + singlePage.hasOwnProperty('redirect') && + singlePage.redirect !== false && + singlePage.redirect !== '' + ){ + $resultsPage.find("> div:not(.results-page-content-header):not(.qsm-edit-result-view-options):not(.qsm-result-page-redirect-options)").hide(); + $resultsPage.find('.qsm-then-redirect-to-url').prop('checked', true); + $resultsPage.find('.qsm-result-page-template-options').hide(); + $resultsPage.find('.qsm-result-page-common-section').each(function () { + var section = $(this); // `this` refers to the current section in the loop + if (section.children().length > 0) { + if (!section.is(':visible')) { + section.show(); + } + } + }); + } else { + + if(typeof singlePage.redirect === 'undefined') { + // New Result Page + $resultsPage.find("> div:not(.results-page-content-header):not(.qsm-edit-result-view-options)").hide(); + $resultsPage.find('.qsm-result-page-template-options').show(); + } else { + // Default Loading Result Page + $resultsPage.find('.qsm-result-page-redirect-options').hide(); + $resultsPage.find('.qsm-result-page-template-options').hide(); + } + } + $resultsPage.find(".qsm-edit-result-input-option").removeClass("active"); + $resultsPage.find('input[name="qsm_then_show_result_option_'+QSMAdminResults.total+'"]:checked').closest(".qsm-edit-result-input-option").addClass("active"); }, newResultsPage: function () { var conditions = [{ @@ -4238,11 +4400,152 @@ var QSM_Quiz_Broadcast_Channel; }]; var page = '%QUESTIONS_ANSWERS% '; QSMAdminResults.addResultsPage(conditions, page); + }, + displayResultEditor: function ( $resultsPage ){ + $resultsPage.find(".qsm-result-page-editor-options").show(); + $resultsPage.find('.qsm-result-page-redirect-options').hide(); + $resultsPage.find('.qsm-result-page-template-options').hide(); + let section = $resultsPage.find('.qsm-result-page-common-section'); + if (section.children().length > 0) { + if (!section.is(':visible')) { + section.show(); + } + } } }; $(function () { QSMAdminResults.loadResults(); + jQuery(document).on('click', '.qsm-start-with-template', function (e) { + e.preventDefault(); + jQuery("#qsm-result-page-templates-content").data('result-page', jQuery(this).data('result-page')); + MicroModal.show('qsm-result-page-templates'); + }); + + jQuery(document).on('mouseenter', '.qsm-result-page-template-card-content', function () { + jQuery(this).find('.qsm-result-page-template-card-buttons').show(); + }); + + jQuery(document).on('mouseleave', '.qsm-result-page-template-card-content', function () { + jQuery(this).find('.qsm-result-page-template-card-buttons').hide(); + }); + + jQuery(document).on('click', '.qsm-start-with-canvas', function (e) { + e.preventDefault(); + const $resultsPage = jQuery(this).parents('.results-page-show'); + QSMAdminResults.displayResultEditor( $resultsPage ); + }); + + jQuery(document).on('click', '.qsm-result-page-template-header .qsm-result-page-tmpl-header-links', function (e) { + jQuery(document).find(".qsm-result-page-tmpl-header-links").removeClass("active"); + jQuery(this).addClass("active"); + jQuery(document).find('.qsm-result-page-template-common').hide(); + jQuery(document).find('.qsm-result-'+jQuery(this).data('tab')+'-template-container').show(); + }); + + jQuery(document).on('click', '.qsm-result-page-template-preview-button', function (e) { + e.preventDefault(); + jQuery('#qsm-preview-result-page-templates-title').html(jQuery(this).parents('.qsm-result-page-template-card').find('.qsm-result-page-template-template-name').html()); + MicroModal.show('qsm-preview-result-page-templates'); + }); + + jQuery(document).on('click', '.qsm-result-page-template-insert-button', function (e) { + var uniqueId = $(this).data('unique-id'); + var templateName = $(this).closest('.qsm-result-page-template-card').find('.qsm-result-page-template-template-name').text(); + var templateType = 'result'; + var templateContent = qsmResultsObject.new_tmpl_data[uniqueId]; + var isFree = $(this).closest('.qsm-result-page-template-card').hasClass('qsm-result-page-template-pro') ? 'paid' : 'free'; + var button = $(this); + + $.ajax({ + url: ajaxurl, + type: 'POST', + data: { + action: 'qsm_insert_quiz_template', + unique_id: uniqueId, + template_name: templateName, + template_type: templateType, + template_content: templateContent, + is_free: isFree + }, + beforeSend: function() { + button.prop('disabled', true); + }, + success: function(response) { + if (response.success) { + var newTemplate = '
'; + newTemplate += '
'; + newTemplate += '
'; + newTemplate += ''; + newTemplate += ''; + newTemplate += '
'; + newTemplate += '

' + response.data.template_name + '

'; + newTemplate += '
'; + $('.qsm-result-my-template-container').append(newTemplate); + button.closest('.qsm-result-page-template-card').find('.qsm-result-page-template-card-buttons').hide(); + button.html('Inserted'); + button.removeClass('qsm-result-page-template-insert-button'); + + // Wait for 3 seconds, then remove the parent element + setTimeout(function() { + console.log( button.parents('.qsm-result-page-template-card')); + button.parents('.qsm-result-page-template-card').fadeOut('slow', function() { + $(this).remove(); + }); + }, 3000); + qsmResultsObject.my_tmpl_data[uniqueId] = templateContent; + delete qsmResultsObject.new_tmpl_data[uniqueId]; + } + }, + complete: function() { + button.prop('disabled', false); + } + }); + }); + + jQuery(document).on('click', '.qsm-result-page-template-use-button', function (e) { + let editor = tinymce.get(jQuery("#qsm-result-page-templates-content").data('result-page') - 1); + let templateValue = qsmResultsObject.my_tmpl_data[jQuery(this).data('unique-id')]; + let updatedContent = templateValue.replace(/%([^%]+)%/g, '$1 '); // Handle %variable% + updatedContent = qsmConvertContentToShortcode(updatedContent).replace(/\\/g, ''); + editor.setContent(''); + editor.execCommand('mceInsertContent', false, updatedContent); + MicroModal.close('qsm-result-page-templates'); + const $resultsPage = jQuery(`#results-page-${jQuery("#qsm-result-page-templates-content").data('result-page')}`).closest('.results-page-show'); + QSMAdminResults.displayResultEditor( $resultsPage ); + }); + jQuery(document).on('change', '.results-page-show .qsm-then-show-result, .results-page-show .qsm-then-redirect-to-url', function () { + // Show/Hide content + let $this = jQuery(this); + let $parent = $this.parents('.results-page-show'); + + if ($this.val() === "1") { + let editor = tinymce.get($this.parents('.qsm-edit-result-view-options').data('result-page') - 1); + let content = editor.getContent().trim(); + if (content === "") { + console.log("Content is empty."); + $parent.find(".qsm-result-page-template-options").show(); + } else { + $parent.find(".qsm-result-page-template-options").hide(); + $parent.find(".qsm-result-page-editor-options").show(); + } + + $parent.find(".qsm-result-page-redirect-options").hide(); + } else if ($this.val() === "2") { + $parent.find(".qsm-result-page-template-options").hide(); + $parent.find(".qsm-result-page-editor-options").hide(); + $parent.find(".qsm-result-page-redirect-options").show(); + } + var section = $parent.find('.qsm-result-page-common-section'); + if (section.children().length > 0) { + if (!section.is(':visible')) { + section.show(); + } + } + + $parent.find(".qsm-edit-result-input-option").removeClass("active"); + $this.closest(".qsm-edit-result-input-option").addClass("active"); + }); $('.add-new-page').on('click', function (event) { event.preventDefault(); QSMAdminResults.newResultsPage(); @@ -4298,7 +4601,6 @@ var QSM_Quiz_Broadcast_Channel; let arrowUpImage = qsm_admin_messages.arrow_up_image; let arrowDownImage = qsm_admin_messages.arrow_down_image; - // Toggle the image if (currentSrc === arrowUpImage) { $img.attr('src', arrowDownImage); } else { @@ -4308,12 +4610,16 @@ var QSM_Quiz_Broadcast_Channel; jQuery(document).on('click', '.qsm-settings-box-result-button', function () { jQuery('.qsm-settings-box-details').not(jQuery(this).parents('.qsm-template-btn-group').find('.qsm-settings-box-details')).hide(); jQuery(this).parents('.qsm-template-btn-group').find('.qsm-settings-box-details').toggle(); - }); + }); jQuery(document).on('click', function (e) { // Check if the click was outside .qsm-template-btn-group if (!jQuery(e.target).closest('.qsm-template-btn-group').length) { jQuery('.qsm-settings-box-details').hide(); } + if (!$(event.target).closest('.email-show').length) { + let autocomplete = jQuery(document).find('.qsm-autocomplete'); + autocomplete.remove(); + } }); $(document).on('click', '.qsm_global_settings .qsm-generate-api-key', function (event) { diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index eea3325f7..dfd9ac137 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1394,6 +1394,9 @@ function qmnSocialShare(network, mlw_qmn_social_text, mlw_qmn_title, facebook_id "&" + "link=" + pageUrlEncoded + "&" + "name=" + encodeURIComponent(mlw_qmn_social_text) + "&" + "description="; } + if (network === 'linkedin') { + url = "https://www.linkedin.com/sharing/share-offsite?url=" + encodeURIComponent(mlw_qmn_social_text); + } if (network == 'twitter') { url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(mlw_qmn_social_text); } @@ -1756,6 +1759,9 @@ jQuery(function () { if (network == 'twitter') { url = "https://twitter.com/intent/tweet?text=" + social_text; } + if (network == 'linkedin') { + url = "https://www.linkedin.com/feed/?text=" + social_text; + } var sTop = window.screen.height / 2 - (218); var sLeft = window.screen.width / 2 - (313); var sqShareOptions = "height=400,width=580,toolbar=0,status=0,location=0,menubar=0,directories=0,scrollbars=0,top=" + sTop + ",left=" + sLeft; diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index e499f2bef..0acc543a1 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -773,12 +773,6 @@ public function qsm_add_user_capabilities() { if ( ! $role ) { return; } - // Remove all capabilities first. - foreach ( $administrator_capabilities as $cap ) { - if ( $role->has_cap( $cap ) ) { - $role->remove_cap( $cap ); - } - } // Dynamically determine the capabilities to add based on the current user role. $capabilities_to_add = isset(${$rolename . '_capabilities'}) ? ${$rolename . '_capabilities'} : array(); diff --git a/php/admin/admin-dashboard.php b/php/admin/admin-dashboard.php index 678cdc740..b2650283c 100644 --- a/php/admin/admin-dashboard.php +++ b/php/admin/admin-dashboard.php @@ -153,7 +153,7 @@ function qsm_generate_dashboard_page() {

- +
@@ -165,7 +165,7 @@ function qsm_generate_dashboard_page() {

- +
diff --git a/php/admin/functions.php b/php/admin/functions.php index 8eb6e113a..97113d3c8 100644 --- a/php/admin/functions.php +++ b/php/admin/functions.php @@ -251,9 +251,6 @@ function qsm_add_author_column_in_db() { $success = false; $mlwQuizMasterNext->log_manager->add( 'Error updating column charset utf8mb4_unicode_ci', "Tried $query but got {$wpdb->last_error}.", 0, 'error' ); } - } - - if ( $success ) { update_option( 'qsm_update_db_column_charset_utf8mb4_unicode_ci', 1 ); } } @@ -1717,4 +1714,71 @@ function qsm_advanced_assessment_quiz_page_content() { "addon_link" => qsm_get_plugin_link( 'downloads/advanced-assessment', 'quiz-documentation', 'plugin', 'advanced-assessment', 'qsm_plugin_upsell' ), ); qsm_admin_upgrade_content( $args, 'page' ); -} \ No newline at end of file +} + +function qsm_extra_shortcode_popup_window_button( $quiz_id, $categories ) { + if ( ! class_exists('QSM_Extra_Shortcodes') ) { + $qsm_pop_up_arguments = array( + "id" => 'modal-extra-shortcodes', + "title" => __('Extra Shortcode', 'quiz-master-next'), + "description" => __('Need dynamic content on your results pages? Our QSM conditional shortcode makes it easy. Create personalized experiences based on specific conditions or rules.', 'quiz-master-next'), + "chart_image" => plugins_url('', dirname(__FILE__)) . '/images/extra-shortcodes.png', + "information" => __('QSM Addon Bundle is the best way to get all our add-ons at a discount. Upgrade to save 95% today OR you can buy QSM Extra Shortodes Addon separately.', 'quiz-master-next'), + "buy_btn_text" => __('Buy QSM Extra Shortodes Addon', 'quiz-master-next'), + "doc_link" => qsm_get_plugin_link( 'docs/add-ons/extra-shortcodes/', 'qsm_list', 'extrashortcodea_button', 'extra-shortcodes-upsell_read_documentation', 'qsm_plugin_upsell' ), + "upgrade_link" => qsm_get_plugin_link( 'pricing', 'qsm_list', 'extrashortcodea_button', 'extra-shortcodes-upsell_upgrade', 'qsm_plugin_upsell' ), + "addon_link" => qsm_get_plugin_link( 'downloads/extra-shortcodes', 'qsm_list', 'extrashortcodea_button', 'extra-shortcodes-upsell_buy_addon', 'qsm_plugin_upsell' ), + ); + qsm_admin_upgrade_popup($qsm_pop_up_arguments); + ?> + + 'Missing required data.' )); + } + + // Sanitize the incoming data + $unique_id = sanitize_text_field($_POST['unique_id']); + $template_name = sanitize_text_field($_POST['template_name']); + $template_type = sanitize_text_field($_POST['template_type']); + $template_content = sanitize_textarea_field($_POST['template_content']); + $is_free = sanitize_text_field($_POST['is_free']); + + $table_name = $wpdb->prefix . 'mlw_quiz_output_templates'; + + // Insert the template into the database + $wpdb->insert( + $table_name, + array( + 'unique_id' => $unique_id, + 'template_name' => $template_name, + 'template_type' => $template_type, // Default type can be set as 'result' + 'template_content' => $template_content, + 'is_free' => $is_free, + 'created_at' => current_time('mysql'), + ), + array( '%s', '%s', '%s', '%s', '%s', '%s' ) // Format of the inserted data + ); + + // Get the inserted record's ID and other details + $inserted_id = $wpdb->insert_id; + + // Prepare the response with the inserted data + wp_send_json_success(array( + 'id' => $inserted_id, + 'template_name' => $template_name, + 'preview_url' => QSM_PLUGIN_URL . 'assets/eye-line-blue.png', // You can change this to a real preview image + )); +} diff --git a/php/admin/options-page-email-tab.php b/php/admin/options-page-email-tab.php index 823f06a45..83c16df15 100644 --- a/php/admin/options-page-email-tab.php +++ b/php/admin/options-page-email-tab.php @@ -28,17 +28,103 @@ function qsm_settings_email_tab() { * @since 4.4.0 */ function qsm_options_emails_tab_content() { - global $mlwQuizMasterNext; - + global $mlwQuizMasterNext, $wpdb; $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0; $user_id = get_current_user_id(); + + $table_name = $wpdb->prefix . 'mlw_quiz_output_templates'; + $temlate_sql = "SELECT unique_id, template_content FROM {$table_name}"; + $mlw_quiz_output_templates_results = $wpdb->get_results($temlate_sql); + $unique_ids = array_column($mlw_quiz_output_templates_results, 'unique_id'); + $template_contents = array_column($mlw_quiz_output_templates_results, 'template_content'); + // Combine into an associative array where unique_id is the key + $my_tmpl_data = array_combine($unique_ids, $template_contents); + + // Use array_column to extract the unique_id column + $existing_unique_ids = array_column($mlw_quiz_output_templates_results, 'unique_id'); + $qsm_quiz_output_templates_results = [ + (object) [ + 'id' => 1, + 'unique_id' => 'UID101', + 'template_name' => 'Template 1', + 'template_type' => 'email', + 'template_content' => 'Your score: %POINT_SCORE% out of %MAXIMUM_POINTS%. You scored %AMOUNT_CORRECT% correct answers out of %TOTAL_QUESTIONS%.', + 'is_free' => true, + ], + (object) [ + 'id' => 2, + 'unique_id' => 'UID102', + 'template_name' => 'Template 2', + 'template_type' => 'email', + 'template_content' => 'Congratulations %USER_NAME%! You answered %AMOUNT_CORRECT% out of %TOTAL_QUESTIONS% correctly. Your result: %POINT_SCORE%. + [qsm_conditions type="points" condition="equal" value="10"]You scored exactly 10 points! Well done![/qsm_conditions] + [qsm_conditions type="points" condition="greater" value="20"]Excellent! You scored more than 20 points![/qsm_conditions]', + 'is_free' => false, + ], + (object) [ + 'id' => 3, + 'unique_id' => 'UID103', + 'template_name' => 'Template 3', + 'template_type' => 'email', + 'template_content' => 'Great job, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% correct answers out of %TOTAL_QUESTIONS%.', + 'is_free' => true, + ], + (object) [ + 'id' => 4, + 'unique_id' => 'UID104', + 'template_name' => 'Template 4', + 'template_type' => 'email', + 'template_content' => 'Quiz complete! %USER_NAME%, your score is %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% correct answers! + [qsm_conditions type="points" condition="lessthan" value="5"]Oops! You scored less than 5 points. Better luck next time![/qsm_conditions]', + 'is_free' => false, + ], + (object) [ + 'id' => 5, + 'unique_id' => 'UID105', + 'template_name' => 'Template 5', + 'template_type' => 'email', + 'template_content' => 'Your quiz result: %POINT_SCORE% out of %MAXIMUM_POINTS%. Correct answers: %AMOUNT_CORRECT%.', + 'is_free' => true, + ], + (object) [ + 'id' => 6, + 'unique_id' => 'UID106', + 'template_name' => 'Template 6', + 'template_type' => 'email', + 'template_content' => 'Well done, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. Correct answers: %AMOUNT_CORRECT%.', + 'is_free' => false, + ], + (object) [ + 'id' => 7, + 'unique_id' => 'UID107', + 'template_name' => 'Template 7', + 'template_type' => 'email', + 'template_content' => 'Awesome, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% answers correct out of %TOTAL_QUESTIONS%. + [qsm_conditions type="points" condition="greater" value="15"]Excellent! You scored over 15 points![/qsm_conditions]', + 'is_free' => true, + ], + ]; + + $new_templates_uid = array_column($qsm_quiz_output_templates_results, 'unique_id'); + $new_template_contents = array_column($qsm_quiz_output_templates_results, 'template_content'); + // Combine into an associative array where unique_id is the key + $new_tmpl_data = array_combine($new_templates_uid, $new_template_contents); + + // Filter the incoming data to only include templates that have not been inserted + $new_templates = array_filter($qsm_quiz_output_templates_results, function( $template ) use ( $existing_unique_ids ) { + return ! in_array($template->unique_id, $existing_unique_ids); + }); + $js_data = array( 'quizID' => $quiz_id, 'nonce' => wp_create_nonce( 'wp_rest' ), 'qsm_user_ve' => get_user_meta( $user_id, 'rich_editing', true ), 'rest_user_nonce' => wp_create_nonce( 'wp_rest_nonce_' . $quiz_id . '_' . $user_id ), + 'my_tmpl_data' => $my_tmpl_data, + 'new_tmpl_data' => $new_tmpl_data, ); wp_localize_script( 'qsm_admin_js', 'qsmEmailsObject', $js_data ); + do_action( 'qsm_options_email_tab_content_before' ); $quiz_options = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'quiz_options' ); if ( isset( $quiz_options['send_email'] ) && 1 != $quiz_options['send_email'] ) { ?> @@ -58,8 +144,8 @@ function qsm_options_emails_tab_content() { @@ -157,6 +243,104 @@ function qsm_options_emails_tab_content() { + + + + + + +
- @@ -1400,15 +1400,15 @@ function qsm_options_questions_tab_template() {
- - + +
diff --git a/php/admin/options-page-results-page-tab.php b/php/admin/options-page-results-page-tab.php index 91d64e824..5cb28d67d 100644 --- a/php/admin/options-page-results-page-tab.php +++ b/php/admin/options-page-results-page-tab.php @@ -30,10 +30,95 @@ function qsm_options_results_tab_content() { global $mlwQuizMasterNext; $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : ''; $user_id = get_current_user_id(); + $table_name = $wpdb->prefix . 'mlw_quiz_output_templates'; + $temlate_sql = "SELECT unique_id, template_content FROM {$table_name}"; + $mlw_quiz_output_templates_results = $wpdb->get_results($temlate_sql); + $unique_ids = array_column($mlw_quiz_output_templates_results, 'unique_id'); + $template_contents = array_column($mlw_quiz_output_templates_results, 'template_content'); + // Combine into an associative array where unique_id is the key + $my_tmpl_data = array_combine($unique_ids, $template_contents); + + // Use array_column to extract the unique_id column + $existing_unique_ids = array_column($mlw_quiz_output_templates_results, 'unique_id'); + $qsm_quiz_output_templates_results = [ + (object) [ + 'id' => 1, + 'unique_id' => 'UID101', + 'template_name' => 'Template 1', + 'template_type' => 'result', + 'template_content' => 'Your score: %POINT_SCORE% out of %MAXIMUM_POINTS%. You scored %AMOUNT_CORRECT% correct answers out of %TOTAL_QUESTIONS%.', + 'is_free' => true, + ], + (object) [ + 'id' => 2, + 'unique_id' => 'UID102', + 'template_name' => 'Template 2', + 'template_type' => 'result', + 'template_content' => 'Congratulations %USER_NAME%! You answered %AMOUNT_CORRECT% out of %TOTAL_QUESTIONS% correctly. Your result: %POINT_SCORE%. + [qsm_conditions type="points" condition="equal" value="10"]You scored exactly 10 points! Well done![/qsm_conditions] + [qsm_conditions type="points" condition="greater" value="20"]Excellent! You scored more than 20 points![/qsm_conditions]', + 'is_free' => false, + ], + (object) [ + 'id' => 3, + 'unique_id' => 'UID103', + 'template_name' => 'Template 3', + 'template_type' => 'result', + 'template_content' => 'Great job, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% correct answers out of %TOTAL_QUESTIONS%.', + 'is_free' => true, + ], + (object) [ + 'id' => 4, + 'unique_id' => 'UID104', + 'template_name' => 'Template 4', + 'template_type' => 'result', + 'template_content' => 'Quiz complete! %USER_NAME%, your score is %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% correct answers! + [qsm_conditions type="points" condition="lessthan" value="5"]Oops! You scored less than 5 points. Better luck next time![/qsm_conditions]', + 'is_free' => false, + ], + (object) [ + 'id' => 5, + 'unique_id' => 'UID105', + 'template_name' => 'Template 5', + 'template_type' => 'result', + 'template_content' => 'Your quiz result: %POINT_SCORE% out of %MAXIMUM_POINTS%. Correct answers: %AMOUNT_CORRECT%.', + 'is_free' => true, + ], + (object) [ + 'id' => 6, + 'unique_id' => 'UID106', + 'template_name' => 'Template 6', + 'template_type' => 'result', + 'template_content' => 'Well done, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. Correct answers: %AMOUNT_CORRECT%.', + 'is_free' => false, + ], + (object) [ + 'id' => 7, + 'unique_id' => 'UID107', + 'template_name' => 'Template 7', + 'template_type' => 'result', + 'template_content' => 'Awesome, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% answers correct out of %TOTAL_QUESTIONS%. + [qsm_conditions type="points" condition="greater" value="15"]Excellent! You scored over 15 points![/qsm_conditions]', + 'is_free' => true, + ], + ]; + + $new_templates_uid = array_column($qsm_quiz_output_templates_results, 'unique_id'); + $new_template_contents = array_column($qsm_quiz_output_templates_results, 'template_content'); + // Combine into an associative array where unique_id is the key + $new_tmpl_data = array_combine($new_templates_uid, $new_template_contents); + + // Filter the incoming data to only include templates that have not been inserted + $new_templates = array_filter($qsm_quiz_output_templates_results, function( $template ) use ( $existing_unique_ids ) { + return ! in_array($template->unique_id, $existing_unique_ids); + }); + $js_data = array( 'quizID' => $quiz_id, 'nonce' => wp_create_nonce( 'wp_rest' ), 'rest_user_nonce' => wp_create_nonce( 'wp_rest_nonce_' . $quiz_id . '_' . $user_id ), + 'my_tmpl_data' => $my_tmpl_data, + 'new_tmpl_data' => $new_tmpl_data, ); wp_localize_script( 'qsm_admin_js', 'qsmResultsObject', $js_data ); do_action( 'qsm_options_results_tab_content_before' ); @@ -48,8 +133,8 @@ function qsm_options_results_tab_content() { @@ -190,6 +275,104 @@ function qsm_options_results_tab_content() { + + + + +
-

-

+

+

- + +
-

-

+

-
- 'modal-extra-shortcodes', - "title" => __('Extra Shortcode', 'quiz-master-next'), - "description" => __('Need dynamic content on your results pages? Our QSM conditional shortcode makes it easy. Create personalized experiences based on specific conditions or rules.', 'quiz-master-next'), - "chart_image" => plugins_url('', dirname(__FILE__)) . '/images/extra-shortcodes.png', - "information" => __('QSM Addon Bundle is the best way to get all our add-ons at a discount. Upgrade to save 95% today OR you can buy QSM Extra Shortodes Addon separately.', 'quiz-master-next'), - "buy_btn_text" => __('Buy QSM Extra Shortodes Addon', 'quiz-master-next'), - "doc_link" => qsm_get_plugin_link( 'docs/add-ons/extra-shortcodes/', 'qsm_list', 'extrashortcodea_button', 'extra-shortcodes-upsell_read_documentation', 'qsm_plugin_upsell' ), - "upgrade_link" => qsm_get_plugin_link( 'pricing', 'qsm_list', 'extrashortcodea_button', 'extra-shortcodes-upsell_upgrade', 'qsm_plugin_upsell' ), - "addon_link" => qsm_get_plugin_link( 'downloads/extra-shortcodes', 'qsm_list', 'extrashortcodea_button', 'extra-shortcodes-upsell_buy_addon', 'qsm_plugin_upsell' ), - ); - qsm_admin_upgrade_popup($qsm_pop_up_arguments); - ?> - - +
+
+
+ + +
+
+ + +
- -
- - / + if (qsm_is_substring_in_array(match, qsm_varaible_list)) { + return '' + capturedValue + ''; + } else if (/\[qsm[^\]]*\](.*?)\[\/qsm[^\]]*\]/gs.test(match)) { + return match.replace(/\[qsm[^\]]*\](.*?)\[\/qsm[^\]]*\]/gs, function(innerMatch, content) { + const openingTag = innerMatch.match(/\[qsm[^\]]*\]/)[0]; + const closingTag = innerMatch.match(/\[\/qsm[^\]]*\]/)[0]; + return `${openingTag}${content}${closingTag}`; + }); + } else { + return match; + } + }) }}} + +
+ + / +
-
- +

+
+
+ +
diff --git a/php/admin/options-page-style-tab.php b/php/admin/options-page-style-tab.php index 321eddfcd..b3489588f 100644 --- a/php/admin/options-page-style-tab.php +++ b/php/admin/options-page-style-tab.php @@ -176,7 +176,7 @@ function qsm_options_styling_tab_content() {


- +
'; @@ -187,7 +187,7 @@ function qsm_options_styling_tab_content() { - + diff --git a/php/admin/options-page-text-tab.php b/php/admin/options-page-text-tab.php index f1cba582d..81e9046ae 100644 --- a/php/admin/options-page-text-tab.php +++ b/php/admin/options-page-text-tab.php @@ -103,7 +103,7 @@ function mlw_options_text_tab_content() {
- +
@@ -157,7 +157,7 @@ function mlw_options_text_tab_content() {
-
diff --git a/php/admin/quiz-options-page.php b/php/admin/quiz-options-page.php index 8f81d03d8..ec1c6d8fd 100644 --- a/php/admin/quiz-options-page.php +++ b/php/admin/quiz-options-page.php @@ -206,7 +206,7 @@ function qsm_generate_quiz_options() { diff --git a/php/classes/class-qmn-plugin-helper.php b/php/classes/class-qmn-plugin-helper.php index 8e73e67a1..cca0bd78b 100644 --- a/php/classes/class-qmn-plugin-helper.php +++ b/php/classes/class-qmn-plugin-helper.php @@ -642,6 +642,7 @@ public static function get_default_texts() { 'scheduled_timeframe_text' => '', 'twitter_sharing_text' => __('I just scored %CORRECT_SCORE%% on %QUIZ_NAME%!', 'quiz-master-next'), 'facebook_sharing_text' => __('I just scored %CORRECT_SCORE%% on %QUIZ_NAME%!', 'quiz-master-next'), + 'linkedin_sharing_text' => __('I just scored %CORRECT_SCORE%% on %QUIZ_NAME%!', 'quiz-master-next'), 'submit_button_text' => __('Submit', 'quiz-master-next'), 'retake_quiz_button_text' => __('Retake Quiz', 'quiz-master-next'), 'previous_button_text' => __('Previous', 'quiz-master-next'), @@ -1123,7 +1124,7 @@ public function convert_contacts_to_preferred_date_format( $qsm_qna_array ) { $qsm_contact_array = $qsm_qna_array['contact']; foreach ( $qsm_contact_array as $qsm_contact_id => $qsm_contact ) { - if ( 'date' === $qsm_contact['type'] && '' !== $qsm_contact['value'] && null !== $GLOBALS['qsm_date_format'] ) { + if ( ( isset($qsm_contact['type']) && 'date' === $qsm_contact['type'] ) && ( isset($qsm_contact['value']) && '' !== $qsm_contact['value'] ) && null !== $GLOBALS['qsm_date_format'] ) { $qsm_qna_array['contact'][ $qsm_contact_id ]['value'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime( ( $qsm_contact['value'] ) ) ); } } diff --git a/php/classes/class-qmn-quiz-manager.php b/php/classes/class-qmn-quiz-manager.php index 8431275c4..11cd5c3fd 100644 --- a/php/classes/class-qmn-quiz-manager.php +++ b/php/classes/class-qmn-quiz-manager.php @@ -1126,29 +1126,6 @@ public function display_quiz( $options, $quiz_data, $question_amount, $shortcode $randomness_class = 0 === intval( $options->randomness_order ) ? '' : 'random'; ?>
qmn_quiz_container mlw_qmn_quiz quiz_theme_ '> 1, - 'post_type' => 'qsm_quiz', - 'meta_query' => array( - array( - 'key' => 'quiz_id', - 'value' => $quiz_data['quiz_id'], - 'compare' => '=', - ), - ), - ); - $the_query = new WP_Query( $args ); - - // The Loop - if ( $the_query->have_posts() ) { - while ( $the_query->have_posts() ) { - $the_query->the_post(); - echo get_the_post_thumbnail( get_the_ID(), 'full' ); - } - /* Restore original Post Data */ - wp_reset_postdata(); - } echo apply_filters( 'qsm_display_before_form', '', $options, $quiz_data ); $quiz_form_action = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; ?> @@ -2673,11 +2650,13 @@ public function display_social( $qmn_quiz_options, $qmn_array_for_variables ) { $qmn_social_media_text = array( 'twitter' => $qmn_quiz_options->social_media_text, 'facebook' => $qmn_quiz_options->social_media_text, + 'linkedin' => $qmn_quiz_options->social_media_text, ); } $qmn_social_media_text['twitter'] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text['twitter'], $qmn_array_for_variables ); $qmn_social_media_text['facebook'] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text['facebook'], $qmn_array_for_variables ); - $social_display .= "
quiz_name ) . "', '" . esc_js( $facebook_app_id ) . "');\">Facebookquiz_name ) . "');\">Twitter
"; + $qmn_social_media_text['linkedin'] = apply_filters( 'mlw_qmn_template_variable_results_page', $qmn_social_media_text['linkedin'], $qmn_array_for_variables ); + $social_display .= "
quiz_name ) . "', '" . esc_js( $facebook_app_id ) . "');\">Facebookquiz_name ) . "');\">Twitterquiz_name ) . "');\">Linkedin
"; } return apply_filters( 'qmn_returned_social_buttons', $social_display, $qmn_quiz_options, $qmn_array_for_variables ); } diff --git a/php/classes/class-qsm-emails.php b/php/classes/class-qsm-emails.php index c10da8205..1ab64d2cf 100644 --- a/php/classes/class-qsm-emails.php +++ b/php/classes/class-qsm-emails.php @@ -524,6 +524,13 @@ function( $matches ) { }, $emails[ $i ]['content'] ); + $emails[ $i ]['content'] = preg_replace_callback( + '/([^<]+)<\/qsmextrashortcodetag>/u', + function( $matches ) { + return wp_strip_all_tags( preg_replace('/^\s+|\s+$/u', '', $matches[1] ) ); + }, + $emails[ $i ]['content'] + ); $emails[ $i ]['content'] = wp_kses_post( $emails[ $i ]['content'] ); } $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $emails[ $i ]['subject'], "quiz-email-subject-{$i}-{$quiz_id}" ); diff --git a/php/classes/class-qsm-fields.php b/php/classes/class-qsm-fields.php index bc81b4c30..16015c660 100644 --- a/php/classes/class-qsm-fields.php +++ b/php/classes/class-qsm-fields.php @@ -309,9 +309,9 @@ public static function generate_section( $fields, $section ) {
diff --git a/php/classes/class-qsm-install.php b/php/classes/class-qsm-install.php index eb02b062c..189f4ff12 100644 --- a/php/classes/class-qsm-install.php +++ b/php/classes/class-qsm-install.php @@ -806,7 +806,7 @@ public function register_default_settings() { ), 'default' => 0, /* translators: %FACEBOOK_SHARE%: Facebook share link, %TWITTER_SHARE%: Twitter share link */ - 'tooltip' => __( 'Please use the new template variables instead.%FACEBOOK_SHARE% %TWITTER_SHARE%', 'quiz-master-next' ), + 'tooltip' => __( 'Please use the new template variables instead.%FACEBOOK_SHARE% %TWITTER_SHARE% %LINKEDIN_SHARE%', 'quiz-master-next' ), 'option_tab' => 'legacy', ); $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_options' ); @@ -1073,6 +1073,27 @@ public function register_default_settings() { ); $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_text' ); + // Registers linkedin_sharing_text setting + $field_array = array( + 'id' => 'linkedin_sharing_text', + 'label' => __( 'Linkedin Sharing Text', 'quiz-master-next' ), + 'type' => 'editor', + 'default' => 0, + 'variables' => array( + '%POINT_SCORE%', + '%AVERAGE_POINT%', + '%AMOUNT_CORRECT%', + '%TOTAL_QUESTIONS%', + '%CORRECT_SCORE%', + '%QUIZ_NAME%', + '%QUIZ_LINK%', + '%RESULT_LINK%', + '%TIMER%', + '%CURRENT_DATE%', + ), + ); + $mlwQuizMasterNext->pluginHelper->register_quiz_setting( $field_array, 'quiz_text' ); + // Registers facebook_sharing_text setting $field_array = array( 'id' => 'facebook_sharing_text', @@ -1953,8 +1974,8 @@ public function update() { } // Update 7.1.11 - $user_email_template_data = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $wpdb->prefix . "mlw_quizzes LIKE 'user_email_template'" ); - if ( 'text' === $user_email_template_data->Type ) { + $user_email_my_tmpl_data = $wpdb->get_row( 'SHOW COLUMNS FROM ' . $wpdb->prefix . "mlw_quizzes LIKE 'user_email_template'" ); + if ( 'text' === $user_email_my_tmpl_data->Type ) { $sql = 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes MODIFY user_email_template LONGTEXT'; $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); } @@ -1966,12 +1987,6 @@ public function update() { $results = $mlwQuizMasterNext->wpdb_alter_table_query( $sql ); } - // Update 2.6.1 - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_qm_audit_trail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' ); - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_questions CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); - $results = $mlwQuizMasterNext->wpdb_alter_table_query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' ); - global $wpdb; $table_name = $wpdb->prefix . 'mlw_results'; $audit_table = $wpdb->prefix . 'mlw_qm_audit_trail'; @@ -2036,9 +2051,6 @@ public function update() { if ( ! get_option( 'fix_deleted_quiz_posts' ) ) { QSM_Migrate::fix_deleted_quiz_posts(); } - - update_option( 'mlw_quiz_master_version', $data ); - // Update 9.1.3 $mlw_questions_table = $wpdb->prefix . 'mlw_questions'; if ( 'linked_question' != $wpdb->get_var( "SHOW COLUMNS FROM $mlw_questions_table LIKE 'linked_question'" ) ) { @@ -2047,6 +2059,29 @@ public function update() { $update_sql = 'UPDATE ' . $mlw_questions_table . ' SET linked_question = \'\' WHERE linked_question IS NULL'; $results = $mlwQuizMasterNext->wpdb_alter_table_query( $update_sql ); } + + $quiz_templates_table_name = $wpdb->prefix . 'mlw_quiz_output_templates'; + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$quiz_templates_table_name}'" ) != $quiz_templates_table_name ) { + // SQL to create the table + $charset_collate = $wpdb->get_charset_collate(); + $sql = "CREATE TABLE {$quiz_templates_table_name} ( + id BIGINT(20) UNSIGNED AUTO_INCREMENT, + unique_id VARCHAR(20) DEFAULT NULL, + template_name VARCHAR(255) DEFAULT NULL, + template_type VARCHAR(50) DEFAULT 'result', + template_content LONGTEXT DEFAULT NULL, + is_free VARCHAR(10) DEFAULT 'free', + PRIMARY KEY (id), + created_at DATETIME DEFAULT CURRENT_TIMESTAMP + ) $charset_collate;"; + + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + + dbDelta( $sql ); + } + + // Update QSM versoin at last + update_option( 'mlw_quiz_master_version', $data ); } if ( ! get_option( 'mlw_advert_shows' ) ) { add_option( 'mlw_advert_shows', 'true' ); diff --git a/php/classes/class-qsm-results-pages.php b/php/classes/class-qsm-results-pages.php index fc981ed1d..06f56231d 100644 --- a/php/classes/class-qsm-results-pages.php +++ b/php/classes/class-qsm-results-pages.php @@ -376,6 +376,13 @@ function( $matches ) { }, $pages[ $i ]['page'] ); + $pages[ $i ]['page'] = preg_replace_callback( + '/([^<]+)<\/qsmextrashortcodetag>/u', + function( $matches ) { + return wp_strip_all_tags( preg_replace('/^\s+|\s+$/u', '', $matches[1] ) ); + }, + $pages[ $i ]['page'] + ); $pages[ $i ]['page'] = wp_kses_post( $pages[ $i ]['page'] ); } $pages[ $i ]['default_mark'] = sanitize_text_field( $pages[ $i ]['default_mark'] ); diff --git a/php/classes/class-qsm-settings.php b/php/classes/class-qsm-settings.php index 076833438..2b1129152 100644 --- a/php/classes/class-qsm-settings.php +++ b/php/classes/class-qsm-settings.php @@ -360,6 +360,7 @@ private function load_settings() { $social_media_text = array( 'twitter' => $quiz_options->social_media_text, 'facebook' => $quiz_options->social_media_text, + 'linkedin' => $quiz_options->social_media_text, ); } @@ -394,6 +395,7 @@ private function load_settings() { 'total_user_tries_text' => $quiz_options->total_user_tries_text, 'twitter_sharing_text' => $social_media_text['twitter'], 'facebook_sharing_text' => $social_media_text['facebook'], + 'linkedin_sharing_text' => $social_media_text['linkedin'], 'previous_button_text' => $pagination_text[0], 'next_button_text' => $pagination_text[1], 'require_log_in_text' => $quiz_options->require_log_in_text, diff --git a/php/question-types/qsm-question-type-fill-in-the-blanks.php b/php/question-types/qsm-question-type-fill-in-the-blanks.php index 9d2837733..370604a47 100644 --- a/php/question-types/qsm-question-type-fill-in-the-blanks.php +++ b/php/question-types/qsm-question-type-fill-in-the-blanks.php @@ -50,12 +50,14 @@ function qmn_fill_blank_display( $id, $question, $answers ) { if ( ! empty( $question ) ) { $question = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( html_entity_decode( $question, ENT_HTML5 ), ENT_QUOTES ), "question-description-{$id}", "QSM Questions" ); } + $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' ); if ( strpos( $question, '%BLANK%' ) !== false ) { - $question = str_replace( '%BLANK%', $input_text, do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) ); + $question = str_replace( '%BLANK%', $input_text, htmlspecialchars_decode( $question, ENT_QUOTES ) ); + qsm_question_title_func( $question, 'fill_in_blank', $new_question_title, $id ); + $question = do_shortcode( $question ); + } else { + qsm_question_title_func( $question, 'fill_in_blank', $new_question_title, $id ); } - // $question_title = apply_filters('the_content', $question); - $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' ); - qsm_question_title_func( $question, 'fill_in_blank', $new_question_title, $id ); echo apply_filters( 'qmn_fill_blank_display_front', '', $id, $question, $answers ); } diff --git a/php/shortcodes.php b/php/shortcodes.php index 3076f6535..6ba8f462b 100644 --- a/php/shortcodes.php +++ b/php/shortcodes.php @@ -44,51 +44,10 @@ function qsm_quiz_link_shortcode( $atts, $content = '' ) { // Craft the target attribute if one is passed to shortcode $target_html = ''; - $allowed_tags = apply_filters( 'qsm_quiz_link_allowed_tags', array( - 'span' => array( - 'class' => true, - 'id' => true, - 'style' => true, - ), - 'a' => array( - 'href' => true, - 'target' => true, - 'class' => true, - 'id' => true, - 'rel' => true, - ), - 'img' => array( - 'src' => true, - 'alt' => true, - 'width' => true, - 'height' => true, - 'class' => true, - 'id' => true, - ), - 'div' => array( - 'class' => true, - 'id' => true, - 'style' => true, - ), - 'h1' => array( 'class' => true ), - 'h2' => array( 'class' => true ), - 'h3' => array( 'class' => true ), - 'h4' => array( 'class' => true ), - 'h5' => array( 'class' => true ), - 'h6' => array( 'class' => true ), - 'p' => array(), - 'br' => array(), - 'b' => array(), - 'strong' => array(), - 'i' => array(), - 'em' => array(), - 'u' => array(), - ) ); - if ( ! empty( $target ) ) { - return "" . wp_kses( $content, $allowed_tags ) . ''; + return "" . do_shortcode( $content ) . ''; } else { - return "" . wp_kses( $content, $allowed_tags ) . ''; + return "" . do_shortcode( $content ) . ''; } } diff --git a/php/template-variables.php b/php/template-variables.php index aee4cb81b..87caf6773 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -312,6 +312,14 @@ function mlw_qmn_variable_social_share( $content, $mlw_quiz_array ) { $social_display = "" . __( "; $content = str_replace( '%TWITTER_SHARE%', $social_display, $content ); } + if ( false !== strpos( $content, '%LINKEDIN_SHARE%' ) ) { + $ln_image = plugins_url( '', dirname( __FILE__ ) ) . '/assets/linkedin.png'; + $sharing = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_text', 'linkedin_sharing_text', '%QUIZ_NAME%' ); + $sharing = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $sharing, "quiz_linkedin_sharing_text-{$mlw_quiz_array['quiz_id']}" ); + $sharing = apply_filters( 'mlw_qmn_template_variable_results_page', $sharing, $mlw_quiz_array ); + $social_display = "" . __( "; + $content = str_replace( '%LINKEDIN_SHARE%', $social_display, $content ); + } return $content; } @@ -525,12 +533,14 @@ function qsm_all_contact_fields_variable( $content, $results ) { $return = ''; if ( isset( $results['contact'] ) && ( is_array( $results['contact'] ) || is_object( $results['contact'] ) ) ) { foreach ( $results['contact'] as $results_contact ) { - $options = qsm_get_options_of_contact_fields($contact_form, $results_contact['label'], $results_contact['type'] ); - $isRadioOrSelect = in_array($results_contact['type'], [ 'radio', 'select' ], true); - $hasOptions = ! empty(trim($options)); + if ( isset( $results_contact['label'] ) && isset( $results_contact['type'] ) && isset( $results_contact['value'] ) ) { + $options = qsm_get_options_of_contact_fields($contact_form, $results_contact['label'], $results_contact['type'] ); + $isRadioOrSelect = in_array($results_contact['type'], [ 'radio', 'select' ], true); + $hasOptions = ! empty(trim($options)); - if ( ($isRadioOrSelect && $hasOptions) || ! $isRadioOrSelect ) { - $return .= $results_contact['label'] . ': ' . $results_contact['value'] . '
'; + if ( ($isRadioOrSelect && $hasOptions) || ! $isRadioOrSelect ) { + $return .= $results_contact['label'] . ': ' . $results_contact['value'] . '
'; + } } } } From a7f58d9f2a660aa7e42b791aaed0681f738d2004 Mon Sep 17 00:00:00 2001 From: etchirag Date: Fri, 13 Dec 2024 12:40:39 +0530 Subject: [PATCH 02/18] Updated Template settings options and minimize the code --- assets/add-large-fill.svg | 1 + assets/download-line.svg | 1 + assets/share-forward-box-fill.svg | 1 + css/qsm-admin.css | 157 ++++++-- data/templates.json | 62 ++++ js/qsm-admin.js | 391 ++++++++++++-------- mlw_quizmaster2.php | 6 + php/admin/functions.php | 187 ++++++++-- php/admin/options-page-email-tab.php | 234 +++--------- php/admin/options-page-results-page-tab.php | 228 ++---------- php/classes/class-qsm-install.php | 12 +- 11 files changed, 673 insertions(+), 607 deletions(-) create mode 100644 assets/add-large-fill.svg create mode 100644 assets/download-line.svg create mode 100644 assets/share-forward-box-fill.svg create mode 100644 data/templates.json diff --git a/assets/add-large-fill.svg b/assets/add-large-fill.svg new file mode 100644 index 000000000..9d6989bb1 --- /dev/null +++ b/assets/add-large-fill.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/download-line.svg b/assets/download-line.svg new file mode 100644 index 000000000..881622c9b --- /dev/null +++ b/assets/download-line.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/share-forward-box-fill.svg b/assets/share-forward-box-fill.svg new file mode 100644 index 000000000..af045c7b6 --- /dev/null +++ b/assets/share-forward-box-fill.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/css/qsm-admin.css b/css/qsm-admin.css index 350646413..f58e5aed2 100644 --- a/css/qsm-admin.css +++ b/css/qsm-admin.css @@ -556,8 +556,9 @@ span.qsm-quiz-name { .qsm_tab_content .results-page-condition .qsm-result-condition-container input[type="text"], .email-condition select, .qsm_tab_content .email-condition .qsm-email-condition-container input[type="text"], -.qsm_tab_content .results-page-show .qsm-result-page-common-section select, -.qsm_tab_content .results-page-show .qsm-result-page-common-section input[type="text"], +.results-page-content .qsm-result-page-common-section select, +.results-page-content .qsm-result-page-common-section input[type="text"], +.results-page-content .qsm-result-page-redirect-options input[type="text"], .qsm-email-content .qsm-email-page-common-section select, .qsm-email-content .qsm-email-page-common-section input[type="text"], .qsm-email-content .qsm-email-page-common-section input[type="email"] { @@ -2897,7 +2898,9 @@ input#duplicate_questions { .qsm-actions-link-box a:not(:first-child) { border-left: 1px solid #d6d6d6; } -.qsm-actions-link-box a.qsm-settings-box-result-button:focus { +.qsm-actions-link-box a.qsm-settings-box-result-button:focus, +.qsm-actions-link-box a.qsm-settings-box-email-button:focus, +.qsm-actions-link-box a.qsm-insert-page-template-anchor:focus { background-color: #ebf4fc; } .results-page-when .qsm-new-condition, .qsm-email-when .qsm-new-condition, @@ -3610,14 +3613,20 @@ input#duplicate_questions { font-weight: 600; } -.qsm-result-page-template-container, .qsm-result-my-template-container, -.qsm-email-page-template-container, .qsm-email-my-template-container { +.qsm-result-page-template-container, +.qsm-email-page-template-container { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; +} + +.qsm-result-page-template-container, .qsm-result-my-template-container, +.qsm-email-page-template-container, .qsm-email-my-template-container { padding: 0 25px; - min-height: 75vh; - min-width: 75vw; + height: 75vh; + width: 75vw; + max-height: 75vh; + max-width: 75vw; } .qsm-result-page-template-card, @@ -3664,27 +3673,7 @@ input#duplicate_questions { font-size: 14px; color: #333; } - -.qsm-result-page-template-pro, -.qsm-email-page-template-pro { - position: relative; -} - -.qsm-result-page-template-pro::after, -.qsm-email-page-template-pro::after { - content: "PRO"; - position: absolute; - top: 8px; - right: 8%; - background-color: #FFEDF3; - color: white; - font-size: 11px; - font-weight: bold; - padding: 4px 8px; - border-radius: 10px; - color: #BD2457; -} - + #qsm-result-page-templates .qsm-popup__container, #qsm-email-page-templates .qsm-popup__container { max-width: initial; @@ -3722,7 +3711,7 @@ input#duplicate_questions { #qsm-result-page-templates .qsm-popup__header, #qsm-email-page-templates .qsm-popup__header { display: grid; - grid-template-columns: 1.3fr 2fr; + grid-template-columns: 1.4fr 2fr; border-bottom: 1px solid rgba(30, 30, 30, 0.1); padding: 0 10px; } @@ -3766,7 +3755,7 @@ h2#qsm-email-page-templates-title { } -.qsm-actions-link-box a.qsm-delete-email-button:hover, .qsm-actions-link-box a.qsm-delete-result-button:hover { +.qsm-actions-link-box a.qsm-delete-email-button:hover, .qsm-actions-link-box a.qsm-delete-result-button:hover, .qsm-my-template-rows-actions a.qsm-result-page-template-remove-button:hover, .qsm-my-template-rows-actions a.qsm-email-page-template-remove-button:hover { background-color: #ffd4d4; } .results-page-show .wp-media-buttons, .email-show .wp-media-buttons { @@ -3818,6 +3807,114 @@ button.qsm-email-page-template-preview-button.button img { #qsm-preview-email-page-templates .qsm-popup__content { margin: 0; } + +.qsm-actions-link-box .qsm-insert-page-template-anchor { + position: relative; +} + +.qsm-actions-link-box .qsm-insert-template-wrap { + position: absolute; + display: none; + left: -205px; + width: 300px; + top: 45px; + z-index: 100; + padding: 10px; + border-radius: 4px; + background: #ffffff; + border: 1px solid #dfd4d4; + cursor: initial; + box-shadow: 0 0 6px 2px #ddd; + max-width: 300px; +} +.qsm_tab_content .qsm-insert-template-wrap input[type="text"]qsm-insert-page-template-title { + min-width: 240px; + width: 240px; +} + +.qsm-insert-template-container { + display: flex; + justify-content: space-between; + align-items: flex-start; +} + +.qsm-insert-template-left:before { + content: " "; + position: absolute; + top: -22px; + left: 69%; + margin-left: -12px; + border-width: 12px; + border-style: solid; + border-color: transparent transparent #ffffff transparent; + z-index: 1; +} + +.qsm-insert-template-left:after { + content: " "; + position: absolute; + top: -24px; + left: 69%; + margin-left: -12px; + border-width: 12px; + border-style: solid; + border-color: transparent transparent #dfd4d4 transparent; + z-index: 0; +} + +.qsm-insert-template-wrap span.qsm-insert-template-response { + display: block; + font-size: 12px; +} +.results-page-show a.qsm-view-templates-list, +.email-show a.qsm-view-templates-list { + position: absolute; + right: 20px; + top: 9px; + font-weight: bold; + padding: 0; + color: #1D4EDD; +} +.qsm-my-templates-table-body .qsm-my-template-rows-actions { + display: flex; + align-items: center; +} + +.qsm-my-templates-table-body .qsm-my-template-rows-actions a { + padding: 5px; + color: #3c434a; + border: 1px solid #ddd; + cursor: pointer; + background: #eee; + background-color: #fff; + display: flex; + align-items: center; +} +.qsm-my-template-rows-actions a:hover, .qsm-my-template-rows-actions a:focus { + background: #f8f8f8; + color: #000000; + border: 1px solid #ddd; +} +.qsm-my-templates-table-body .qsm-my-template-rows-actions a:first-child { + border-radius: 5px 0 0 5px; +} +.qsm-my-templates-table-body .qsm-my-template-rows-actions .qsm-result-page-template-remove-button, +.qsm-my-templates-table-body .qsm-my-template-rows-actions .qsm-email-page-template-remove-button { + border-radius: 0 5px 5px 0px; + border-left: 0; +} +.qsm-my-templates-table-body .qsm-my-template-rows-actions img { + height: 18px; + padding: 0; +} + +.qsm-my-templates-table-body .qsm-my-template-rows-actions .qsm-spinner-loader { + font-size: 6px; +} +.widefat .qsm-my-templates-table-body td, .widefat .qsm-my-templates-table-body th { + vertical-align: middle; +} + @media screen and (min-width: 961px) { .folded .option-page-result-page-tab-footer, .folded .contact-page-tab-footer, diff --git a/data/templates.json b/data/templates.json new file mode 100644 index 000000000..4c9dcc804 --- /dev/null +++ b/data/templates.json @@ -0,0 +1,62 @@ +[ + { + "id": 1, + "template_name": "Basic Result Overview", + "template_type": "result", + "template_content": "

Quiz Name: %QUIZ_NAME%

\n

Participant Name: %FULL_NAME%

\n

Business: %USER_BUSINESS%

\n

Email: %USER_EMAIL%

\n

Phone: %USER_PHONE%

\n
\n

Your Score:

\n

You scored %POINT_SCORE% out of a possible %MAXIMUM_POINTS%.

\n
    \n
  • Questions Attempted: %AMOUNT_ATTEMPTED%
  • \n
  • Correct Answers: %AMOUNT_CORRECT%
  • \n
  • Incorrect Answers: %AMOUNT_INCORRECT%
  • \n
  • Average Score: %AVERAGE_POINT%
  • \n
\n
\n

Time Taken:

\n
    \n
  • Total Time: %TIMER%
  • \n
  • Minutes: %TIMER_MINUTES%
  • \n
  • Seconds: %TIMER_SECONDS%
  • \n
" + }, + { + "id": 2, + "template_name": "Detailed Score Breakdown", + "template_type": "result", + "template_content": "

Quiz Results:

\n

You scored %POINT_SCORE% out of %MAXIMUM_POINTS%.

\n
    \n
  • Your Correct Score: %CORRECT_SCORE%
  • \n
  • Total Questions: %TOTAL_QUESTIONS%
  • \n
\n
\n

Category Breakdown:

\n

%CATEGORY_POINTS_X%:

\n
    \n
  • Category Points: %CATEGORY_POINTS_X%
  • \n
  • Category Average Score: %CATEGORY_AVERAGE_SCORE%
  • \n
  • Category Average Points: %CATEGORY_AVERAGE_POINTS%
  • \n
\n
\n

Question Performance:

\n

Below is a summary of your performance on individual questions:

\n

%QUESTIONS_ANSWERS%

\n
\n

Quiz Link:
\nView your quiz results

" + }, + { + "id": 3, + "template_name": "Results with Comments Section", + "template_type": "email", + "template_content": "

Your Quiz Result:

\n

Congratulations, %FULL_NAME%! You scored %POINT_SCORE% out of %MAXIMUM_POINTS%.

\n
\n
    \n
  • Total Questions: %TOTAL_QUESTIONS%
  • \n
  • Correct Answers: %AMOUNT_CORRECT%
  • \n
  • Incorrect Answers: %AMOUNT_INCORRECT%
  • \n
\n
\n

Timer Details:

\n
    \n
  • Time Finished: %TIME_FINISHED%
  • \n
  • Timer (Minutes): %TIMER_MINUTES%
  • \n
  • Timer (Seconds): %TIMER_SECONDS%
  • \n
\n
\n

Quiz Results Breakdown:

\n

%QUESTIONS_ANSWERS%

\n
\n

Feedback and Comments:

\n

Your feedback is valuable! Please leave your comments below:

\n

%COMMENT_SECTION%

" + }, + { + "id": 4, + "template_name": "Detailed Performance with Results Link", + "template_type": "email", + "template_content": "

Quiz Result Overview:

\n

%USER_NAME%, you completed the quiz titled %QUIZ_NAME% and scored %POINT_SCORE% out of %MAXIMUM_POINTS%.

\n
\n
    \n
  • Correct Answers: %AMOUNT_CORRECT%
  • \n
  • Incorrect Answers: %AMOUNT_INCORRECT%
  • \n
  • Questions Attempted: %AMOUNT_ATTEMPTED%
  • \n
\n
\n

Category Breakdown:

\n

Category %CATEGORY_SCORE_X%:

\n
    \n
  • Points: %CATEGORY_POINTS_X%
  • \n
  • Average Score: %CATEGORY_AVERAGE_SCORE%
  • \n
  • Average Points: %CATEGORY_AVERAGE_POINTS%
  • \n
\n
\n

Question-by-Question Performance:

\n

Below you will find a breakdown of each question’s performance:

\n

%QUESTIONS_ANSWERS_EMAIL%

\n
\n

Click here to review your full results

" + }, + { + "id": 5, + "template_name": "Summary with Contact Info", + "template_type": "result", + "template_content": "

Quiz Results Summary:

\n

Your results for %QUIZ_NAME% are as follows:

\n
    \n
  • Total Points: %POINT_SCORE%
  • \n
  • Maximum Points: %MAXIMUM_POINTS%
  • \n
  • Total Correct Answers: %AMOUNT_CORRECT%
  • \n
  • Total Incorrect Answers: %AMOUNT_INCORRECT%
  • \n
  • Average Points: %AVERAGE_POINT%
  • \n
\n
\n

Performance by Category:

\n
    \n
  • Category %CATEGORY_SCORE_X%:
  • \n
  • Points: %CATEGORY_POINTS_X%
  • \n
  • Average Score: %CATEGORY_AVERAGE_SCORE%
  • \n
  • Average Points: %CATEGORY_AVERAGE_POINTS%
  • \n
\n
\n

Timer Information:

\n
    \n
  • Total Time Spent: %TIMER%
  • \n
  • Minutes: %TIMER_MINUTES%
  • \n
  • Seconds: %TIMER_SECONDS%
  • \n
\n
\n

Need Assistance?

\n

If you have any questions or need help, feel free to reach out:

\n
    \n
  • Email: %USER_EMAIL%
  • \n
  • Phone: %USER_PHONE%
  • \n
  • Business: %USER_BUSINESS%
  • \n
" + }, + { + "id": 6, + "template_name": "Success with Final Score", + "template_type": "result", + "template_content": "

Well Done, %FULL_NAME%!

\n

You’ve successfully completed the quiz %QUIZ_NAME%!

\n

Your Final Score: %POINT_SCORE% out of %MAXIMUM_POINTS%

\n

Total Correct Answers: %AMOUNT_CORRECT%

\n

Total Incorrect Answers: %AMOUNT_INCORRECT%

\n
\n

Time Taken:

\n
    \n
  • Total Time: %TIMER%
  • \n
  • Time in Minutes: %TIMER_MINUTES%
  • \n
  • Time in Seconds: %TIMER_SECONDS%
  • \n
\n
\n

Review Your Full Results

" + }, + { + "id": 7, + "template_name": "Category Performance Overview", + "template_type": "email", + "template_content": "

Quiz Result Summary

\n

%FULL_NAME%, here’s a detailed breakdown of your performance in %QUIZ_NAME%.

\n

Total Score: %POINT_SCORE% out of %MAXIMUM_POINTS%

\n

Total Correct Answers: %AMOUNT_CORRECT%

\n

Total Incorrect Answers: %AMOUNT_INCORRECT%

\n
\n

Category Breakdown:

\n

%CATEGORY_SCORE_X%:

\n
    \n
  • Points: %CATEGORY_POINTS_X%
  • \n
  • Average Score: %CATEGORY_AVERAGE_SCORE%
  • \n
  • Average Points: %CATEGORY_AVERAGE_POINTS%
  • \n
\n
\n

For more details on your individual questions, click below.

\n

View Full Results

" + }, + { + "id": 8, + "template_name": "Summary with Questions and Answers", + "template_type": "email", + "template_content": "

Quiz Results for %QUIZ_NAME%

\n

Congratulations, %FULL_NAME%! You’ve completed the quiz.

\n

Your Total Score: %POINT_SCORE% out of %MAXIMUM_POINTS%

\n

Total Correct Answers: %AMOUNT_CORRECT%

\n

Total Incorrect Answers: %AMOUNT_INCORRECT%

\n
\n

Question-by-Question Performance:

\n

%QUESTIONS_ANSWERS%

\n
\n

Quiz Details:

\n
    \n
  • Average Score: %AVERAGE_POINT%
  • \n
  • Total Questions: %TOTAL_QUESTIONS%
  • \n
  • Time Taken: %TIMER%
  • \n
\n
\n

View Results Again

" + }, + { + "id": 9, + "template_name": "Quick Performance Snapshot", + "template_type": "result", + "template_content": "

Quick Results for %QUIZ_NAME%

\n

%FULL_NAME%, you finished the quiz!

\n

Your Score: %POINT_SCORE% / %MAXIMUM_POINTS%

\n

Correct Answers: %AMOUNT_CORRECT%

\n

Incorrect Answers: %AMOUNT_INCORRECT%

\n
\n

Quiz Performance Summary:

\n

Average Score: %AVERAGE_POINT%

\n

Total Time Spent: %TIMER%

\n
\n

Review all your results by following the link below.

\n

Click to View Full Results

" + }, + { + "id": 10, + "template_name": "Result with User Feedback", + "template_type": "email", + "template_content": "

%QUIZ_NAME% - Results

\n

Thank you for taking the quiz, %FULL_NAME%!

\n

Your Score: %POINT_SCORE% out of %MAXIMUM_POINTS%

\n

Correct Answers: %AMOUNT_CORRECT% | Incorrect Answers: %AMOUNT_INCORRECT%

\n
\n

Time and Performance Summary:

\n
    \n
  • Time Taken: %TIMER%
  • \n
  • Average Score: %AVERAGE_POINT%
  • \n
\n
\n

Your Feedback:

\n

We would love to hear your feedback on the quiz. Please leave your comments below:

\n

%COMMENT_SECTION%

\n
\n

Review Your Full Results

" + } +] diff --git a/js/qsm-admin.js b/js/qsm-admin.js index c899632c8..1d02ca653 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -3,6 +3,7 @@ */ var QSMAdmin; +var QSMAdminResultsAndEmail; (function ($) { QSMAdmin = { @@ -852,6 +853,173 @@ if(current_id == 'qsm_variable_text'){ jQuery(".current_variable")[0].click();} }); }); } + if ( window.location.href.indexOf('tab=emails') > 0 || window.location.href.indexOf('tab=results-pages') > 0 ) { + QSMAdminResultsAndEmail = { + insertTemplate: async function (button, data) { + const templateResponse = button.parents('.qsm-insert-template-wrap').find('.qsm-insert-template-response'); + try { + button.prop('disabled', true); + const response = await jQuery.ajax({ + url: ajaxurl, + type: 'POST', + data: data, + beforeSend: function () { + templateResponse.text(qsm_admin_messages.add_process).css('color', '#000000');; + } + }); + jQuery(document).find('.qsm-no-templates-row').remove(); + if (response.success) { + QSMAdminResultsAndEmail.addTemplateRow(response.data); + return response; + } else { + return { success: false, message: response.message || 'Unknown error' }; + } + } catch (error) { + return { success: false, message: error.message }; + } finally { + button.prop('disabled', false); + button.text(qsm_admin_messages.add_more); + } + }, + headerLinks: function ( link, templateType ) { + jQuery(document).find('.qsm-'+templateType+'-page-tmpl-header-links').removeClass('active'); + link.addClass("active"); + jQuery(document).find('.qsm-'+templateType+'-page-template-common').hide(); + jQuery(document).find('.qsm-'+templateType+'-'+link.data('tab')+'-template-container').show(); + }, + addTemplateRow: function ( data ) { + var template = wp.template('qsm-my-template-rows'); + jQuery('.qsm-my-templates-table-body').append(template(data)); + }, + loadMyTemplates: function ( type ) { + if(type == 'result'){ + if (Array.isArray(qsmResultsObject.my_tmpl_data)) { + qsmResultsObject.my_tmpl_data.forEach(function (filteredRow, key) { + filteredRow.indexid = key; + QSMAdminResultsAndEmail.addTemplateRow(filteredRow); + }); + } + } else if(type == 'email'){ + if (Array.isArray(qsmEmailsObject.my_tmpl_data)) { + qsmEmailsObject.my_tmpl_data.forEach(function (filteredRow, key) { + filteredRow.indexid = key; + QSMAdminResultsAndEmail.addTemplateRow(filteredRow); + }); + } + } + } + }; + + jQuery(document).ready(function () { + jQuery(document).on('click', '.qsm-insert-page-template-button', async function (e) { + e.preventDefault(); + const button = jQuery(this); + const templateName = jQuery(this).parents('.qsm-insert-template-wrap').find('.qsm-insert-page-template-title').val().trim(); + const templateResponse = jQuery(this).parents('.qsm-insert-template-wrap').find('.qsm-insert-template-response'); + const uniqueId = button.data('id'); + const editor = tinymce.get(uniqueId - 1); + const templateType = button.parents('.qsm-insert-page-template-anchor').data('template-type'); + const templateContent = editor.getContent().trim(); + templateResponse.text(''); + if (!templateName) { + templateResponse.text(qsm_admin_messages.empty_template_name).css('color', 'red'); + return; + } + if (!templateContent) { + templateResponse.text(qsm_admin_messages.empty_template_content).css('color', 'red'); + return; + } + const data = { + action: 'qsm_insert_quiz_template', + template_name: templateName, + template_type: templateType, + template_content: templateContent, + }; + try { + const response = await QSMAdminResultsAndEmail.insertTemplate(button, data); + if (response?.success) { + if(templateType == 'result') { + response.data.id = qsmResultsObject.my_tmpl_data.length > 0 ? qsmResultsObject.my_tmpl_data.length - 1 : 0; + qsmResultsObject.my_tmpl_data.push(response.data); + } else if(templateType == 'email') { + response.data.id = qsmEmailsObject.my_tmpl_data.length > 0 ? qsmEmailsObject.my_tmpl_data.length - 1 : 0; + qsmEmailsObject.my_tmpl_data.push(response.data); + } + templateResponse.text(qsm_admin_messages.template_added).css('color', 'green'); + button.parents('.qsm-insert-template-wrap').find('.qsm-insert-page-template-title').val(''); + } + } catch (error) { + console.error('An error occurred during template insertion:', error.message); + templateResponse.text(qsm_admin_messages.template_save_error).css('color', 'red'); + } + }); + jQuery(document).on('click', '.qsm-insert-page-template-anchor', function (e) { + var templateWrap = jQuery(this).find('.qsm-insert-template-wrap'); + jQuery(this).find('.qsm-insert-template-response').text(''); + if (!templateWrap.is(':visible')) { + templateWrap.show(); + } + }); + + jQuery(document).on('click', 'a.qsm-view-templates-list', function (e) { + e.preventDefault(); + let templateType = jQuery(this).data('type'); + if(templateType == 'result') { + var resultPageIndex = jQuery(this).parents('.results-page-show').data('result-page'); + jQuery("#qsm-result-page-templates-content").attr('data-result-page', resultPageIndex); + } else if(templateType == 'email') { + var emailPageValue = jQuery(this).parents('.email-show').data('email-page'); + jQuery("#qsm-email-page-templates-content").attr('data-email-page', emailPageValue); + } + MicroModal.show('qsm-'+templateType+'-page-templates'); + }); + + jQuery(document).on('click', 'a.qsm-result-page-template-remove-button, a.qsm-email-page-template-remove-button', async function (e) { + e.preventDefault(); + if (!confirm(qsm_admin_messages.confirmDeleteText)) { + return; + } + const button = jQuery(this); + const templateId = button.data('id'); + const type = button.data('type'); + let nonce; + if (type === 'result') { nonce = qsmResultsObject.remove_tmpl_nonce; } + else if (type === 'email') { nonce = qsmEmailsObject.remove_tmpl_nonce; } else { + console.error("Unknown template type."); + return; + } + button.prop('disabled', true); + const loader = jQuery('
'); + button.after(loader); + try { + const response = await jQuery.ajax({ + url: ajaxurl, + type: 'POST', + data: { + action: 'qsm_remove_my_templates', + id: templateId, + nonce: nonce, + } + }); + if (response.success) { + console.log(response.data.message); + setTimeout(function () { + button.closest('tr').fadeOut('slow', function () { + jQuery(this).remove(); + }); + }, 1000); + } else { + console.error(response.data.message || "Failed to remove the template."); + } + } catch (error) { + console.error("AJAX request failed:", error); + } finally { + loader.remove(); + button.prop('disabled', false); + } + }); + }); + } } @@ -1837,6 +2005,7 @@ var QSMContact; QSMAdminEmails.addEmail(email.conditions, email.to, email.subject, email.content, email.replyTo, email.default_mark); }); QSMAdmin.clearAlerts(); + jQuery(document).find('.qsm-email-my-template-container').hide(); }) .fail(QSMAdmin.displayjQueryError); }, @@ -1919,7 +2088,7 @@ var QSMContact; }]; var to = '%USER_EMAIL%'; var subject = 'Quiz Results For %QUIZ_NAME%'; - var content = '%QUESTIONS_ANSWERS_EMAIL%'; + var content = ''; var replyTo = false; QSMAdminEmails.addEmail(conditions, to, subject, content, replyTo); }, @@ -1932,15 +2101,19 @@ var QSMContact; if (!section.is(':visible')) { section.show(); } + } else { + section.hide(); } }); } }; $(function () { QSMAdminEmails.loadEmails(); + QSMAdminResultsAndEmail.loadMyTemplates( 'email' ); jQuery(document).on('click', '.qsm-start-with-template', function (e) { e.preventDefault(); - jQuery("#qsm-email-page-templates-content").data('email-page', jQuery(this).data('email-page')); + var emailPageValue = jQuery(this).data('email-page'); + jQuery("#qsm-email-page-templates-content").attr('data-email-page', emailPageValue); MicroModal.show('qsm-email-page-templates'); }); @@ -1956,85 +2129,37 @@ var QSMContact; e.preventDefault(); const $emailBlock = jQuery(this).parents('.email-show'); console.log($emailBlock) + let email_page = $emailBlock.data('email-page'); + let editor = tinymce.get(email_page - 1); + let updatedContent = '%QUESTIONS_ANSWERS_EMAIL%'.replace(/%([^%]+)%/g, '$1 '); + updatedContent = qsmConvertContentToShortcode(updatedContent).replace(/\\/g, ''); + editor.setContent(''); + editor.execCommand('mceInsertContent', false, updatedContent); + QSMAdminEmails.displayEmailEditor( $emailBlock ); + MicroModal.close('qsm-email-page-templates'); }); - jQuery(document).on('click', '.qsm-email-page-template-header .qsm-email-page-tmpl-header-links', function (e) { - jQuery(document).find(".qsm-email-page-tmpl-header-links").removeClass("active"); - jQuery(this).addClass("active"); - jQuery(document).find('.qsm-email-page-template-common').hide(); - jQuery(document).find('.qsm-email-'+jQuery(this).data('tab')+'-template-container').show(); - }); - jQuery(document).on('click', '.qsm-email-page-template-preview-button', function (e) { e.preventDefault(); jQuery('#qsm-preview-email-page-templates-title').html(jQuery(this).parents('.qsm-email-page-template-card').find('.qsm-email-page-template-template-name').html()); MicroModal.show('qsm-preview-email-page-templates'); }); - - jQuery(document).on('click', '.qsm-email-page-template-insert-button', function (e) { - var uniqueId = $(this).data('unique-id'); // Get unique_id from the button - var templateName = $(this).closest('.qsm-email-page-template-card').find('.qsm-email-page-template-template-name').text(); // Get template name - var templateType = 'email'; // Default to 'email' for now - var templateContent = qsmEmailsObject.new_tmpl_data[uniqueId]; - var isFree = $(this).closest('.qsm-email-page-template-card').hasClass('qsm-email-page-template-pro') ? 'paid' : 'free'; // Check if it's free or paid - var button = $(this); // Store reference to the button - - // Send AJAX request to insert the template - $.ajax({ - url: ajaxurl, // WordPress AJAX URL - type: 'POST', - data: { - action: 'qsm_insert_quiz_template', - unique_id: uniqueId, - template_name: templateName, - template_type: templateType, - template_content: templateContent, - is_free: isFree - }, - beforeSend: function() { - // Optionally disable the button or show a loading indicator - button.prop('disabled', true); - }, - success: function(response) { - if (response.success) { - // On success, add the template to the list - var newTemplate = ''; - - // Append the newly inserted template to the container - $('.qsm-email-my-template-container').append(newTemplate); - button.closest('.qsm-email-page-template-card').find('.qsm-email-page-template-card-buttons').hide(); - button.html('Inserted'); - button.removeClass('qsm-email-page-template-insert-button'); - - // Wait for 3 seconds, then remove the parent element - setTimeout(function() { - console.log( button.parents('.qsm-email-page-template-card')); - button.parents('.qsm-email-page-template-card').fadeOut('slow', function() { - $(this).remove(); // Remove the element after fade-out animation completes - }); - }, 3000); - qsmEmailsObject.my_tmpl_data[uniqueId] = templateContent; - delete qsmEmailsObject.new_tmpl_data[uniqueId]; - } - }, - complete: function() { - button.prop('disabled', false); // Re-enable the button after AJAX completes - } - }); + + jQuery(document).on('click', '.qsm-email-page-template-header .qsm-email-page-tmpl-header-links', function (e) { + QSMAdminResultsAndEmail.headerLinks( jQuery(this), 'email' ); }); jQuery(document).on('click', '.qsm-email-page-template-use-button', function (e) { + let structure = jQuery(this).data('structure'); + let templateValue; + if (structure == 'default') { + templateValue = qsmEmailsObject.script_tmpl[jQuery(this).data('indexid')].template_content; + } else if (structure == 'custom') { + templateValue = qsmEmailsObject.my_tmpl_data[jQuery(this).data('indexid')].template_content; + } let email_page = jQuery("#qsm-email-page-templates-content").data('email-page'); let editor = tinymce.get(email_page -1); - let templateValue = qsmEmailsObject.my_tmpl_data[jQuery(this).data('unique-id')]; - let updatedContent = templateValue.replace(/%([^%]+)%/g, '$1 '); // Handle %variable% + let updatedContent = templateValue.replace(/%([^%]+)%/g, '$1 '); updatedContent = qsmConvertContentToShortcode(updatedContent).replace(/\\/g, ''); editor.setContent(''); editor.execCommand('mceInsertContent', false, updatedContent); @@ -4367,14 +4492,7 @@ var QSM_Quiz_Broadcast_Channel; $resultsPage.find("> div:not(.results-page-content-header):not(.qsm-edit-result-view-options):not(.qsm-result-page-redirect-options)").hide(); $resultsPage.find('.qsm-then-redirect-to-url').prop('checked', true); $resultsPage.find('.qsm-result-page-template-options').hide(); - $resultsPage.find('.qsm-result-page-common-section').each(function () { - var section = $(this); // `this` refers to the current section in the loop - if (section.children().length > 0) { - if (!section.is(':visible')) { - section.show(); - } - } - }); + QSMAdminResults.hideShowResultPageSection($resultsPage); } else { if(typeof singlePage.redirect === 'undefined') { @@ -4398,26 +4516,33 @@ var QSM_Quiz_Broadcast_Channel; 'operator': 'greater', 'value': '0' }]; - var page = '%QUESTIONS_ANSWERS% '; + var page = ''; QSMAdminResults.addResultsPage(conditions, page); }, displayResultEditor: function ( $resultsPage ){ $resultsPage.find(".qsm-result-page-editor-options").show(); $resultsPage.find('.qsm-result-page-redirect-options').hide(); $resultsPage.find('.qsm-result-page-template-options').hide(); - let section = $resultsPage.find('.qsm-result-page-common-section'); - if (section.children().length > 0) { - if (!section.is(':visible')) { - section.show(); + QSMAdminResults.hideShowResultPageSection($resultsPage); + }, + hideShowResultPageSection: function ( $resultsPage ) { + $resultsPage.find('.qsm-result-page-common-section').each(function () { + var section = $(this); // `this` refers to the current section in the loop + if (section.children().length > 0) { + if (!section.is(':visible')) { + section.show(); + } } - } + }); } }; $(function () { QSMAdminResults.loadResults(); + QSMAdminResultsAndEmail.loadMyTemplates( 'result' ); jQuery(document).on('click', '.qsm-start-with-template', function (e) { e.preventDefault(); - jQuery("#qsm-result-page-templates-content").data('result-page', jQuery(this).data('result-page')); + var resultPageIndex = jQuery(this).parents('.results-page-show').data('result-page'); + jQuery("#qsm-result-page-templates-content").attr('data-result-page', resultPageIndex); MicroModal.show('qsm-result-page-templates'); }); @@ -4431,86 +4556,40 @@ var QSM_Quiz_Broadcast_Channel; jQuery(document).on('click', '.qsm-start-with-canvas', function (e) { e.preventDefault(); - const $resultsPage = jQuery(this).parents('.results-page-show'); + let $resultsPage = jQuery(this).parents('.results-page-show'); + let resultPageIndex = $resultsPage.data('result-page'); + let editor = tinymce.get(resultPageIndex - 1); + let updatedContent = '%QUESTIONS_ANSWERS% '.replace(/%([^%]+)%/g, '$1 '); + editor.execCommand('mceInsertContent', false, updatedContent); QSMAdminResults.displayResultEditor( $resultsPage ); }); - jQuery(document).on('click', '.qsm-result-page-template-header .qsm-result-page-tmpl-header-links', function (e) { - jQuery(document).find(".qsm-result-page-tmpl-header-links").removeClass("active"); - jQuery(this).addClass("active"); - jQuery(document).find('.qsm-result-page-template-common').hide(); - jQuery(document).find('.qsm-result-'+jQuery(this).data('tab')+'-template-container').show(); - }); - jQuery(document).on('click', '.qsm-result-page-template-preview-button', function (e) { e.preventDefault(); jQuery('#qsm-preview-result-page-templates-title').html(jQuery(this).parents('.qsm-result-page-template-card').find('.qsm-result-page-template-template-name').html()); MicroModal.show('qsm-preview-result-page-templates'); }); - - jQuery(document).on('click', '.qsm-result-page-template-insert-button', function (e) { - var uniqueId = $(this).data('unique-id'); - var templateName = $(this).closest('.qsm-result-page-template-card').find('.qsm-result-page-template-template-name').text(); - var templateType = 'result'; - var templateContent = qsmResultsObject.new_tmpl_data[uniqueId]; - var isFree = $(this).closest('.qsm-result-page-template-card').hasClass('qsm-result-page-template-pro') ? 'paid' : 'free'; - var button = $(this); - - $.ajax({ - url: ajaxurl, - type: 'POST', - data: { - action: 'qsm_insert_quiz_template', - unique_id: uniqueId, - template_name: templateName, - template_type: templateType, - template_content: templateContent, - is_free: isFree - }, - beforeSend: function() { - button.prop('disabled', true); - }, - success: function(response) { - if (response.success) { - var newTemplate = '
'; - newTemplate += '
'; - newTemplate += '
'; - newTemplate += ''; - newTemplate += ''; - newTemplate += '
'; - newTemplate += '

' + response.data.template_name + '

'; - newTemplate += '
'; - $('.qsm-result-my-template-container').append(newTemplate); - button.closest('.qsm-result-page-template-card').find('.qsm-result-page-template-card-buttons').hide(); - button.html('Inserted'); - button.removeClass('qsm-result-page-template-insert-button'); - - // Wait for 3 seconds, then remove the parent element - setTimeout(function() { - console.log( button.parents('.qsm-result-page-template-card')); - button.parents('.qsm-result-page-template-card').fadeOut('slow', function() { - $(this).remove(); - }); - }, 3000); - qsmResultsObject.my_tmpl_data[uniqueId] = templateContent; - delete qsmResultsObject.new_tmpl_data[uniqueId]; - } - }, - complete: function() { - button.prop('disabled', false); - } - }); - }); + jQuery(document).on('click', '.qsm-result-page-template-header .qsm-result-page-tmpl-header-links', function (e) { + QSMAdminResultsAndEmail.headerLinks( jQuery(this), 'result' ); + }); + jQuery(document).on('click', '.qsm-result-page-template-use-button', function (e) { - let editor = tinymce.get(jQuery("#qsm-result-page-templates-content").data('result-page') - 1); - let templateValue = qsmResultsObject.my_tmpl_data[jQuery(this).data('unique-id')]; - let updatedContent = templateValue.replace(/%([^%]+)%/g, '$1 '); // Handle %variable% + let structure = jQuery(this).data('structure'); + let templateValue; + if (structure == 'default') { + templateValue = qsmResultsObject.script_tmpl[jQuery(this).data('indexid')].template_content; + } else if (structure == 'custom') { + templateValue = qsmResultsObject.my_tmpl_data[jQuery(this).data('indexid')].template_content; + } + let result_index = jQuery("#qsm-result-page-templates-content").data('result-page'); + let editor = tinymce.get(result_index - 1); + let updatedContent = templateValue.replace(/%([^%]+)%/g, '$1 '); updatedContent = qsmConvertContentToShortcode(updatedContent).replace(/\\/g, ''); editor.setContent(''); editor.execCommand('mceInsertContent', false, updatedContent); MicroModal.close('qsm-result-page-templates'); - const $resultsPage = jQuery(`#results-page-${jQuery("#qsm-result-page-templates-content").data('result-page')}`).closest('.results-page-show'); + const $resultsPage = jQuery(`#results-page-${result_index}`).closest('.results-page-show'); QSMAdminResults.displayResultEditor( $resultsPage ); }); jQuery(document).on('change', '.results-page-show .qsm-then-show-result, .results-page-show .qsm-then-redirect-to-url', function () { @@ -4519,7 +4598,7 @@ var QSM_Quiz_Broadcast_Channel; let $parent = $this.parents('.results-page-show'); if ($this.val() === "1") { - let editor = tinymce.get($this.parents('.qsm-edit-result-view-options').data('result-page') - 1); + let editor = tinymce.get($parent.data('result-page') - 1); let content = editor.getContent().trim(); if (content === "") { console.log("Content is empty."); @@ -4536,12 +4615,7 @@ var QSM_Quiz_Broadcast_Channel; $parent.find(".qsm-result-page-redirect-options").show(); } - var section = $parent.find('.qsm-result-page-common-section'); - if (section.children().length > 0) { - if (!section.is(':visible')) { - section.show(); - } - } + QSMAdminResults.hideShowResultPageSection($parent); $parent.find(".qsm-edit-result-input-option").removeClass("active"); $this.closest(".qsm-edit-result-input-option").addClass("active"); @@ -4607,7 +4681,7 @@ var QSM_Quiz_Broadcast_Channel; $img.attr('src', arrowUpImage); } }); - jQuery(document).on('click', '.qsm-settings-box-result-button', function () { + jQuery(document).on('click', '.qsm-settings-box-result-button, .qsm-settings-box-email-button', function () { jQuery('.qsm-settings-box-details').not(jQuery(this).parents('.qsm-template-btn-group').find('.qsm-settings-box-details')).hide(); jQuery(this).parents('.qsm-template-btn-group').find('.qsm-settings-box-details').toggle(); }); @@ -4615,6 +4689,7 @@ var QSM_Quiz_Broadcast_Channel; // Check if the click was outside .qsm-template-btn-group if (!jQuery(e.target).closest('.qsm-template-btn-group').length) { jQuery('.qsm-settings-box-details').hide(); + jQuery('.qsm-insert-template-wrap').hide(); } if (!$(event.target).closest('.email-show').length) { let autocomplete = jQuery(document).find('.qsm-autocomplete'); diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index 0acc543a1..db5e1fe7a 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -586,6 +586,12 @@ public function qsm_admin_scripts_style( $hook ) { 'qsmQuizzesObject' => $qsm_quizzes, 'arrow_up_image' => esc_url(QSM_PLUGIN_URL . 'assets/arrow-up-s-line.svg'), 'arrow_down_image' => esc_url(QSM_PLUGIN_URL . 'assets/arrow-down-s-line.svg'), + 'add_process' => __('Adding...', 'quiz-master-next'), + 'empty_template_name' => __('Template name cannot be empty.', 'quiz-master-next'), + 'empty_template_content' => __('Template content cannot be empty.', 'quiz-master-next'), + 'template_added' => __('Template added successfully!', 'quiz-master-next'), + 'template_save_error' => __('There was an error when saving the template.', 'quiz-master-next'), + 'confirmDeleteText' => esc_html__( 'Are you sure you want to delete this template?', 'quiz-master-next' ), ); $qsm_admin_messages = apply_filters( 'qsm_admin_messages_after', $qsm_admin_messages ); wp_localize_script( 'qsm_admin_js', 'qsm_admin_messages', $qsm_admin_messages ); diff --git a/php/admin/functions.php b/php/admin/functions.php index 97113d3c8..d9699e678 100644 --- a/php/admin/functions.php +++ b/php/admin/functions.php @@ -1744,41 +1744,172 @@ function qsm_extra_shortcode_popup_window_button( $quiz_id, $categories ) { function qsm_insert_quiz_template_callback() { global $wpdb; - // Check if all necessary data is present - if ( ! isset($_POST['unique_id']) || ! isset($_POST['template_name']) || ! isset($_POST['template_type']) || ! isset($_POST['template_content']) || ! isset($_POST['is_free']) ) { - wp_send_json_error(array( 'message' => 'Missing required data.' )); - } - + // Sanitize the incoming data - $unique_id = sanitize_text_field($_POST['unique_id']); - $template_name = sanitize_text_field($_POST['template_name']); - $template_type = sanitize_text_field($_POST['template_type']); - $template_content = sanitize_textarea_field($_POST['template_content']); - $is_free = sanitize_text_field($_POST['is_free']); - + $template_name = isset($_POST['template_name']) ? sanitize_text_field(wp_unslash( $_POST['template_name'] )) : ""; + $template_type = isset($_POST['template_type']) ? sanitize_text_field(wp_unslash( $_POST['template_type'] )) : ""; + $template_content = wp_unslash( $_POST['template_content'] ); + $filtered_content = preg_replace_callback( + '/([^<]+)<\/qsmvariabletag>/u', + function( $matches ) { + return '%' . wp_strip_all_tags( preg_replace('/^\s+|\s+$/u', '', $matches[1] ) ) . '%'; + }, + $template_content + ); + $filtered_content = preg_replace_callback( + '/([^<]+)<\/qsmextrashortcodetag>/u', + function( $matches ) { + return wp_strip_all_tags( preg_replace('/^\s+|\s+$/u', '', $matches[1] ) ); + }, + $filtered_content + ); + $table_name = $wpdb->prefix . 'mlw_quiz_output_templates'; - + $template_data = array( + 'template_name' => $template_name, + 'template_type' => $template_type, + 'template_content' => $filtered_content, + 'created_at' => current_time('mysql'), + ); // Insert the template into the database $wpdb->insert( $table_name, - array( - 'unique_id' => $unique_id, - 'template_name' => $template_name, - 'template_type' => $template_type, // Default type can be set as 'result' - 'template_content' => $template_content, - 'is_free' => $is_free, - 'created_at' => current_time('mysql'), - ), - array( '%s', '%s', '%s', '%s', '%s', '%s' ) // Format of the inserted data + $template_data, + array( '%s', '%s', '%s', '%s' ) // Format of the inserted data ); // Get the inserted record's ID and other details - $inserted_id = $wpdb->insert_id; - + $template_data['id'] = $wpdb->insert_id; // Prepare the response with the inserted data - wp_send_json_success(array( - 'id' => $inserted_id, - 'template_name' => $template_name, - 'preview_url' => QSM_PLUGIN_URL . 'assets/eye-line-blue.png', // You can change this to a real preview image - )); + wp_send_json_success($template_data); +} + +add_action( 'wp_ajax_qsm_remove_my_templates', 'qsm_remove_my_templates_handler' ); + +function qsm_remove_my_templates_handler() { + global $wpdb; + if ( ! isset( $_POST['nonce'] ) || + ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'qsm_remove_template' ) + ) { + wp_send_json_error( [ 'message' => __( 'Invalid nonce. Action not authorized.', 'quiz-master-next' ) ] ); + wp_die(); + } + + if ( ! isset( $_POST['id'] ) || ! absint( wp_unslash( $_POST['id'] ) ) ) { + wp_send_json_error( [ 'message' => __( 'Invalid template ID.', 'quiz-master-next' ) ] ); + wp_die(); + } + + $template_id = absint( wp_unslash( $_POST['id'] ) ); + $table_name = $wpdb->prefix . 'mlw_quiz_output_templates'; + $result = $wpdb->delete( $table_name, [ 'id' => $template_id ], [ '%d' ] ); + if ( $result ) { + wp_send_json_success( [ 'message' => __( 'Template removed successfully.', 'quiz-master-next' ) ] ); + } else { + wp_send_json_error( [ 'message' => __( 'Failed to remove the template.', 'quiz-master-next' ) ] ); + } + wp_die(); } + + +function qsm_result_and_email_popups_for_templates( $template_from_script, $my_templates, $type ) { + ?> + + + + + + false ] ); + $template_from_script = json_decode( wp_remote_retrieve_body( $template_from_script ), true ); $quiz_id = isset( $_GET['quiz_id'] ) ? intval( $_GET['quiz_id'] ) : 0; $user_id = get_current_user_id(); - $table_name = $wpdb->prefix . 'mlw_quiz_output_templates'; - $temlate_sql = "SELECT unique_id, template_content FROM {$table_name}"; - $mlw_quiz_output_templates_results = $wpdb->get_results($temlate_sql); - $unique_ids = array_column($mlw_quiz_output_templates_results, 'unique_id'); - $template_contents = array_column($mlw_quiz_output_templates_results, 'template_content'); - // Combine into an associative array where unique_id is the key - $my_tmpl_data = array_combine($unique_ids, $template_contents); - - // Use array_column to extract the unique_id column - $existing_unique_ids = array_column($mlw_quiz_output_templates_results, 'unique_id'); - $qsm_quiz_output_templates_results = [ - (object) [ - 'id' => 1, - 'unique_id' => 'UID101', - 'template_name' => 'Template 1', - 'template_type' => 'email', - 'template_content' => 'Your score: %POINT_SCORE% out of %MAXIMUM_POINTS%. You scored %AMOUNT_CORRECT% correct answers out of %TOTAL_QUESTIONS%.', - 'is_free' => true, - ], - (object) [ - 'id' => 2, - 'unique_id' => 'UID102', - 'template_name' => 'Template 2', - 'template_type' => 'email', - 'template_content' => 'Congratulations %USER_NAME%! You answered %AMOUNT_CORRECT% out of %TOTAL_QUESTIONS% correctly. Your result: %POINT_SCORE%. - [qsm_conditions type="points" condition="equal" value="10"]You scored exactly 10 points! Well done![/qsm_conditions] - [qsm_conditions type="points" condition="greater" value="20"]Excellent! You scored more than 20 points![/qsm_conditions]', - 'is_free' => false, - ], - (object) [ - 'id' => 3, - 'unique_id' => 'UID103', - 'template_name' => 'Template 3', - 'template_type' => 'email', - 'template_content' => 'Great job, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% correct answers out of %TOTAL_QUESTIONS%.', - 'is_free' => true, - ], - (object) [ - 'id' => 4, - 'unique_id' => 'UID104', - 'template_name' => 'Template 4', - 'template_type' => 'email', - 'template_content' => 'Quiz complete! %USER_NAME%, your score is %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% correct answers! - [qsm_conditions type="points" condition="lessthan" value="5"]Oops! You scored less than 5 points. Better luck next time![/qsm_conditions]', - 'is_free' => false, - ], - (object) [ - 'id' => 5, - 'unique_id' => 'UID105', - 'template_name' => 'Template 5', - 'template_type' => 'email', - 'template_content' => 'Your quiz result: %POINT_SCORE% out of %MAXIMUM_POINTS%. Correct answers: %AMOUNT_CORRECT%.', - 'is_free' => true, - ], - (object) [ - 'id' => 6, - 'unique_id' => 'UID106', - 'template_name' => 'Template 6', - 'template_type' => 'email', - 'template_content' => 'Well done, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. Correct answers: %AMOUNT_CORRECT%.', - 'is_free' => false, - ], - (object) [ - 'id' => 7, - 'unique_id' => 'UID107', - 'template_name' => 'Template 7', - 'template_type' => 'email', - 'template_content' => 'Awesome, %USER_NAME%! You scored %POINT_SCORE%/%MAXIMUM_POINTS%. %AMOUNT_CORRECT% answers correct out of %TOTAL_QUESTIONS%. - [qsm_conditions type="points" condition="greater" value="15"]Excellent! You scored over 15 points![/qsm_conditions]', - 'is_free' => true, - ], - ]; + $temlpate_sql = "SELECT * FROM {$table_name} WHERE template_type='email'"; + $my_email_templates = $wpdb->get_results($temlpate_sql); - $new_templates_uid = array_column($qsm_quiz_output_templates_results, 'unique_id'); - $new_template_contents = array_column($qsm_quiz_output_templates_results, 'template_content'); - // Combine into an associative array where unique_id is the key - $new_tmpl_data = array_combine($new_templates_uid, $new_template_contents); - - // Filter the incoming data to only include templates that have not been inserted - $new_templates = array_filter($qsm_quiz_output_templates_results, function( $template ) use ( $existing_unique_ids ) { - return ! in_array($template->unique_id, $existing_unique_ids); - }); - $js_data = array( - 'quizID' => $quiz_id, - 'nonce' => wp_create_nonce( 'wp_rest' ), - 'qsm_user_ve' => get_user_meta( $user_id, 'rich_editing', true ), - 'rest_user_nonce' => wp_create_nonce( 'wp_rest_nonce_' . $quiz_id . '_' . $user_id ), - 'my_tmpl_data' => $my_tmpl_data, - 'new_tmpl_data' => $new_tmpl_data, + 'quizID' => $quiz_id, + 'nonce' => wp_create_nonce( 'wp_rest' ), + 'qsm_user_ve' => get_user_meta( $user_id, 'rich_editing', true ), + 'rest_user_nonce' => wp_create_nonce( 'wp_rest_nonce_' . $quiz_id . '_' . $user_id ), + 'my_tmpl_data' => $my_email_templates, + 'script_tmpl' => $template_from_script, + 'add_tmpl_nonce' => wp_create_nonce( 'qsm_add_template' ), + 'remove_tmpl_nonce' => wp_create_nonce( 'qsm_remove_template' ), ); wp_localize_script( 'qsm_admin_js', 'qsmEmailsObject', $js_data ); do_action( 'qsm_options_email_tab_content_before' ); @@ -243,105 +168,8 @@ function qsm_options_emails_tab_content() { - - - - - {{data.id}}
@@ -395,14 +243,14 @@ function qsm_options_emails_tab_template() {
+
-