Skip to content

Commit

Permalink
Merge pull request #2531 from QuizandSurveyMaster/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
zubairraeen authored Apr 25, 2024
2 parents 9325872 + f60fb9e commit 3ef2981
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 45 deletions.
36 changes: 18 additions & 18 deletions blocks/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,25 @@ private function qsm_block_register_legacy() {
* Get hierarchical qsm_category
*/
private function hierarchical_qsm_category( $cat = 0 ) {
$category = [];
$next = get_categories( array(
'taxonomy' => 'qsm_category',
'hide_empty' => false,
'hierarchical' => true,
'orderby' => 'name',
'order' => 'ASC',
'parent' => $cat,
) );

if ( $next ) {
foreach ( $next as $cat ) {
$cat->name = $cat->cat_name;
$cat->id = $cat->term_id;
$cat->children = $this->hierarchical_qsm_category( $cat->term_id );
$category[] = $cat;
$category = [];
$next = get_categories( array(
'taxonomy' => 'qsm_category',
'hide_empty' => false,
'hierarchical' => true,
'orderby' => 'name',
'order' => 'ASC',
'parent' => $cat,
) );

if ( $next ) {
foreach ( $next as $cat ) {
$cat->name = $cat->cat_name;
$cat->id = $cat->term_id;
$cat->children = $this->hierarchical_qsm_category( $cat->term_id );
$category[] = $cat;
}
}
}
return $category;
return $category;
}

/**
Expand Down
11 changes: 4 additions & 7 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2537,9 +2537,9 @@ var import_button;
}
if (qsmQuestionSettings.form_type == 0) {
if (questionType == 14) {
$('.correct-answer').hide();
$('.answer-correct-div').hide();
} else {
$('.correct-answer').show();
$('.answer-correct-div').show();
}
}

Expand Down Expand Up @@ -3314,9 +3314,6 @@ var import_button;
if (pageKey.replace(/^\s+|\s+$/g, "").length == 0) {
alert(qsm_admin_messages.page_name_required);
return false;
} else if (null == pageKey.match(/^[ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñA-Za-z0-9\-\s]+$/)) {
alert(qsm_admin_messages.page_name_validation);
return false;
} else {
QSMQuestion.updateQPage(pageID);
QSMQuestion.savePages();
Expand Down Expand Up @@ -3409,9 +3406,9 @@ var import_button;
}
}
if (14 == question_val) {
$('.correct-answer').hide();
$('.answer-correct-div').hide();
} else {
$('.correct-answer').show();
$('.answer-correct-div').show();
}
if (15 == question_val || 16 == question_val || 17 == question_val) {
MicroModal.show('modal-advanced-question-type');
Expand Down
5 changes: 3 additions & 2 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1781,15 +1781,16 @@ function qsm_show_inline_result(quizID, question_id, value, $this, answer_type,
if ( 0 < value.length && data.success == 'correct') {
$this.append('<div style="color: green" class="quick-question-res-p qsm-correct-answer-info">' + qmn_quiz_data[quizID].quick_result_correct_answer_text + '</div>')
$this.append('<div class="qsm-inline-correct-info">' + qsm_check_shortcode(data.message) + '</div>');
} else if ( 0 < value.length && data.success == 'incorrect') {
$this.find('.qmn_radio_answers').children().eq(parseInt(data.correct_index)).addClass('data-correct-answer');
} else if (0 < value.length && data.success == 'incorrect') {
$this.find('.qmn_radio_answers input[value="' + data.correct_index + '"]').parent().addClass('data-correct-answer');
$this.append('<div style="color: red" class="quick-question-res-p qsm-incorrect-answer-info">' + qmn_quiz_data[quizID].quick_result_wrong_answer_text + '</div>')
$this.append('<div class="qsm-inline-correct-info">' + qsm_check_shortcode(data.message) + '</div>');
}
if (1 != qmn_quiz_data[quizID].disable_mathjax) {
MathJax.typesetPromise();
}
jQuery('.qsm-spinner-loader').remove();
jQuery(document).trigger('qsm_show_inline_result_after', [quizID, question_id, value, $this, answer_type, $i_this, index]);
}
function addSpinnerLoader($this,$i_this) {
if ($this.find('.mlw_answer_open_text').length) {
Expand Down
7 changes: 4 additions & 3 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Quiz And Survey Master
* Description: Easily and quickly add quizzes and surveys to your website.
* Version: 9.0.0
* Version: 9.0.1
* Author: ExpressTech
* Author URI: https://quizandsurveymaster.com/
* Plugin URI: https://expresstech.io/
Expand Down Expand Up @@ -43,7 +43,7 @@ class MLWQuizMasterNext {
* @var string
* @since 4.0.0
*/
public $version = '9.0.0';
public $version = '9.0.1';

/**
* QSM Alert Manager Object
Expand Down Expand Up @@ -191,7 +191,8 @@ private function load_dependencies() {
include_once 'php/classes/class-qsm-audit.php';
$this->audit_manager = new QSM_Audit();

if ( is_admin() || $this->qsm_is_admin() ) {
// In block editor api call is_admin return false so use qsm_is_admin.
if ( is_admin() || ( ! empty( $_POST['qsm_block_api_call'] ) && $this->qsm_is_admin() ) ) {
include_once 'php/admin/functions.php';
include_once 'php/admin/stats-page.php';
include_once 'php/admin/quizzes-page.php';
Expand Down
34 changes: 33 additions & 1 deletion php/admin/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,38 @@ function qsm_add_author_column_in_db() {
}
}
}

/**
* Add new column in the results table
*
* @since 9.0.1
*/
if ( get_option( 'qsm_update_db_column_charset_utf8mb4_unicode_ci', '' ) != 1 ) {
global $wpdb;

$tables_to_convert = array(
"{$wpdb->prefix}mlw_qm_audit_trail",
"{$wpdb->prefix}mlw_questions",
"{$wpdb->prefix}mlw_quizzes",
"{$wpdb->prefix}mlw_results",
);

$success = true;

foreach ( $tables_to_convert as $table ) {
$query = "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;";
$result = $wpdb->query($query);

if ( ! $result ) {
$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 );
}
}
}

add_action( 'admin_init', 'qsm_change_the_post_type' );
Expand Down Expand Up @@ -1576,7 +1608,7 @@ function qsm_get_input_label_selected( $param ) {
'<option value="%1$s" %2$s >%3$s</option>',
esc_attr( $key ),
esc_attr( $is_selected ),
esc_attr( $val ),
esc_attr( $val )
);
}
$allowed_tags = array(
Expand Down
8 changes: 4 additions & 4 deletions php/classes/class-qsm-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -1951,10 +1951,10 @@ public function update() {
}

// Update 2.6.1
$results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_qm_audit_trail CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;' );
$results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_questions CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci' );
$results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci' );
$results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci' );
$results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_qm_audit_trail CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' );
$results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_questions CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' );
$results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_quizzes CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' );
$results = $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'mlw_results CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci' );

