Skip to content

Commit

Permalink
Merge branch 'dev' into CU-86cvbnjaj-accessibility-issue-code-change
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-pranav committed May 14, 2024
2 parents 9e498ff + dd61c23 commit 4d65b39
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 43 deletions.
1 change: 1 addition & 0 deletions js/qsm-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3714,6 +3714,7 @@ var import_button;
'value': $(this).find('.results-page-condition-value').val()
});
});
jQuery(document).trigger('qsm_save_result_page_before', [this, page]);
pages.push(page);
});
let _X_validation = false;
Expand Down
2 changes: 2 additions & 0 deletions js/qsm-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
jQuery('.question-section-id-'+questionID+' .question-type-polar-s').find(
'.right-polar-title img').css('opacity', "0.8");
}
jQuery(document).trigger('qsm_polar_slider_change_after', [ui,questionID, answer1, answer2, value , isReverse]);
}

function qsmPolarSliderQuestionCreate(questionID){
Expand All @@ -187,5 +188,6 @@
'.right-polar-title').css('font-weight', '400');
jQuery('.question-section-id-'+questionID+' .question-type-polar-s img').find(
'.right-polar-title img').css('opacity', "0.5");
jQuery(document).trigger('qsm_polar_slider_create_after', [questionID]);
}
}(jQuery));
8 changes: 5 additions & 3 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ var qsmTimerInterval = [];
jQuery(document).trigger('qsm_init_progressbar_after', [quizID, qmn_quiz_data]);
}
QSM.goToPage(quizID, 1);
jQuery(document).on('click', '.qsm-quiz-container-' + quizID + ' .qsm-pagination .qsm-next', function (event) {
jQuery(document).on('click', '.qsm-quiz-container-' + quizID + ' .qsm-next', function (event) {
jQuery(document).trigger('qsm_next_button_click_before', [quizID]);
event.preventDefault();
let $quizForm = QSM.getQuizForm(quizID);
Expand All @@ -365,7 +365,7 @@ var qsmTimerInterval = [];
}
jQuery(document).trigger('qsm_next_button_click_after', [quizID]);
});
jQuery(document).on('click', '.qsm-quiz-container-' + quizID + ' .qsm-pagination .qsm-previous', function (event) {
jQuery(document).on('click', '.qsm-quiz-container-' + quizID + ' .qsm-previous', function (event) {
jQuery(document).trigger('qsm_previous_button_click_before', [quizID]);
event.preventDefault();
QSM.prevPage(quizID);
Expand Down Expand Up @@ -1466,7 +1466,7 @@ jQuery(function () {
});
});

jQuery(document).on('change', '.qmn-multiple-choice-input, .qsm_dropdown' , function (e) {
jQuery(document).on('change', '.qmn-multiple-choice-input, .qsm_dropdown, .mlw_answer_date ' , function (e) {
let $i_this = jQuery(this);
var quizID = jQuery(this).parents('.qsm-quiz-container').find('.qmn_quiz_id').val();
var $quizForm = QSM.getQuizForm(quizID);
Expand Down Expand Up @@ -1607,6 +1607,8 @@ jQuery(function () {
$this.parent('.quiz_section').find('.qsm-file-upload-status').text('').text(obj.message);
$this.parent('.quiz_section').find('.qsm-file-upload-status').show();
}
// triggers after file remove
jQuery(document).trigger('qsm_after_file_remove', [$this.parent(), obj]);
}
});
return false;
Expand Down
2 changes: 2 additions & 0 deletions php/admin/options-page-results-page-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function qsm_options_results_tab_content() {
'rest_user_nonce' => wp_create_nonce( 'wp_rest_nonce_' . $quiz_id . '_' . $user_id ),
);
wp_localize_script( 'qsm_admin_js', 'qsmResultsObject', $js_data );
do_action( 'qsm_options_results_tab_content_before' );
?>

<!-- Results Page Section -->
Expand Down Expand Up @@ -218,6 +219,7 @@ function qsm_options_results_tab_template(){
<?php esc_html_e( 'Mark as default', 'quiz-master-next' ); ?>
</label>
<div class="qsm-actions-link-box">
<?php do_action( 'qsm_add_action_links_before' ); ?>
<a href="javascript:void(0)" class="qsm-delete-result-button"><span class="dashicons dashicons-trash"></span></a>
<a href="javascript:void(0)" class="qsm-duplicate-result-page-button"><span class="dashicons dashicons-admin-page"></span></a>
<a href="javascript:void(0)" class="qsm-toggle-result-page-button"><span class="dashicons dashicons-arrow-down-alt2"></span></a>
Expand Down
66 changes: 66 additions & 0 deletions php/classes/class-qmn-plugin-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,72 @@ public function __construct() {
add_filter( 'qsm_language_support', array( $this, 'qsm_language_support' ), 10, 3 );
}

/**
* Calls all class functions to check if quiz is setup properly
*
* @param int $quiz_id The ID of the quiz or survey to load.
* @return array An array which contains boolean result of has_proper_quiz, message and/or qmn_quiz_options
*/
public function has_proper_quiz( $quiz_id ) {
if ( empty( $quiz_id ) ) {
return array(
'res' => false,
'message' => __( 'Empty Quiz ID.', 'quiz-master-next' ),
);
}

$quiz_id = intval( $quiz_id );

// Tries to load quiz name to ensure this is a valid ID.
global $mlwQuizMasterNext, $qmn_allowed_visit, $qmn_json_data;
$qmn_json_data = array();
$qmn_allowed_visit = true;
if ( false === $this->prepare_quiz( $quiz_id ) ) {
return array(
'res' => false,
'message' => __( 'It appears that this quiz is not set up correctly.', 'quiz-master-next' ),
);
}

$has_result_id = ( ! isset( $_GET['result_id'] ) || '' === $_GET['result_id'] );

if ( $has_result_id ) {
global $mlw_qmn_quiz;
$mlw_qmn_quiz = $quiz_id;
}

$qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();

if ( $has_result_id ) {
/**
* Filter Quiz Options before Quiz Display
*/
$qmn_quiz_options = apply_filters( 'qsm_shortcode_quiz_options', $qmn_quiz_options );
}

// If quiz options isn't found, stop function.
if ( is_null( $qmn_quiz_options ) || ( ! empty( $qmn_quiz_options->deleted ) && 1 == $qmn_quiz_options->deleted ) ) {
return array(
'res' => false,
'message' => __( 'This quiz is no longer available.', 'quiz-master-next' ),
);
}

// If quiz options isn't found, stop function.
if ( is_null( $qmn_quiz_options ) || empty( $qmn_quiz_options->quiz_name ) ) {
return array(
'res' => false,
'message' => __( 'It appears that this quiz is not set up correctly.', 'quiz-master-next' ),
);
}

return array(
'res' => true,
'message' => __( 'Quiz is setup properly.', 'quiz-master-next' ),
'qmn_quiz_options' => $qmn_quiz_options,
);
}

/**
* Calls all class functions to initialize quiz
*
Expand Down
52 changes: 15 additions & 37 deletions php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,29 +331,33 @@ public function qsm_clear_audit_data() {
* @return string The content for the shortcode
*/
public function display_shortcode( $atts ) {
global $wpdb, $mlwQuizMasterNext;
$shortcode_args = shortcode_atts(
array(
'quiz' => 0,
'question_amount' => 0,
),
$atts
);

// Quiz ID.
$quiz = intval( $shortcode_args['quiz'] );
$question_amount = intval( $shortcode_args['question_amount'] );

// Check, if quiz is setup properly.
$has_proper_quiz = $mlwQuizMasterNext->pluginHelper->has_proper_quiz( $quiz );
if ( false === $has_proper_quiz['res'] ) {
return $has_proper_quiz['message'];
}

$qmn_quiz_options = $has_proper_quiz['qmn_quiz_options'];
$return_display = '';

ob_start();
global $wpdb, $mlwQuizMasterNext;
if ( isset( $_GET['result_id'] ) && '' !== $_GET['result_id'] ) {
$result_unique_id = sanitize_text_field( wp_unslash( $_GET['result_id'] ) );
$result = $wpdb->get_row( $wpdb->prepare( "SELECT `result_id`, `quiz_id` FROM {$wpdb->prefix}mlw_results WHERE unique_id = %s", $result_unique_id ), ARRAY_A );
if ( ! empty( $result ) && isset( $result['result_id'] ) ) {
$mlwQuizMasterNext->pluginHelper->prepare_quiz( $result['quiz_id'] );
$qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();

// If quiz options isn't found, stop function.
if ( is_null( $qmn_quiz_options ) || 1 == $qmn_quiz_options->deleted ) {
return __( 'This quiz is no longer available.', 'quiz-master-next' );
}

wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );
wp_style_add_data( 'qmn_quiz_common_style', 'rtl', 'replace' );
Expand All @@ -376,35 +380,8 @@ public function display_shortcode( $atts ) {
}
$return_display .= ob_get_clean();
} else {
global $qmn_allowed_visit;
global $qmn_json_data;
$qmn_json_data = array();
$qmn_allowed_visit = true;
$success = $mlwQuizMasterNext->pluginHelper->prepare_quiz( $quiz );
if ( false === $success ) {
return __( 'It appears that this quiz is not set up correctly', 'quiz-master-next' );
}

global $mlw_qmn_quiz;
$mlw_qmn_quiz = $quiz;
$return_display = '';
$qmn_quiz_options = $mlwQuizMasterNext->quiz_settings->get_quiz_options();
// Legacy variable.
/**
* Filter Quiz Options before Quiz Display
*/
$qmn_quiz_options = apply_filters( 'qsm_shortcode_quiz_options', $qmn_quiz_options );

// If quiz options isn't found, stop function.
if ( is_null( $qmn_quiz_options ) || 1 == $qmn_quiz_options->deleted ) {
return __( 'This quiz is no longer available.', 'quiz-master-next' );
}

// If quiz options isn't found, stop function.
if ( is_null( $qmn_quiz_options ) || empty( $qmn_quiz_options->quiz_name ) ) {
return __( 'It appears that this quiz is not set up correctly', 'quiz-master-next' );
}

global $qmn_allowed_visit, $qmn_json_data, $mlw_qmn_quiz;

// Loads Quiz Template.
wp_enqueue_style( 'qmn_quiz_animation_style', QSM_PLUGIN_CSS_URL . '/animate.css', array(), $mlwQuizMasterNext->version );
wp_enqueue_style( 'qmn_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );
Expand Down Expand Up @@ -1937,6 +1914,7 @@ public function submit_results( $qmn_quiz_options, $qmn_array_for_variables ) {

$result_display .= $this->display_social( $qmn_quiz_options, $qmn_array_for_variables );
$result_display = apply_filters( 'qmn_after_social_media', $result_display, $qmn_quiz_options, $qmn_array_for_variables );
$qmn_quiz_options = apply_filters( 'qmn_retake_quiz_button_before', $qmn_quiz_options );
if ( 1 == $qmn_quiz_options->enable_retake_quiz_button ) {
$result_display .= '<form method="POST">';
$result_display .= '<input type="hidden" value="' . $qmn_array_for_variables['quiz_id'] . '" name="qsm_retake_quiz_id" />';
Expand Down
1 change: 1 addition & 0 deletions php/classes/class-qsm-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public static function generate_section( $fields, $section ) {
<div id="quiz_submission" class="quiz_style_tab_content" style="display:none">
<table class="form-table" style="width: 100%;">
<?php
$settings = apply_filters( 'qsm_quiz_submission_section_before', $settings, $fields );
// Cycles through each field
foreach ( $fields as $field ) {
// Generate the field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ function qmn_horizontal_multiple_choice_display( $id, $question, $answers ) {
$mrq_checkbox_class = "mrq_checkbox_class";
}
$mlw_answer_total++;
$other_option_class = '';
$other_option_class = apply_filters( 'qsm_multiple_choice_other_option_classes', $other_option_class, $mlw_answer_total, $id, $answers );
if ( '' !== $answer[0] ) {
$answer_class = apply_filters( 'qsm_answer_wrapper_class', '', $answer, $id );
$answer_class .= 'image' === $answerEditor ? ' qmn_image_option' : '';
?>
<span class="mlw_horizontal_choice <?php echo esc_attr( $answer_class.' '.$mrq_checkbox_class ); ?>">
<input type="radio" class="qmn_quiz_radio qmn-multiple-choice-input" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer_index ); ?>" />
<input type="radio" class="qmn_quiz_radio qmn-multiple-choice-input <?php echo esc_attr( $other_option_class ); ?>" name="question<?php echo esc_attr( $id ); ?>" id="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer_index ); ?>" />
<label class="qsm-input-label" for="question<?php echo esc_attr( $id ) . '_' . esc_attr( $mlw_answer_total ); ?>">
<?php
if ( 'image' === $answerEditor ) {
Expand Down Expand Up @@ -110,6 +112,7 @@ function qmn_horizontal_multiple_choice_display( $id, $question, $answers ) {
*/
function qmn_horizontal_multiple_choice_review( $id, $question, $answers ) {
$current_question = new QSM_Question_Review_Choice( $id, $question, $answers );
$current_question = apply_filters( 'qmn_multiple_choice_review_before', $current_question, $id, $question, $answers );
$user_text_array = $current_question->get_user_answer( 'single_response' );
$correct_text_array = $current_question->get_correct_answer();
$return_array['user_text'] = ! empty( $user_text_array ) ? implode( ', ', $user_text_array ) : '';
Expand Down
6 changes: 5 additions & 1 deletion php/question-types/qsm-question-type-multiple-choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ function qmn_multiple_choice_display( $id, $question, $answers ) {
$mrq_checkbox_class = "mrq_checkbox_class";
}
$mlw_answer_total++;
$other_option_class = '';
$other_option_class = apply_filters( 'qsm_multiple_choice_other_option_classes', $other_option_class, $mlw_answer_total, $id, $answers );
if ( '' !== $answer[0] ) {
$answer_class = apply_filters( 'qsm_answer_wrapper_class', '', $answer, $id );
if ( 'rich' === $answerEditor ) {
Expand All @@ -59,7 +61,7 @@ function qmn_multiple_choice_display( $id, $question, $answers ) {
<?php
}
?>
<input type='radio' class='qmn_quiz_radio qmn-multiple-choice-input' name="<?php echo esc_attr( 'question' . $id ); ?>" id="<?php echo esc_attr( 'question' . $id . '_' . $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer_index ); ?>" />
<input type='radio' class='qmn_quiz_radio qmn-multiple-choice-input <?php echo esc_attr( $other_option_class ); ?>' name="<?php echo esc_attr( 'question' . $id ); ?>" id="<?php echo esc_attr( 'question' . $id . '_' . $mlw_answer_total ); ?>" value="<?php echo esc_attr( $answer_index ); ?>" />
<label class="qsm-input-label" for="<?php echo esc_attr( 'question' . $id . '_' . $mlw_answer_total ); ?>">
<?php
if ( 'image' === $answerEditor ) {
Expand Down Expand Up @@ -95,6 +97,7 @@ function qmn_multiple_choice_display( $id, $question, $answers ) {
}
//}
}
echo apply_filters( 'qsm_multiple_choice_display_after_loop', ' ', $id, $question, $answers );
?>
<label style="display: none;" for="<?php echo esc_attr( 'question' . $id . '_none' ); ?>"><?php echo esc_attr( 'question' . $id ); ?></label>
<input type="radio" style="display: none;" name="<?php echo esc_attr( 'question' . $id ); ?>" id="<?php echo esc_attr( 'question' . $id . '_none' ); ?>" checked="checked" value="" />
Expand All @@ -118,6 +121,7 @@ function qmn_multiple_choice_display( $id, $question, $answers ) {
*/
function qmn_multiple_choice_review( $id, $question, $answers ) {
$current_question = new QSM_Question_Review_Choice( $id, $question, $answers );
$current_question = apply_filters( 'qmn_multiple_choice_review_before', $current_question, $id, $question, $answers );
$user_text_array = $current_question->get_user_answer();
$correct_text_array = $current_question->get_correct_answer();
$return_array['user_answer'] = $user_text_array;
Expand Down
2 changes: 1 addition & 1 deletion php/template-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function mlw_qmn_variable_total_questions( $content, $mlw_quiz_array ) {
}

function mlw_qmn_variable_correct_score( $content, $mlw_quiz_array ) {
$correct_score = isset( $mlw_quiz_array['total_score'] ) ? $mlw_quiz_array['total_score'] : '';
$correct_score = isset( $mlw_quiz_array['total_score'] ) ? $mlw_quiz_array['total_score'] : 0;
$correct_score = qsm_is_allow_score_roundoff() ? round( $correct_score ) : round( $correct_score, 2 );
$content = str_replace( '%CORRECT_SCORE%', $correct_score, $content );
return $content;
Expand Down
1 change: 1 addition & 0 deletions php/template-variables/qsm-tempvar-question-answers.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function qsm_tempvar_qa_text_qt_choice( $total_answers, $answers_from_response,
$image_class = '';
$show_user_answer = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $show_user_answer, 'answer-' . $answers_from_response['id'] . '-' . $single_answer_key, 'QSM Answers' );
}
$show_user_answer = apply_filters( 'qsm_show_user_answer_after', $show_user_answer, $single_answer, $user_answer_array, $single_answer_key, $answers_from_response, $grading_system, $question_settings, $form_type, $total_answers );
$close_span = '</span>';
if ( 0 == $form_type && ( 0 === intval( $grading_system ) || 3 === intval( $grading_system ) ) ) {
$hide_correct_answer = $mlwQuizMasterNext->pluginHelper->get_section_setting( 'quiz_options', 'hide_correct_answer' );
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ This is usually a theme conflict. You can [checkout out our common conflict solu
18. Database

== Changelog ==
= 9.0.2 ( Beta ) =
* Bug: Fixed display shortcode php buffer due to invalid quiz id

= 9.0.1 (April 25, 2024) =
* Bug: Fixed date format in %ANSWER_X% variable
* Bug: Resolved PHP warning in Quiz Block editor
Expand Down

0 comments on commit 4d65b39

Please sign in to comment.