From a7f3569c4cc02c43b89a8c70565e2914381cb5b5 Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Fri, 13 Dec 2024 18:11:07 +0530 Subject: [PATCH 1/3] Release QSM 9.2.3 --- js/qsm-admin.js | 12 ++++++------ js/qsm-quiz.js | 23 ++++++++++++++++------- mlw_quizmaster2.php | 10 ++-------- php/admin/options-page-text-tab.php | 2 +- php/classes/class-qsm-install.php | 6 ------ php/classes/class-qsm-settings.php | 10 +++++----- php/template-variables.php | 13 ++++++++++++- readme.txt | 9 ++++++++- 8 files changed, 50 insertions(+), 35 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 277e3378..b7b22636 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -2498,13 +2498,13 @@ var import_button; } var category = []; var multicategories = model.get('multicategories'); - if (multicategories === null || typeof multicategories === "undefined") { - //No Action Require - } else { - $.each(multicategories, function (i, val) { - category.push($(".qsm-popup__content #qsm_category-" + val + " label:first-child")[0].textContent); + if (multicategories) { + multicategories.forEach(val => { + const categoryLabel = $(".qsm-popup__content #in-qsm_category-" + val + "-1 > label").text(); + if (categoryLabel) { + category.push(categoryLabel); + } }); - category = category.filter(item => item); } $('.question[data-question-id=' + model.id + ']').replaceWith(template({ id: model.id, diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index 735aa509..3d7c05f9 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -52,6 +52,8 @@ var qsmTimerInterval = []; if (quiz.hasOwnProperty('timer_limit') && 0 != quiz.timer_limit) { QSM.initTimer(quizID); quizType = 'timer'; + } else if (jQuery('.qsm-quiz-container-' + quizID + ' #timer').val() == 0) { + qsmTimerInterval[quizID] = setInterval(function () { qmnTimeTakenTimer(quizID) }, 1000); } if (jQuery('.qsm-quiz-container-' + quizID + ' .qsm-submit-btn').is(':visible') && !jQuery('.qsm-quiz-container-' + quizID).hasClass('qsm_auto_pagination_enabled') ) { jQuery('.qsm-quiz-container-' + quizID + ' .qsm-quiz-comment-section').fadeIn(); @@ -1868,13 +1870,20 @@ jQuery(document).ready(function () { var rnum = Math.floor(Math.random() * mlw_chars.length); mlw_code += mlw_chars.substring(rnum, rnum + 1); } - var mlw_captchaCTX = document.getElementById('mlw_captcha').getContext('2d'); - mlw_captchaCTX.font = 'normal 24px Verdana'; - mlw_captchaCTX.strokeStyle = '#000000'; - mlw_captchaCTX.clearRect(0, 0, 100, 50); - mlw_captchaCTX.strokeText(mlw_code, 10, 30, 70); - mlw_captchaCTX.textBaseline = 'middle'; - document.getElementById('mlw_code_captcha').value = mlw_code; + var captchaCanvas = document.getElementById('mlw_captcha'); + var mlw_captchaCTX = captchaCanvas.getContext('2d'); + var containerDirection = window.getComputedStyle(captchaCanvas).direction || 'ltr'; + mlw_captchaCTX.font = 'normal 24px Verdana'; + mlw_captchaCTX.strokeStyle = '#000000'; + mlw_captchaCTX.clearRect(0, 0, captchaCanvas.width, captchaCanvas.height); + if (containerDirection === 'rtl') { + mlw_captchaCTX.textAlign = 'right'; + mlw_captchaCTX.strokeText(mlw_code, captchaCanvas.width - 10, captchaCanvas.height / 2); + } else { + mlw_captchaCTX.textAlign = 'left'; + mlw_captchaCTX.strokeText(mlw_code, 10, captchaCanvas.height / 2); + } + document.getElementById('mlw_code_captcha').value = mlw_code; } }); diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index 57364677..96d1e4ff 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -2,7 +2,7 @@ /** * Plugin Name: Quiz And Survey Master * Description: Easily and quickly add quizzes and surveys to your website. - * Version: 9.2.2 + * Version: 9.2.3 * Author: ExpressTech * Author URI: https://quizandsurveymaster.com/ * Plugin URI: https://expresstech.io/ @@ -43,7 +43,7 @@ class MLWQuizMasterNext { * @var string * @since 4.0.0 */ - public $version = '9.2.2'; + public $version = '9.2.3'; /** * QSM Alert Manager Object @@ -765,12 +765,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/options-page-text-tab.php b/php/admin/options-page-text-tab.php index 0404ce1c..f1cba582 100644 --- a/php/admin/options-page-text-tab.php +++ b/php/admin/options-page-text-tab.php @@ -221,7 +221,7 @@ function qsm_get_question_text_message() { exit; } else { $settings = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_text', $text_id ); - $settings = ! empty( $settings ) ? $settings : ''; + $settings = ! empty( $settings ) ? $settings : ''; $quiz_text_arr = $mlwQuizMasterNext->quiz_settings->load_setting_fields( 'quiz_text' ); $key = array_search( $text_id, array_column( $quiz_text_arr, 'id' ), true ); $allowed_text = ''; diff --git a/php/classes/class-qsm-install.php b/php/classes/class-qsm-install.php index 134d91bc..0a356108 100644 --- a/php/classes/class-qsm-install.php +++ b/php/classes/class-qsm-install.php @@ -1966,12 +1966,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'; diff --git a/php/classes/class-qsm-settings.php b/php/classes/class-qsm-settings.php index 916afe61..e6f70c82 100644 --- a/php/classes/class-qsm-settings.php +++ b/php/classes/class-qsm-settings.php @@ -464,17 +464,17 @@ public function get_quiz_options() { $quiz_options = array_merge( $quiz_options, $leaderboards ); } + $text = $this->get_setting('quiz_text'); + if ( is_array($text) ) { + $quiz_options = array_merge( $quiz_options, $text ); + } + $options = $this->get_setting( 'quiz_options' ); if ( is_array( $options ) ) { unset( $options['quiz_name'] ); $quiz_options = array_merge( $quiz_options, $options ); } - $text = $this->get_setting('quiz_text'); - if ( is_array($text) ) { - $quiz_options = array_merge( $quiz_options, $text ); - } - // Return as old object model return (object) $quiz_options; } diff --git a/php/template-variables.php b/php/template-variables.php index a67d9baa..55a18f31 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -496,7 +496,18 @@ function mlw_qmn_variable_user_email( $content, $mlw_quiz_array ) { function qsm_contact_field_variable( $content, $results_array ) { preg_match_all( '~%CONTACT_(.*?)%~i', $content, $matches ); for ( $i = 0; $i < count( $matches[0] ); $i++ ) { - $content = str_replace( '%CONTACT_' . $matches[1][ $i ] . '%', $results_array['contact'][ $matches[1][ $i ] - 1 ]['value'], $content ); + $contact_key = $matches[1][ $i ]; + if ( is_numeric( $contact_key ) && intval( $contact_key ) > 0 ) { + $contact_index = intval( $contact_key ) - 1; + + if ( isset( $results_array['contact'][ $contact_index ]['value'] ) ) { + $content = str_replace( '%CONTACT_' . $contact_key . '%', $results_array['contact'][ $contact_index ]['value'], $content ); + } else { + $content = str_replace( '%CONTACT_' . $contact_key . '%', '', $content ); + } + } else { + $content = str_replace( '%CONTACT_' . $contact_key . '%', '', $content ); + } } return $content; } diff --git a/readme.txt b/readme.txt index b5cc6168..82269dc9 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: quiz, survey, test, exam, online assessment Requires at least: 4.9 Tested up to: 6.7 Requires PHP: 5.4 -Stable tag: 9.2.2 +Stable tag: 9.2.3 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -222,6 +222,13 @@ As a WordPress quiz maker, QSM is designed to be compatible with most other plug 18. Database == Changelog == += 9.2.3 ( December 13, 2024 ) = +* Bug: Resolved issue where contact form not showing at quiz end +* Bug: Resolved quiz timer issue for single-page quizzes +* Bug: Fixed PHP warning related to the CONTACT_X variable +* Enhancement: Enhanced the Captcha question type canvas for RTL websites +* Enhancement: Refined user role permissions for improved access control + = 9.2.2 ( November 06, 2024 ) = * Bug: Fixed issue with text displaying before quiz options * Bug: Resolved issue with left/right arrow keys in the quiz input box From dd191e921c49e1f4e033ac685834bc820662c2d2 Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Fri, 13 Dec 2024 18:18:32 +0530 Subject: [PATCH 2/3] fixed sonar issue --- js/qsm-admin.js | 3 --- js/qsm-quiz.js | 14 +++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index b7b22636..264c1e75 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -2249,7 +2249,6 @@ var import_button; import_button.attr("onclick", "return confirm('" + qsm_admin_messages.confirm_message + " " + qsm_admin_messages.import_question_again + "');"); } QSMQuestion.openEditPopup(model.id, $('.question[data-question-id=' + model.id + ']').find('.edit-question-button')); - // $('#save-popup-button').trigger('click'); }, addNewQuestion: function (model) { var default_answers = parseInt(qsmQuestionSettings.default_answers); @@ -2770,7 +2769,6 @@ var import_button; } CurrentElement.parents('.question').next('.questionElements').slideDown('slow'); $('#modal-1-content').html(questionElements); - //MicroModal.show( 'modal-1' ); $('.questions').sortable('disable'); $('.page').sortable('disable'); @@ -3786,7 +3784,6 @@ var import_button; .fail(QSMAdmin.displayjQueryError); }, loadResults: function () { - //QSMAdmin.displayAlert( 'Loading results pages...', 'info' ); $.ajax({ url: wpApiSettings.root + 'quiz-survey-master/v1/quizzes/' + qsmResultsObject.quizID + '/results', headers: { 'X-WP-Nonce': qsmResultsObject.nonce }, diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index 3d7c05f9..cb8ba0f2 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1864,15 +1864,15 @@ jQuery(document).ready(function () { let captchaElement = jQuery('#mlw_code_captcha'); if (captchaElement.length !== 0) { mlw_code = ''; - var mlw_chars = '0123456789ABCDEFGHIJKL!@#$%^&*()MNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'; - var mlw_code_length = 5; - for (var i = 0; i < mlw_code_length; i++) { - var rnum = Math.floor(Math.random() * mlw_chars.length); + let mlw_chars = '0123456789ABCDEFGHIJKL!@#$%^&*()MNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'; + let mlw_code_length = 5; + for (let i = 0; i < mlw_code_length; i++) { + let rnum = Math.floor(Math.random() * mlw_chars.length); mlw_code += mlw_chars.substring(rnum, rnum + 1); } - var captchaCanvas = document.getElementById('mlw_captcha'); - var mlw_captchaCTX = captchaCanvas.getContext('2d'); - var containerDirection = window.getComputedStyle(captchaCanvas).direction || 'ltr'; + let captchaCanvas = document.getElementById('mlw_captcha'); + let mlw_captchaCTX = captchaCanvas.getContext('2d'); + let containerDirection = window.getComputedStyle(captchaCanvas).direction || 'ltr'; mlw_captchaCTX.font = 'normal 24px Verdana'; mlw_captchaCTX.strokeStyle = '#000000'; mlw_captchaCTX.clearRect(0, 0, captchaCanvas.width, captchaCanvas.height); From 37fa789eb452f79ad6866b83f54973d622e4dea1 Mon Sep 17 00:00:00 2001 From: etchirag Date: Mon, 16 Dec 2024 12:14:23 +0530 Subject: [PATCH 3/3] Fixed issue with total question variable --- php/template-variables.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/php/template-variables.php b/php/template-variables.php index 55a18f31..5f4c4b74 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -386,13 +386,20 @@ function mlw_qmn_variable_amount_incorrect( $content, $mlw_quiz_array ) { function mlw_qmn_variable_total_questions( $content, $mlw_quiz_array ) { global $wp_current_filter; - if ( ! empty( $wp_current_filter[1] ) && 'mlw_qmn_template_variable_quiz_page' == $wp_current_filter[1] ) { + if ( is_array( $wp_current_filter ) && ! empty( $wp_current_filter ) && in_array( 'mlw_qmn_template_variable_quiz_page', $wp_current_filter, true ) ) { global $wpdb; $table_name = $wpdb->prefix . 'mlw_quizzes'; $quiz_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE quiz_id=%d", $mlw_quiz_array['quiz_id'] ) ); $quiz_settings = maybe_unserialize($quiz_data->quiz_settings); $quiz_questions = ! empty( $quiz_settings['pages'] ) ? maybe_unserialize( $quiz_settings['pages'] ) : array(); - $total_questions = isset( $quiz_questions[0] ) ? count( $quiz_questions[0] ) : 0; + $total_questions = 0; + if ( ! empty( $quiz_questions ) && isset( $quiz_questions[0] ) ) { + foreach ( $quiz_questions as $sub_questions ) { + if ( is_array( $sub_questions ) ) { + $total_questions += count( $sub_questions ); + } + } + } $content = str_replace( '%TOTAL_QUESTIONS%', $total_questions, $content ); return $content; }