global $wpdb;
$table_name = $wpdb->prefix . 'mlw_results';
Expand Down
6 changes: 3 additions & 3 deletions php/question-types/qsm-question-type-text-or-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
function qmn_text_block_display( $id, $question, $answers ) {
global $mlwQuizMasterNext;
$question = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( $question, ENT_QUOTES ), "question-description-{$id}", "QSM Questions" );
$question = apply_filters( 'qmn_text_block_display_front', $question, $id, $answers);
echo do_shortcode( wp_kses_post( $question ) );
$new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' );
qsm_question_title_func( $question, '', $new_question_title, $id );
echo apply_filters( 'qmn_text_block_display_front', '', $id, $question, $answers );
}
17 changes: 11 additions & 6 deletions php/template-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function qsm_variable_single_question_answer( $content, $mlw_quiz_array ) {

function qsm_variable_single_answer( $content, $mlw_quiz_array ) {
global $mlwQuizMasterNext,$wpdb;
$quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
$quiz_id = is_object( $mlw_quiz_array ) ? $mlw_quiz_array->quiz_id : $mlw_quiz_array['quiz_id'];
while ( false !== strpos( $content, '%ANSWER_' ) ) {
$question_id = mlw_qmn_get_string_between( $content, '%ANSWER_', '%' );
Expand All @@ -136,14 +137,18 @@ function qsm_variable_single_answer( $content, $mlw_quiz_array ) {
if ( isset($answers['user_answer']) ) {
if ( 13 === intval( $answers['question_type'] ) ) {
$answerstr .= $answers['points'];
}elseif ( 12 === intval( $answers['question_type'] ) ) {
$preferred_date_format = isset($quiz_options->preferred_date_format) ? $quiz_options->preferred_date_format : get_option('date_format');
foreach ( $answers['user_answer'] as $answer ) {
$answerstr = ! empty( $answer ) && strtotime( $answer ) ? date_i18n( $preferred_date_format, strtotime( $answer ) ) : $answer;
}
}elseif ( 'rich' === $question_settings['answerEditor'] ) {
foreach ( $answers['user_answer'] as $answer ) {
$answerstr .= htmlspecialchars_decode($answer);
$answerstr .= htmlspecialchars_decode($answer);
}
}
elseif ( 'image' === $question_settings['answerEditor'] ) {
}elseif ( 'image' === $question_settings['answerEditor'] ) {
foreach ( $answers['user_answer'] as $answer ) {
$answerstr .= '<span class="qmn_image_option" ><img src="' . htmlspecialchars_decode($answer, ENT_QUOTES ) . '"/></span>';
$answerstr .= '<span class="qmn_image_option" ><img src="' . htmlspecialchars_decode($answer, ENT_QUOTES ) . '"/></span>';
}
}else {
$answerstr .= implode(", ",$answers['user_answer']);
Expand Down Expand Up @@ -1084,7 +1089,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
if ( isset( $answer['question_type'] ) && in_array( intval( $answer['question_type'] ), $question_with_text_input, true ) ) {
$do_show_wrong = true;
$user_given_answer = '' === $answer[1] ? $quiz_options->no_answer_text : htmlentities( $answer[1] );
if ( 12 == $answer['question_type'] ) {
if ( 12 == $answer['question_type'] && ! empty( $answer[1] ) && strtotime( $user_given_answer ) ) {
$preferred_date_format = isset($quiz_options->preferred_date_format) ? $quiz_options->preferred_date_format : get_option('date_format');
$user_given_answer = date_i18n($preferred_date_format, strtotime($user_given_answer));
}
Expand Down Expand Up @@ -1268,7 +1273,7 @@ function qsm_questions_answers_shortcode_to_text( $mlw_quiz_array, $qmn_question
} else {
$question_with_answer_text .= "$open_span_tag" . trim( htmlspecialchars_decode( $answer[1], ENT_QUOTES ) ) . '</span>';
}
} elseif ( isset( $answer['question_type'] ) && 12 == $answer['question_type'] ) {
} elseif ( isset( $answer['question_type'] ) && 12 == $answer['question_type'] && ! empty( $answer[1] ) && strtotime( $answer[1] ) ) {
$preferred_date_format = isset($quiz_options->preferred_date_format) ? $quiz_options->preferred_date_format : get_option('date_format');
$user_given_answer = date_i18n($preferred_date_format, strtotime($answer[1]));
$question_with_answer_text .= '<span class="qsm-user-answer-text">' . $user_given_answer . '</span>';
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: quiz, survey, lead, test, score, exam, questionnaire, question,wordpress q
Requires at least: 4.9
Tested up to: 6.5
Requires PHP: 5.4
Stable tag: 9.0.0
Stable tag: 9.0.1
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -163,6 +163,13 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
18. Database

== Changelog ==
= 9.0.1 (April 25, 2024) =
* Bug: Fixed date format in %ANSWER_X% variable
* Bug: Resolved PHP warning in Quiz Block editor
* Bug: Fixed an issue in showing the correct answers in a quiz while using random answers
* Enhancement: Improved text feature to accept other language characters in quiz page names
* Enhancement: Added support for using emojis in quiz questions, result pages, and email templates

= 9.0.0 (March 27, 2024) =
* Feature: Implemented a minimum length requirement for text-based question types
* Feature: Introduced a placeholder option for contact fields
Expand Down

0 comments on commit 3ef2981

Please sign in to comment.