Skip to content

Commit

Permalink
fixed phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
zubairraeen committed Dec 3, 2023
2 parents 9f8e03c + a671076 commit dcb9ec8
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 12 deletions.
72 changes: 70 additions & 2 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ var qsmTimerInterval = [];
}
var secondsRemaining = qmn_quiz_data[quizID].timerRemaning;
var secondsConsumed = qmn_quiz_data[quizID].timerConsumed;
if (localStorage.getItem('mlw_time_quiz' + quizID) != null ) {
secondsRemaining = (parseFloat(qmn_quiz_data[quizID].timer_limit) * 60) - secondsConsumed + 1;
if(secondsRemaining < 0) {
secondsRemaining = 0;
}
}
var display = QSM.secondsToTimer(secondsRemaining);
var systemTime = new Date().getTime() / 1000;
systemTime = Math.round(systemTime);
Expand Down Expand Up @@ -1484,13 +1490,75 @@ jQuery(function () {
});
});

const videoAttributePatterns = [
/\ssrc="([^"]+)"/,
/\smp4="([^"]+)"/,
/\sm4v="([^"]+)"/,
/\swebm="([^"]+)"/,
/\sogv="([^"]+)"/,
/\swmv="([^"]+)"/,
/\sflv="([^"]+)"/,
/\swidth="(\d+)"/,
/\sheight="(\d+)"/
];

function parseAttributes(match, src, width, height) {
let videoAttrs = { src: '', width: '', height: '' };

videoAttributePatterns.forEach(pattern => {
const attrMatch = match.match(pattern);
if (attrMatch) {
const value = attrMatch[1] || '';
if (pattern.toString().includes('width')) {
videoAttrs.width = value;
} else if (pattern.toString().includes('height')) {
videoAttrs.height = value;
} else {
videoAttrs.src = value;
}
}
});

return videoAttrs;
}

function generateVideoTag(src, width, height, content) {
return `<video src="${src}" width="${width}" height="${height}" controls>${content}</video>`;
}

function qsm_check_shortcode(message = null) {
const videoContentRegex = /\[video(?:\s(?:src|mp4|m4v|webm|ogv|wmv|flv|width|height)="[^"]*")*\](.*?)\[\/video\]/g;
let videoMatch = message.match(videoContentRegex);

if (videoMatch) {
let videoHTML = message.replace(videoContentRegex, function(match, content) {
const { src, width, height } = parseAttributes(match);
const videoTag = generateVideoTag(src, width, height, content);
return `<div class="video-content">${videoTag}</div>`;
});
return videoHTML;
}

// Check if message contains an image shortcode
let imageRegex = /\[img(?:(?:\ssrc="([^"]+)")|(?:\salt="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,4}\s*\]/g;
let imageMatch = message.match(imageRegex);

if (imageMatch) {
let imageHTML = message.replace(imageRegex, function(match, src, alt, width, height) {
return '<img src="' + (src || '') + '" alt="' + (alt || '') + '" width="' + (width || '') + '" height="' + (height || '') + '">';
});
return '<div class="image-content">' + imageHTML + '</div>';
}

return message;
}

//inline result status function
function qsm_show_inline_result(quizID, question_id, value, $this, answer_type, $i_this, index = null) {
jQuery('.qsm-spinner-loader').remove();
addSpinnerLoader($this,$i_this);
let data = qsm_question_quick_result_js(question_id, value, answer_type, qmn_quiz_data[quizID].enable_quick_correct_answer_info,quizID);
$this.find('.quick-question-res-p').remove();
$this.find('.qsm-inline-correct-info').remove();
$this.find('.quick-question-res-p, .qsm-inline-correct-info').remove();
$this.find('.qmn_radio_answers').children().removeClass('data-correct-answer');
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>')
Expand Down
25 changes: 17 additions & 8 deletions php/admin/options-page-questions-tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ function qsm_options_questions_tab_content() {
$read_only = "";
$disable_class = "";
$background = "#FFFFFF";
$display_advance = "yes";
if ( ! class_exists ( 'QSM_AdvancedTimer' ) ) {
$read_only = 'readonly';
$disable_class = 'qsm-disabled-td';
$background = "#F0F0F0";
} else {
$date_now = date("d-m-Y");
$date_now = gmdate("d-m-Y");
$settings_data = get_option('qsm_addon_advanced_timer_settings', '');
$license = isset( $settings_data['license_key'] ) ? trim( $settings_data['license_key'] ) : '';
if ( version_compare( $mlwQuizMasterNext->version, '8.1.6', '<' ) && (isset($settings_data['expiry_date']) && "" != $settings_data['expiry_date']) && (isset($settings_data['last_validate']) && "" != $settings_data['last_validate']) && strtotime($date_now) > strtotime($settings_data['expiry_date']) && strtotime($date_now) >= strtotime($settings_data['last_validate']) ) {
Expand All @@ -180,6 +181,12 @@ function qsm_options_questions_tab_content() {
$target_link = sprintf( '<div class="notice notice-error notice-advance-timer"><strong>'.__('Error! ', 'quiz-master-next').'</strong>'.$target_text.'</div>' );
echo wp_kses_post($target_link);
}
$advancetimer = 'qsm-advanced-timer/qsm-advanced-timer.php';
$plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/'. $advancetimer);
$version_number = $plugin_data['Version'];
if ( version_compare($version_number, '2.0.0', '<') ) {
$display_advance = "no";
}
}
?>
<div class="question-controls">
Expand Down Expand Up @@ -697,34 +704,36 @@ class="save-page-button button button-primary"><?php esc_html_e( 'Save Questions
<div class="qsm-row">
<label class="qsm-page-setting-label"><?php esc_html_e( 'Button Control', 'quiz-master-next' ); ?></label>
<input name="hide_prevbtn" id="hide_prevbtn" type="checkbox" value="" />
<span class="qsm-page-setting-span"><?php _e( 'Hide Previous button', 'quiz-master-next' ); ?></span>
<span class="qsm-page-setting-span"><?php esc_html_e( 'Hide Previous button', 'quiz-master-next' ); ?></span>
</div>
<?php if ( "yes" == $display_advance ) { ?>
<div class="qsm-page-setting-container" style="background-color:<?php echo esc_attr($background); ?>">
<div class="qsm-page-setting-top ">
<div class="qsm-page-setting-left">
<span class="qsm-page-setting-label"><?php _e( 'Page Timer', 'quiz-master-next' ); ?></span>
<span class="qsm-page-setting-label"><?php esc_html_e( 'Page Timer', 'quiz-master-next' ); ?></span>
</div>
<div class="qsm-page-setting-right">
<div class="qsm-row <?php echo esc_attr($disable_class); ?>">
<label><?php _e( 'How many minutes does the user have to finish the page?', 'quiz-master-next' ); ?></label>
<span><?php _e( 'Set a time limit to complete this page in ', 'quiz-master-next' ); ?></span><input <?php echo esc_html($read_only); ?> type="number" step="1" class="small-text" min="0" id="pagetimer" name="pagetimer" value="0" placeholder="<?php _e( 'MM', 'quiz-master-next' ); ?>"> : <input type="number" <?php echo esc_html($read_only); ?> step="1" class="small-text" min="0" id="pagetimer_second" name="pagetimer_second" value="0" placeholder="<?php _e( 'SS', 'quiz-master-next' ); ?>">
<label><?php esc_html_e( 'How many minutes does the user have to finish the page?', 'quiz-master-next' ); ?></label>
<span><?php esc_html_e( 'Set a time limit to complete this page in ', 'quiz-master-next' ); ?></span><input <?php echo esc_html($read_only); ?> type="number" step="1" class="small-text" min="0" id="pagetimer" name="pagetimer" value="0" placeholder="<?php esc_attr_e( 'MM', 'quiz-master-next' ); ?>"> : <input type="number" <?php echo esc_html($read_only); ?> step="1" class="small-text" min="0" id="pagetimer_second" name="pagetimer_second" value="0" placeholder="<?php esc_attr_e( 'SS', 'quiz-master-next' ); ?>">
</div>
<div class="qsm-row <?php echo esc_attr($disable_class); ?>">
<input <?php echo esc_html($read_only); ?> name="warning_checkbox" type="checkbox" value="" /><span><?php esc_html_e( 'Show warning at', 'quiz-master-next' ); ?></span>
<input <?php echo esc_html($read_only); ?> type="number" step="1" class="small-text" min="0" placeholder="<?php _e( 'MM', 'quiz-master-next' ); ?>" id="pagetimer_warning" name="pagetimer_warning" value="0"> :
<input <?php echo esc_html($read_only); ?> type="number" step="1" class="small-text" min="0" placeholder="<?php _e( 'SS', 'quiz-master-next' ); ?>" id="pagetimer_warning_second" name="pagetimer_warning_second" value="0">
<input <?php echo esc_html($read_only); ?> type="number" step="1" class="small-text" min="0" placeholder="<?php esc_html_e( 'MM', 'quiz-master-next' ); ?>" id="pagetimer_warning" name="pagetimer_warning" value="0"> :
<input <?php echo esc_html($read_only); ?> type="number" step="1" class="small-text" min="0" placeholder="<?php esc_html_e( 'SS', 'quiz-master-next' ); ?>" id="pagetimer_warning_second" name="pagetimer_warning_second" value="0">
</div>
</div>
</div>
<div class="qsm-page-setting-bottom ">
<?php if ( ! class_exists ( 'QSM_AdvancedTimer' ) ) { ?>
<div class="qsm-popup-upgrade-warning">
<img src="<?php echo esc_url( QSM_PLUGIN_URL . 'php/images/info-yellow.png' ); ?>" alt="information">
<span><?php _e( 'You can set timer in each page using Advanced Timer Add-on. ', 'quiz-master-next'); echo sprintf( '<a style="margin-right: 5px;font-weight: bolder;" href="%s" target="_blank">%s</a>', esc_url( qsm_get_plugin_link( 'downloads/wordpress-quiz-timer-advanced', 'advanced-timer-popup', 'quiz_editor', 'get_addon', 'qsm_plugin_upsell' ) ), __( 'Get this add-on ', 'quiz-master-next' ) ); _e( 'and extend your quiz features.', 'quiz-master-next' ); ?></span>
<span><?php esc_html_e( 'You can set timer in each page using Advanced Timer Add-on. ', 'quiz-master-next'); echo sprintf( '<a style="margin-right: 5px;font-weight: bolder;" href="%s" target="_blank">%s</a>', esc_url( qsm_get_plugin_link( 'downloads/wordpress-quiz-timer-advanced', 'advanced-timer-popup', 'quiz_editor', 'get_addon', 'qsm_plugin_upsell' ) ), __( 'Get this add-on ', 'quiz-master-next' ) ); esc_html_e( 'and extend your quiz features.', 'quiz-master-next' ); ?></span>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<?php do_action( 'qsm_action_quiz_page_attributes_fields' ); ?>
</div>
</main>
Expand Down
20 changes: 20 additions & 0 deletions php/admin/settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function init() {
add_settings_field( 'ip-collection', __( 'Disable collecting and storing IP addresses?', 'quiz-master-next' ), array( $this, 'ip_collection_field' ), 'qmn_global_settings', 'qmn-global-section' );
add_settings_field( 'cpt-search', __( 'Disable Quiz Posts From Being Searched?', 'quiz-master-next' ), array( $this, 'cpt_search_field' ), 'qmn_global_settings', 'qmn-global-section' );
add_settings_field( 'cpt-archive', __( 'Quiz Archive Settings', 'quiz-master-next' ), array( $this, 'cpt_archive_field' ), 'qmn_global_settings', 'qmn-global-section' );
add_settings_field( 'duplicate-quiz-with-theme', __( 'Duplicate Quiz Controls', 'quiz-master-next' ), array( $this, 'qsm_duplicate_quiz_with_theme' ), 'qmn_global_settings', 'qmn-global-section' );
add_settings_field( 'detele-qsm-data', __( 'Delete all the data related to QSM on deletion?', 'quiz-master-next' ), array( $this, 'qsm_delete_data' ), 'qmn_global_settings', 'qmn-global-section' );
add_settings_field( 'background-quiz-email-process', __( 'Process emails in background?', 'quiz-master-next' ), array( $this, 'qsm_background_quiz_email_process' ), 'qmn_global_settings', 'qmn-global-section' );
add_settings_field( 'cpt-slug', __( 'Quiz Url Slug', 'quiz-master-next' ), array( $this, 'cpt_slug_field' ), 'qmn_global_settings', 'qmn-global-section' );
Expand Down Expand Up @@ -368,6 +369,25 @@ public function cpt_search_field() {
echo '<span class="slider round"></span></label>';
}

/**
* Generates Setting Field To Duplicate Quiz with Theme Settings
*
* @since 8.1.19
* @return void
*/
public function qsm_duplicate_quiz_with_theme() {
$settings = (array) get_option( 'qmn-settings' );
$duplicate_quiz_with_theme = ! empty( $settings['duplicate_quiz_with_theme'] ) ? esc_attr( $settings['duplicate_quiz_with_theme'] ) : 0;
?>
<fieldset>
<label for="qmn-settings-duplicate_quiz_with_theme">
<input type="checkbox" name="qmn-settings[duplicate_quiz_with_theme]" id="qmn-settings-duplicate_quiz_with_theme" value="1" <?php checked( $duplicate_quiz_with_theme, 1, true ); ?> />
<?php esc_html_e( 'Enable quiz duplication along with theme settings', 'quiz-master-next'); ?>
</label>
</fieldset>
<?php
}

/**
* Generates Setting Field For Post Archive
*
Expand Down
32 changes: 30 additions & 2 deletions php/classes/class-qmn-quiz-creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function delete_quiz( $quiz_id, $quiz_name ) {
}

$is_row_exists = $wpdb->get_var( $wpdb->prepare( "SELECT * FROM $quizzes_table WHERE quiz_id=%d", $quiz_id ) );

if ( $qsm_delete_from_db ) {
$qsm_delete = $wpdb->delete(
$wpdb->prefix . 'mlw_quizzes',
Expand Down Expand Up @@ -273,7 +273,7 @@ public function delete_quiz( $quiz_id, $quiz_name ) {
);
}
}

if ( empty( $is_row_exists ) ) {
$qsm_delete = 1;
}
Expand Down Expand Up @@ -493,6 +493,34 @@ public function duplicate_quiz( $quiz_id, $quiz_name, $is_duplicating_questions
);
$mlw_new_id = $wpdb->insert_id;

$settings = (array) get_option('qmn-settings');
$duplicate_quiz_with_theme = ! empty($settings['duplicate_quiz_with_theme']) ? esc_attr($settings['duplicate_quiz_with_theme']) : 0;

if ( '1' === $duplicate_quiz_with_theme ) {
$theme_table = $wpdb->prefix . 'mlw_quiz_theme_settings';
$old_quiz_theme_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM $theme_table WHERE quiz_id = %d AND active_theme = 1", $quiz_id));

if ( $old_quiz_theme_data ) {
$new_quiz_theme_data = array(
'theme_id' => $old_quiz_theme_data->theme_id,
'quiz_id' => $mlw_new_id,
'quiz_theme_settings' => $old_quiz_theme_data->quiz_theme_settings,
'active_theme' => 1,
);

$format = array(
'%d',
'%d',
'%s',
'%d',
);

$wpdb->insert($theme_table, $new_quiz_theme_data, $format);
$mlwQuizMasterNext->alertManager->newAlert(__('There has been an error in this action. Please share this with the developer. Error Code: 0051', 'quiz-master-next'), 'error');
$mlwQuizMasterNext->log_manager->add('Error 0051', $wpdb->last_error . ' from ' . $wpdb->last_query, 0, 'error');
}
}

// Update quiz settings
$update_quiz_settings = maybe_unserialize( $mlw_qmn_duplicate_data->quiz_settings );
$update_pages = maybe_unserialize( $update_quiz_settings['pages'] );
Expand Down
1 change: 1 addition & 0 deletions php/question-types/qsm-question-title.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function qsm_question_title_func( $question, $question_type = '', $new_question_
$allow_html['input']['class'] = 1;
$allow_html['input']['id'] = 1;
$allow_html['input']['maxlength'] = 1;
$allow_html = apply_filters( 'qsm_allow_html_question_title_after', $question_id, $allow_html );
?>
<p><?php echo do_shortcode( wp_kses( $question_title . $deselect_answer, $allow_html ) ); ?></p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function qmn_fill_blank_display( $id, $question, $answers ) {
$mlw_require_class = '';
}
$input_text = '<input ' . $autofill_att . $limit_text_att . " type='text' class='qmn_fill_blank $mlw_require_class' name='question" . $id . "[]' />";
$input_text = apply_filters( 'qsm_fill_in_blanks_input_after', $input_text, $id, $question, $answers, $mlw_require_class );
if ( strpos( $question, '%BLANK%' ) !== false ) {
$question = str_replace( '%BLANK%', $input_text, do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) );
}
Expand Down

0 comments on commit dcb9ec8

Please sign in to comment.