public function save(WpProQuiz_Model_Quiz $data) { if ($data->isResultGradeEnabled()) { $resultText = serialize($data->getResultText()); } else { $resultText = $data->getResultText(); } $set = array('name' => $data->getName(), 'text' => $data->getText(), 'result_text' => $resultText, 'title_hidden' => (int) $data->isTitleHidden(), 'btn_restart_quiz_hidden' => (int) $data->isBtnRestartQuizHidden(), 'btn_view_question_hidden' => (int) $data->isBtnViewQuestionHidden(), 'question_random' => (int) $data->isQuestionRandom(), 'answer_random' => (int) $data->isAnswerRandom(), 'time_limit' => (int) $data->getTimeLimit(), 'statistics_on' => (int) $data->isStatisticsOn(), 'statistics_ip_lock' => (int) $data->getStatisticsIpLock(), 'result_grade_enabled' => (int) $data->isResultGradeEnabled(), 'show_points' => (int) $data->isShowPoints(), 'quiz_run_once' => (int) $data->isQuizRunOnce(), 'quiz_run_once_type' => $data->getQuizRunOnceType(), 'quiz_run_once_cookie' => (int) $data->isQuizRunOnceCookie(), 'quiz_run_once_time' => (int) $data->getQuizRunOnceTime(), 'numbered_answer' => (int) $data->isNumberedAnswer(), 'hide_answer_message_box' => (int) $data->isHideAnswerMessageBox(), 'disabled_answer_mark' => (int) $data->isDisabledAnswerMark(), 'show_max_question' => (int) $data->isShowMaxQuestion(), 'show_max_question_value' => (int) $data->getShowMaxQuestionValue(), 'show_max_question_percent' => (int) $data->isShowMaxQuestionPercent(), 'toplist_activated' => (int) $data->isToplistActivated(), 'toplist_data' => $data->getToplistData(), 'show_average_result' => (int) $data->isShowAverageResult(), 'prerequisite' => (int) $data->isPrerequisite(), 'quiz_modus' => (int) $data->getQuizModus(), 'show_review_question' => (int) $data->isShowReviewQuestion(), 'quiz_summary_hide' => (int) $data->isQuizSummaryHide(), 'skip_question_disabled' => (int) $data->isSkipQuestionDisabled(), 'email_notification' => $data->getEmailNotification(), 'user_email_notification' => (int) $data->isUserEmailNotification(), 'show_category_score' => (int) $data->isShowCategoryScore(), 'hide_result_correct_question' => (int) $data->isHideResultCorrectQuestion(), 'hide_result_quiz_time' => (int) $data->isHideResultQuizTime(), 'hide_result_points' => (int) $data->isHideResultPoints(), 'autostart' => (int) $data->isAutostart(), 'forcing_question_solve' => (int) $data->isForcingQuestionSolve(), 'hide_question_position_overview' => (int) $data->isHideQuestionPositionOverview(), 'hide_question_numbering' => (int) $data->isHideQuestionNumbering(), 'form_activated' => (int) $data->isFormActivated(), 'form_show_position' => $data->getFormShowPosition(), 'start_only_registered_user' => (int) $data->isStartOnlyRegisteredUser(), 'questions_per_page' => $data->getQuestionsPerPage(), 'sort_categories' => (int) $data->isSortCategories(), 'show_category' => (int) $data->isShowCategory(), 'category_id' => (int) $data->getCategoryId(), 'admin_email' => $data->getAdminEmail(true), 'user_email' => $data->getUserEmail(true), 'plugin_container' => $data->getPluginContainer(true)); if ($data->getId() != 0) { $result = $this->_wpdb->update($this->_table, $set, array('id' => $data->getId()), array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%s', '%s'), array('%d')); } else { $result = $this->_wpdb->insert($this->_table, $set, array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s', '%s', '%s')); $data->setId($this->_wpdb->insert_id); } if ($result === false) { return null; } /** * Fired when a new WP Pro Quiz is created. * * @since 0.38.0 * * @param WpProQuiz_Model_Quiz Object $data The newly created WpProQuiz_Model_Quiz object */ do_action('wp_pro_quiz_save_quiz', $data); return $data; }
private function formTable() { if (!$this->quiz->isFormActivated()) { return; } ?> <div id="wpProQuiz_form_box"> <div id="poststuff"> <div class="postbox"> <h3 class="hndle"><?php _e('Custom fields', 'wp-pro-quiz'); ?> </h3> <div class="inside"> <table> <tbody> <?php foreach ($this->forms as $form) { /* @var $form WpProQuiz_Model_Form */ ?> <tr> <td style="padding: 5px;"><?php echo esc_html($form->getFieldname()); ?> </td> <td id="form_id_<?php echo $form->getFormId(); ?> ">asdfffffffffffffffffffffsadfsdfa sf asd fas </td> </tr> <?php } ?> </tbody> </table> </div> </div> </div> </div> <?php }
public function show() { ?> <style> .wpProQuiz_blueBox { padding: 20px; background-color: rgb(223, 238, 255); border: 1px dotted; margin-top: 10px; } .categoryTr th { background-color: #F1F1F1; } .wpProQuiz_modal_backdrop { background: #000; opacity: 0.7; top: 0; bottom: 0; right: 0; left: 0; position: fixed; z-index: 159900; } .wpProQuiz_modal_window { position: fixed; background: #FFF; top: 40px; bottom: 40px; left: 40px; right: 40px; z-index: 160000; } .wpProQuiz_actions { display: none; padding: 2px 0 0; } .mobile .wpProQuiz_actions { display: block; } tr:hover .wpProQuiz_actions { display: block; } </style> <div class="wrap wpProQuiz_statisticsNew"> <input type="hidden" id="quizId" value="<?php echo $this->quiz->getId(); ?> " name="quizId"> <h2><?php printf(__('Quiz: %s - Statistics', 'wp-pro-quiz'), $this->quiz->getName()); ?> </h2> <p><a class="button-secondary" href="admin.php?page=wpProQuiz"><?php _e('back to overview', 'wp-pro-quiz'); ?> </a></p> <?php if (!$this->quiz->isStatisticsOn()) { ?> <p style="padding: 30px; background: #F7E4E4; border: 1px dotted; width: 300px;"> <span style="font-weight: bold; padding-right: 10px;"><?php _e('Stats not enabled', 'wp-pro-quiz'); ?> </span> <a class="button-secondary" href="admin.php?page=wpProQuiz&action=addEdit&quizId=<?php echo $this->quiz->getId(); ?> "><?php _e('Activate statistics', 'wp-pro-quiz'); ?> </a> </p> <?php return; } ?> <div style="padding: 10px 0px;" class="wpProQuiz_tab_wrapper"> <a class="button-primary" href="#" data-tab="#wpProQuiz_tabHistory"><?php _e('History', 'wp-pro-quiz'); ?> </a> <a class="button-secondary" href="#" data-tab="#wpProQuiz_tabOverview"><?php _e('Overview', 'wp-pro-quiz'); ?> </a> </div> <div id="wpProQuiz_loadData" class="wpProQuiz_blueBox" style="background-color: #F8F5A8; display: none;"> <img alt="load" src="data:image/gif;base64,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"> <?php _e('Loading', 'wp-pro-quiz'); ?> </div> <div id="wpProQuiz_content" style="display: block;"> <?php $this->showHistory(); ?> <?php $this->showTabOverview(); ?> </div> <?php $this->showModalWindow(); ?> </div> <?php }
/** * @param DOMDocument $dom * @param WpProQuiz_Model_Quiz $quiz * @param $forms * @return DOMElement */ private function getQuizElement($dom, $quiz, $forms) { $quizElement = $dom->createElement('quiz'); $title = $dom->createElement('title'); $title->appendChild($dom->createCDATASection($quiz->getName())); $title->setAttribute('titleHidden', $this->booleanToTrueOrFalse($quiz->isTitleHidden())); $quizElement->appendChild($title); $quizElement->appendChild($text = $dom->createElement('text')); $text->appendChild($dom->createCDATASection($quiz->getText())); $quizElement->appendChild($dom->createElement('category', $quiz->getCategoryName())); if (is_array($quiz->getResultText())) { $resultArray = $quiz->getResultText(); $result = $dom->createElement('resultText'); $result->setAttribute('gradeEnabled', $this->booleanToTrueOrFalse($quiz->isResultGradeEnabled())); for ($i = 0; $i < count($resultArray); $i++) { $r = $dom->createElement('text'); $r->appendChild($dom->createCDATASection($resultArray['text'][$i])); $r->setAttribute('prozent', $resultArray['prozent'][$i]); $result->appendChild($r); } $quizElement->appendChild($result); } else { $result = $dom->createElement('resultText'); $result->setAttribute('gradeEnabled', $this->booleanToTrueOrFalse($quiz->isResultGradeEnabled())); $result->appendChild($dom->createCDATASection($quiz->getResultText())); $quizElement->appendChild($result); } $quizElement->appendChild($dom->createElement('btnRestartQuizHidden', $this->booleanToTrueOrFalse($quiz->isBtnRestartQuizHidden()))); $quizElement->appendChild($dom->createElement('btnViewQuestionHidden', $this->booleanToTrueOrFalse($quiz->isBtnViewQuestionHidden()))); $quizElement->appendChild($dom->createElement('questionRandom', $this->booleanToTrueOrFalse($quiz->isQuestionRandom()))); $quizElement->appendChild($dom->createElement('answerRandom', $this->booleanToTrueOrFalse($quiz->isAnswerRandom()))); $quizElement->appendChild($dom->createElement('timeLimit', $quiz->getTimeLimit())); $quizElement->appendChild($dom->createElement('showPoints', $this->booleanToTrueOrFalse($quiz->isShowPoints()))); $statistic = $dom->createElement('statistic'); $statistic->setAttribute('activated', $this->booleanToTrueOrFalse($quiz->isStatisticsOn())); $statistic->setAttribute('ipLock', $quiz->getStatisticsIpLock()); $quizElement->appendChild($statistic); $quizElement->appendChild($quizRunOnce = $dom->createElement('quizRunOnce', $this->booleanToTrueOrFalse($quiz->isQuizRunOnce()))); $quizRunOnce->setAttribute('type', $quiz->getQuizRunOnceType()); $quizRunOnce->setAttribute('cookie', $this->booleanToTrueOrFalse($quiz->isQuizRunOnceCookie())); $quizRunOnce->setAttribute('time', $quiz->getQuizRunOnceTime()); $quizElement->appendChild($dom->createElement('numberedAnswer', $this->booleanToTrueOrFalse($quiz->isNumberedAnswer()))); $quizElement->appendChild($dom->createElement('hideAnswerMessageBox', $this->booleanToTrueOrFalse($quiz->isHideAnswerMessageBox()))); $quizElement->appendChild($dom->createElement('disabledAnswerMark', $this->booleanToTrueOrFalse($quiz->isDisabledAnswerMark()))); $quizElement->appendChild($showMaxQuestion = $dom->createElement('showMaxQuestion', $this->booleanToTrueOrFalse($quiz->isShowMaxQuestion()))); $showMaxQuestion->setAttribute('showMaxQuestionValue', $quiz->getShowMaxQuestionValue()); $showMaxQuestion->setAttribute('showMaxQuestionPercent', $this->booleanToTrueOrFalse($quiz->isShowMaxQuestionPercent())); //Toplist $toplist = $dom->createElement('toplist'); $toplist->setAttribute('activated', $this->booleanToTrueOrFalse($quiz->isToplistActivated())); $toplist->appendChild($dom->createElement('toplistDataAddPermissions', $quiz->getToplistDataAddPermissions())); $toplist->appendChild($dom->createElement('toplistDataSort', $quiz->getToplistDataSort())); $toplist->appendChild($dom->createElement('toplistDataAddMultiple', $this->booleanToTrueOrFalse($quiz->isToplistDataAddMultiple()))); $toplist->appendChild($dom->createElement('toplistDataAddBlock', $quiz->getToplistDataAddBlock())); $toplist->appendChild($dom->createElement('toplistDataShowLimit', $quiz->getToplistDataShowLimit())); $toplist->appendChild($dom->createElement('toplistDataShowIn', $quiz->getToplistDataShowIn())); $toplist->appendChild($dom->createElement('toplistDataCaptcha', $this->booleanToTrueOrFalse($quiz->isToplistDataCaptcha()))); $toplist->appendChild($dom->createElement('toplistDataAddAutomatic', $this->booleanToTrueOrFalse($quiz->isToplistDataAddAutomatic()))); $quizElement->appendChild($toplist); $quizElement->appendChild($dom->createElement('showAverageResult', $this->booleanToTrueOrFalse($quiz->isShowAverageResult()))); $quizElement->appendChild($dom->createElement('prerequisite', $this->booleanToTrueOrFalse($quiz->isPrerequisite()))); $quizElement->appendChild($dom->createElement('showReviewQuestion', $this->booleanToTrueOrFalse($quiz->isShowReviewQuestion()))); $quizElement->appendChild($dom->createElement('quizSummaryHide', $this->booleanToTrueOrFalse($quiz->isQuizSummaryHide()))); $quizElement->appendChild($dom->createElement('skipQuestionDisabled', $this->booleanToTrueOrFalse($quiz->isSkipQuestionDisabled()))); $quizElement->appendChild($dom->createElement('emailNotification', $quiz->getEmailNotification())); $quizElement->appendChild($dom->createElement('userEmailNotification', $this->booleanToTrueOrFalse($quiz->isUserEmailNotification()))); $quizElement->appendChild($dom->createElement('showCategoryScore', $this->booleanToTrueOrFalse($quiz->isShowCategoryScore()))); $quizElement->appendChild($dom->createElement('hideResultCorrectQuestion', $this->booleanToTrueOrFalse($quiz->isHideResultCorrectQuestion()))); $quizElement->appendChild($dom->createElement('hideResultQuizTime', $this->booleanToTrueOrFalse($quiz->isHideResultQuizTime()))); $quizElement->appendChild($dom->createElement('hideResultPoints', $this->booleanToTrueOrFalse($quiz->isHideResultPoints()))); $quizElement->appendChild($dom->createElement('autostart', $this->booleanToTrueOrFalse($quiz->isAutostart()))); $quizElement->appendChild($dom->createElement('forcingQuestionSolve', $this->booleanToTrueOrFalse($quiz->isForcingQuestionSolve()))); $quizElement->appendChild($dom->createElement('hideQuestionPositionOverview', $this->booleanToTrueOrFalse($quiz->isHideQuestionPositionOverview()))); $quizElement->appendChild($dom->createElement('hideQuestionNumbering', $this->booleanToTrueOrFalse($quiz->isHideQuestionNumbering()))); //0.27 $quizElement->appendChild($dom->createElement('sortCategories', $this->booleanToTrueOrFalse($quiz->isSortCategories()))); $quizElement->appendChild($dom->createElement('showCategory', $this->booleanToTrueOrFalse($quiz->isShowCategory()))); $quizModus = $dom->createElement('quizModus', $quiz->getQuizModus()); $quizModus->setAttribute('questionsPerPage', $quiz->getQuestionsPerPage()); $quizElement->appendChild($quizModus); $quizElement->appendChild($dom->createElement('startOnlyRegisteredUser', $this->booleanToTrueOrFalse($quiz->isStartOnlyRegisteredUser()))); $formsElement = $dom->createElement('forms'); $formsElement->setAttribute('activated', $this->booleanToTrueOrFalse($quiz->isFormActivated())); $formsElement->setAttribute('position', $quiz->getFormShowPosition()); //0.29 if ($quiz->getAdminEmail() !== null) { /* @var $adminEmail WpProQuiz_Model_Email */ $adminEmail = $quiz->getAdminEmail(); $adminEmailXml = $dom->createElement('adminEmail'); /* * $qElement->appendChild($title = $dom->createElement('title')); $title->appendChild($dom->createCDATASection($question->getTitle())); */ $adminEmailXml->appendChild($dom->createElement('to', $adminEmail->getTo())); $adminEmailXml->appendChild($dom->createElement('form', $adminEmail->getFrom())); $adminEmailXml->appendChild($dom->createElement('subject', $adminEmail->getSubject())); $adminEmailXml->appendChild($dom->createElement('html', $this->booleanToTrueOrFalse($adminEmail->isHtml()))); $adminEmailXml->appendChild($message = $dom->createElement('message')); $message->appendChild($dom->createCDATASection($adminEmail->getMessage())); $quizElement->appendChild($adminEmailXml); } if ($quiz->getUserEmail() !== null) { /* @var $adminEmail WpProQuiz_Model_Email */ $userEmail = $quiz->getUserEmail(); $userEmaillXml = $dom->createElement('userEmail'); $userEmaillXml->appendChild($dom->createElement('to', $userEmail->getTo())); $userEmaillXml->appendChild($dom->createElement('toUser', $this->booleanToTrueOrFalse($userEmail->isToUser()))); $userEmaillXml->appendChild($dom->createElement('toForm', $this->booleanToTrueOrFalse($userEmail->isToForm()))); $userEmaillXml->appendChild($dom->createElement('form', $userEmail->getFrom())); $userEmaillXml->appendChild($dom->createElement('subject', $userEmail->getSubject())); $userEmaillXml->appendChild($dom->createElement('html', $this->booleanToTrueOrFalse($userEmail->isHtml()))); $userEmaillXml->appendChild($message = $dom->createElement('message')); $message->appendChild($dom->createCDATASection($userEmail->getMessage())); $quizElement->appendChild($userEmaillXml); } foreach ($forms as $form) { /** @var WpProQuiz_Model_Form $form * */ $formElement = $dom->createElement('form'); $formElement->setAttribute('type', $form->getType()); $formElement->setAttribute('required', $this->booleanToTrueOrFalse($form->isRequired())); $formElement->setAttribute('fieldname', $form->getFieldname()); if ($form->getData() !== null) { $data = $form->getData(); foreach ($data as $d) { $formDataElement = $dom->createElement('formData', $d); $formElement->appendChild($formDataElement); } } $formsElement->appendChild($formElement); } $quizElement->appendChild($formsElement); return $quizElement; }
private function showQuizBox($questionCount) { $globalPoints = 0; $json = array(); $catPoints = array(); ?> <div style="display: none;" class="wpProQuiz_quiz"> <ol class="wpProQuiz_list"> <?php $index = 0; foreach ($this->question as $question) { $index++; /* @var $answerArray WpProQuiz_Model_AnswerTypes[] */ $answerArray = $question->getAnswerData(); $globalPoints += $question->getPoints(); $json[$question->getId()]['type'] = $question->getAnswerType(); $json[$question->getId()]['id'] = (int) $question->getId(); $json[$question->getId()]['catId'] = (int) $question->getCategoryId(); if ($question->isAnswerPointsActivated() && $question->isAnswerPointsDiffModusActivated() && $question->isDisableCorrect()) { $json[$question->getId()]['disCorrect'] = (int) $question->isDisableCorrect(); } if (!isset($catPoints[$question->getCategoryId()])) { $catPoints[$question->getCategoryId()] = 0; } $catPoints[$question->getCategoryId()] += $question->getPoints(); if (!$question->isAnswerPointsActivated()) { $json[$question->getId()]['points'] = $question->getPoints(); // $catPoints[$question->getCategoryId()] += $question->getPoints(); } if ($question->isAnswerPointsActivated() && $question->isAnswerPointsDiffModusActivated()) { // $catPoints[$question->getCategoryId()] += $question->getPoints(); $json[$question->getId()]['diffMode'] = 1; } ?> <li class="wpProQuiz_listItem" style="display: none;"> <div class="wpProQuiz_question_page" <?php $this->isDisplayNone($this->quiz->getQuizModus() != WpProQuiz_Model_Quiz::QUIZ_MODUS_SINGLE && !$this->quiz->isHideQuestionPositionOverview()); ?> > <?php printf(__('Question %s of %s', 'wp-pro-quiz'), '<span>' . $index . '</span>', '<span>' . $questionCount . '</span>'); ?> </div> <h5 style="<?php echo $this->quiz->isHideQuestionNumbering() ? 'display: none;' : 'display: inline-block;'; ?> " class="wpProQuiz_header"> <span><?php echo $index; ?> </span>. <?php _e('Question', 'wp-pro-quiz'); ?> </h5> <?php if ($this->quiz->isShowPoints()) { ?> <span style="font-weight: bold; float: right;"><?php printf(__('%d points', 'wp-pro-quiz'), $question->getPoints()); ?> </span> <div style="clear: both;"></div> <?php } ?> <?php if ($question->getCategoryId() && $this->quiz->isShowCategory()) { ?> <div style="font-weight: bold; padding-top: 5px;"> <?php printf(__('Category: %s', 'wp-pro-quiz'), esc_html($question->getCategoryName())); ?> </div> <?php } ?> <div class="wpProQuiz_question" style="margin: 10px 0 0 0;"> <div class="wpProQuiz_question_text"> <?php echo do_shortcode(apply_filters('comment_text', $question->getQuestion())); ?> </div> <?php if ($question->getAnswerType() === 'matrix_sort_answer') { ?> <div class="wpProQuiz_matrixSortString"> <h5 class="wpProQuiz_header"><?php _e('Sort elements', 'wp-pro-quiz'); ?> </h5> <ul class="wpProQuiz_sortStringList"> <?php $matrix = array(); foreach ($answerArray as $k => $v) { $matrix[$k][] = $k; foreach ($answerArray as $k2 => $v2) { if ($k != $k2) { if ($v->getAnswer() == $v2->getAnswer()) { $matrix[$k][] = $k2; } else { if ($v->getSortString() == $v2->getSortString()) { $matrix[$k][] = $k2; } } } } } foreach ($answerArray as $k => $v) { ?> <li class="wpProQuiz_sortStringItem" data-pos="<?php echo $k; ?> " data-correct="<?php echo implode(',', $matrix[$k]); ?> "> <?php echo $v->isSortStringHtml() ? $v->getSortString() : esc_html($v->getSortString()); ?> </li> <?php } ?> </ul> <div style="clear: both;"></div> </div> <?php } ?> <ul class="wpProQuiz_questionList" data-question_id="<?php echo $question->getId(); ?> " data-type="<?php echo $question->getAnswerType(); ?> "> <?php $answer_index = 0; foreach ($answerArray as $v) { $answer_text = $v->isHtml() ? $v->getAnswer() : esc_html($v->getAnswer()); if ($answer_text == '') { continue; } if ($question->isAnswerPointsActivated()) { $json[$question->getId()]['points'][] = $v->getPoints(); // if(!$question->isAnswerPointsDiffModusActivated()) // $catPoints[$question->getCategoryId()] += $question->getPoints(); } ?> <li class="wpProQuiz_questionListItem" data-pos="<?php echo $answer_index; ?> "> <?php if ($question->getAnswerType() === 'single' || $question->getAnswerType() === 'multiple') { ?> <?php $json[$question->getId()]['correct'][] = (int) $v->isCorrect(); ?> <span <?php echo $this->quiz->isNumberedAnswer() ? '' : 'style="display:none;"'; ?> ></span> <label> <input class="wpProQuiz_questionInput" type="<?php echo $question->getAnswerType() === 'single' ? 'radio' : 'checkbox'; ?> " name="question_<?php echo $this->quiz->getId(); ?> _<?php echo $question->getId(); ?> " value="<?php echo $answer_index + 1; ?> "> <?php echo $answer_text; ?> </label> <?php } else { if ($question->getAnswerType() === 'sort_answer') { ?> <?php $json[$question->getId()]['correct'][] = (int) $answer_index; ?> <div class="wpProQuiz_sortable"> <?php echo $answer_text; ?> </div> <?php } else { if ($question->getAnswerType() === 'free_answer') { ?> <?php $json[$question->getId()]['correct'] = $this->getFreeCorrect($v); ?> <label> <input class="wpProQuiz_questionInput" type="text" name="question_<?php echo $this->quiz->getId(); ?> _<?php echo $question->getId(); ?> " style="width: 300px;"> </label> <?php } else { if ($question->getAnswerType() === 'matrix_sort_answer') { ?> <?php $json[$question->getId()]['correct'][] = (int) $answer_index; $msacwValue = $question->getMatrixSortAnswerCriteriaWidth() > 0 ? $question->getMatrixSortAnswerCriteriaWidth() : 20; ?> <table> <tbody> <tr class="wpProQuiz_mextrixTr"> <td width="<?php echo $msacwValue; ?> %"><div class="wpProQuiz_maxtrixSortText" ><?php echo $answer_text; ?> </div></td> <td width="<?php echo 100 - $msacwValue; ?> %" > <ul class="wpProQuiz_maxtrixSortCriterion"></ul> </td> </tr> </tbody> </table> <?php } else { if ($question->getAnswerType() === 'cloze_answer') { $clozeData = $this->fetchCloze($v->getAnswer()); $this->_clozeTemp = $clozeData['data']; $json[$question->getId()]['correct'] = $clozeData['correct']; if ($question->isAnswerPointsActivated()) { $json[$question->getId()]['points'] = $clozeData['points']; } $cloze = do_shortcode(apply_filters('comment_text', $clozeData['replace'])); $cloze = $clozeData['replace']; echo preg_replace_callback('#@@wpProQuizCloze@@#im', array($this, 'clozeCallback'), $cloze); } else { if ($question->getAnswerType() === 'assessment_answer') { $assessmentData = $this->fetchAssessment($v->getAnswer(), $this->quiz->getId(), $question->getId()); $assessment = do_shortcode(apply_filters('comment_text', $assessmentData['replace'])); echo preg_replace_callback('#@@wpProQuizAssessment@@#im', array($this, 'assessmentCallback'), $assessment); } } } } } } ?> </li> <?php $answer_index++; } ?> </ul> </div> <?php if (!$this->quiz->isHideAnswerMessageBox()) { ?> <div class="wpProQuiz_response" style="display: none;"> <div style="display: none;" class="wpProQuiz_correct"> <?php if ($question->isShowPointsInBox() && $question->isAnswerPointsActivated()) { ?> <div> <span style="float: left;" class="wpProQuiz_respone_span"> <?php _e('Correct', 'wp-pro-quiz'); ?> </span> <span style="float: right;"><?php echo $question->getPoints() . ' / ' . $question->getPoints(); ?> <?php _e('Points', 'wp-pro-quiz'); ?> </span> <div style="clear: both;"></div> </div> <?php } else { ?> <span class="wpProQuiz_respone_span"> <?php _e('Correct', 'wp-pro-quiz'); ?> </span><br> <?php } $_correctMsg = trim(do_shortcode(apply_filters('comment_text', $question->getCorrectMsg()))); if (strpos($_correctMsg, '<p') === 0) { echo $_correctMsg; } else { echo '<p>', $_correctMsg, '</p>'; } ?> </div> <div style="display: none;" class="wpProQuiz_incorrect"> <?php if ($question->isShowPointsInBox() && $question->isAnswerPointsActivated()) { ?> <div> <span style="float: left;" class="wpProQuiz_respone_span"> <?php _e('Incorrect', 'wp-pro-quiz'); ?> </span> <span style="float: right;"><span class="wpProQuiz_responsePoints"></span> / <?php echo $question->getPoints(); ?> <?php _e('Points', 'wp-pro-quiz'); ?> </span> <div style="clear: both;"></div> </div> <?php } else { ?> <span class="wpProQuiz_respone_span"> <?php _e('Incorrect', 'wp-pro-quiz'); ?> </span><br> <?php } if ($question->isCorrectSameText()) { $_incorrectMsg = do_shortcode(apply_filters('comment_text', $question->getCorrectMsg())); } else { $_incorrectMsg = do_shortcode(apply_filters('comment_text', $question->getIncorrectMsg())); } if (strpos($_incorrectMsg, '<p') === 0) { echo $_incorrectMsg; } else { echo '<p>', $_incorrectMsg, '</p>'; } ?> </div> </div> <?php } ?> <?php if ($question->isTipEnabled()) { ?> <div class="wpProQuiz_tipp" style="display: none; position: relative;"> <div> <h5 style="margin: 0 0 10px;" class="wpProQuiz_header"><?php _e('Hint', 'wp-pro-quiz'); ?> </h5> <?php echo do_shortcode(apply_filters('comment_text', $question->getTipMsg())); ?> </div> </div> <?php } ?> <?php if ($this->quiz->getQuizModus() == WpProQuiz_Model_Quiz::QUIZ_MODUS_CHECK && !$this->quiz->isSkipQuestionDisabled() && $this->quiz->isShowReviewQuestion()) { ?> <input type="button" name="skip" value="<?php _e('Skip question', 'wp-pro-quiz'); ?> " class="wpProQuiz_button wpProQuiz_QuestionButton" style="float: left; margin-right: 10px !important;" > <?php } ?> <input type="button" name="back" value="<?php _e('Back', 'wp-pro-quiz'); ?> " class="wpProQuiz_button wpProQuiz_QuestionButton" style="float: left !important; margin-right: 10px !important; display: none;"> <?php if ($question->isTipEnabled()) { ?> <input type="button" name="tip" value="<?php _e('Hint', 'wp-pro-quiz'); ?> " class="wpProQuiz_button wpProQuiz_QuestionButton wpProQuiz_TipButton" style="float: left !important; display: inline-block; margin-right: 10px !important;"> <?php } ?> <input type="button" name="check" value="<?php _e('Check', 'wp-pro-quiz'); ?> " class="wpProQuiz_button wpProQuiz_QuestionButton" style="float: right !important; margin-right: 10px !important; display: none;"> <input type="button" name="next" value="<?php _e('Next', 'wp-pro-quiz'); ?> " class="wpProQuiz_button wpProQuiz_QuestionButton" style="float: right; display: none;" > <div style="clear: both;"></div> <?php if ($this->quiz->getQuizModus() == WpProQuiz_Model_Quiz::QUIZ_MODUS_SINGLE) { ?> <div style="margin-bottom: 20px;"></div> <?php } ?> </li> <?php } ?> </ol> <?php if ($this->quiz->getQuizModus() == WpProQuiz_Model_Quiz::QUIZ_MODUS_SINGLE) { ?> <div> <input type="button" name="wpProQuiz_pageLeft" data-text="<?php echo esc_attr(__('Page %d', 'wp-pro-quiz')); ?> " style="float: left; display: none;" class="wpProQuiz_button wpProQuiz_QuestionButton"> <input type="button" name="wpProQuiz_pageRight" data-text="<?php echo esc_attr(__('Page %d', 'wp-pro-quiz')); ?> " style="float: right; display: none;" class="wpProQuiz_button wpProQuiz_QuestionButton"> <?php if ($this->quiz->isShowReviewQuestion() && !$this->quiz->isQuizSummaryHide()) { ?> <input type="button" name="checkSingle" value="<?php echo $this->_buttonNames['quiz_summary']; ?> " class="wpProQuiz_button wpProQuiz_QuestionButton" style="float: right;" > <?php } else { ?> <input type="button" name="checkSingle" value="<?php echo $this->_buttonNames['finish_quiz']; ?> " class="wpProQuiz_button wpProQuiz_QuestionButton" style="float: right;"> <?php } ?> <div style="clear: both;"></div> </div> <?php } ?> </div> <?php return array('globalPoints' => $globalPoints, 'json' => $json, 'catPoints' => $catPoints); }
private function handleAddInToplist(WpProQuiz_Model_Quiz $quiz) { if (!wp_verify_nonce($this->_post['token'], 'wpProQuiz_toplist')) { return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true); } if (!isset($this->_post['points']) || !isset($this->_post['totalPoints'])) { return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true); } $quizId = $quiz->getId(); $userId = get_current_user_id(); $points = (int) $this->_post['points']; $totalPoints = (int) $this->_post['totalPoints']; $name = !empty($this->_post['name']) ? trim($this->_post['name']) : ''; $email = !empty($this->_post['email']) ? trim($this->_post['email']) : ''; $ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP); $captchaAnswer = !empty($this->_post['captcha']) ? trim($this->_post['captcha']) : ''; $prefix = !empty($this->_post['prefix']) ? trim($this->_post['prefix']) : ''; $quizMapper = new WpProQuiz_Model_QuizMapper(); $toplistMapper = new WpProQuiz_Model_ToplistMapper(); if ($quiz == null || $quiz->getId() == 0 || !$quiz->isToplistActivated()) { return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true); } if (!$this->preCheck($quiz->getToplistDataAddPermissions(), $userId)) { return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true); } $numPoints = $quizMapper->sumQuestionPoints($quizId); if ($totalPoints > $numPoints || $points > $numPoints) { return array('text' => __('An error has occurred.', 'wp-pro-quiz'), 'clear' => true); } $clearTime = null; if ($quiz->isToplistDataAddMultiple()) { $clearTime = $quiz->getToplistDataAddBlock() * 60; } if ($userId > 0) { if ($toplistMapper->countUser($quizId, $userId, $clearTime)) { return array('text' => __('You can not enter again.', 'wp-pro-quiz'), 'clear' => true); } $user = wp_get_current_user(); $email = $user->user_email; $name = $user->display_name; } else { if ($toplistMapper->countFree($quizId, $name, $email, $ip, $clearTime)) { return array('text' => __('You can not enter again.', 'wp-pro-quiz'), 'clear' => true); } if (empty($name) || empty($email) || filter_var($email, FILTER_VALIDATE_EMAIL) === false) { return array('text' => __('No name or e-mail entered.', 'wp-pro-quiz'), 'clear' => false); } if (strlen($name) > 15) { return array('text' => __('Your name can not exceed 15 characters.', 'wp-pro-quiz'), 'clear' => false); } if ($quiz->isToplistDataCaptcha()) { $captcha = WpProQuiz_Helper_Captcha::getInstance(); if ($captcha->isSupported()) { if (!$captcha->check($prefix, $captchaAnswer)) { return array('text' => __('You entered wrong captcha code.', 'wp-pro-quiz'), 'clear' => false); } } } } $toplist = new WpProQuiz_Model_Toplist(); $toplist->setQuizId($quizId)->setUserId($userId)->setDate(time())->setName($name)->setEmail($email)->setPoints($points)->setResult(round($points / $totalPoints * 100, 2))->setIp($ip); $toplistMapper->save($toplist); return true; }
/** * @param WpProQuiz_Model_Quiz $quiz * @param $data * @return array|null */ private function makeFormData($quiz, $data) { if (!$quiz->isFormActivated() || empty($data)) { return null; } $formMapper = new WpProQuiz_Model_FormMapper(); $forms = $formMapper->fetch($quiz->getId()); if (empty($forms)) { return null; } $formArray = array(); foreach ($forms as $form) { if ($form->getType() != WpProQuiz_Model_Form::FORM_TYPE_DATE) { $str = isset($data[$form->getFormId()]) ? $data[$form->getFormId()] : ''; if (!WpProQuiz_Helper_Form::valid($form, $str)) { return null; } $formArray[$form->getFormId()] = trim($str); } else { $date = isset($data[$form->getFormId()]) ? $data[$form->getFormId()] : array(); $dateStr = WpProQuiz_Helper_Form::validData($form, $date); if ($dateStr === null) { return null; } $formArray[$form->getFormId()] = $dateStr; } } return $formArray; }
private function createQuizModel($xml) { $model = new WpProQuiz_Model_Quiz(); $model->setName(trim($xml->title)); $model->setText(trim($xml->text)); $model->setTitleHidden($xml->title->attributes()->titleHidden == 'true'); $model->setQuestionRandom($xml->questionRandom == 'true'); $model->setAnswerRandom($xml->answerRandom == 'true'); $model->setTimeLimit($xml->timeLimit); $model->setResultText($xml->resultText); $model->setResultGradeEnabled($xml->resultText); $model->setCategoryName(trim($xml->category)); if (isset($xml->resultText)) { $attr = $xml->resultText->attributes(); if ($attr !== null) { $model->setResultGradeEnabled($attr->gradeEnabled == 'true'); if ($model->isResultGradeEnabled()) { $resultArray = array('text' => array(), 'prozent' => array()); foreach ($xml->resultText->text as $result) { $resultArray['text'][] = trim((string) $result); $resultArray['prozent'][] = $result->attributes() === null ? 0 : (int) $result->attributes()->prozent; } $model->setResultText($resultArray); } else { $model->setResultText(trim((string) $xml->resultText)); } } } $model->setShowPoints($xml->showPoints == 'true'); $model->setBtnRestartQuizHidden($xml->btnRestartQuizHidden == 'true'); $model->setBtnViewQuestionHidden($xml->btnViewQuestionHidden == 'true'); $model->setNumberedAnswer($xml->numberedAnswer == 'true'); $model->setHideAnswerMessageBox($xml->hideAnswerMessageBox == 'true'); $model->setDisabledAnswerMark($xml->disabledAnswerMark == 'true'); if (isset($xml->statistic)) { $attr = $xml->statistic->attributes(); if ($attr !== null) { $model->setStatisticsOn($attr->activated == 'true'); $model->setStatisticsIpLock($attr->ipLock); } } if (isset($xml->quizRunOnce)) { $model->setQuizRunOnce($xml->quizRunOnce == 'true'); $attr = $xml->quizRunOnce->attributes(); if ($attr !== null) { $model->setQuizRunOnceCookie($attr->cookie == 'true'); $model->setQuizRunOnceType($attr->type); $model->setQuizRunOnceTime($attr->time); } } if (isset($xml->showMaxQuestion)) { $model->setShowMaxQuestion($xml->showMaxQuestion == 'true'); $attr = $xml->showMaxQuestion->attributes(); if ($attr !== null) { $model->setShowMaxQuestionValue($attr->showMaxQuestionValue); $model->setShowMaxQuestionPercent($attr->showMaxQuestionPercent == 'true'); } } $model->setEndOnFirstIncorrect($xml->endOnFirstIncorrect == 'true'); if (isset($xml->toplist)) { $model->setToplistActivated($xml->toplist->attributes()->activated == 'true'); $model->setToplistDataAddPermissions($xml->toplist->toplistDataAddPermissions); $model->setToplistDataSort($xml->toplist->toplistDataSort); $model->setToplistDataAddMultiple($xml->toplist->toplistDataAddMultiple == 'true'); $model->setToplistDataAddBlock($xml->toplist->toplistDataAddBlock); $model->setToplistDataShowLimit($xml->toplist->toplistDataShowLimit); $model->setToplistDataShowIn($xml->toplist->toplistDataShowIn); $model->setToplistDataCaptcha($xml->toplist->toplistDataCaptcha == 'true'); $model->setToplistDataAddAutomatic($xml->toplist->toplistDataAddAutomatic == 'true'); } $model->setShowAverageResult($xml->showAverageResult == 'true'); $model->setPrerequisite($xml->prerequisite == 'true'); $model->setQuizModus($xml->quizModus); $model->setShowReviewQuestion($xml->showReviewQuestion == 'true'); $model->setQuizSummaryHide($xml->quizSummaryHide == 'true'); $model->setSkipQuestionDisabled($xml->skipQuestionDisabled == 'true'); $model->setEmailNotification($xml->emailNotification); $model->setUserEmailNotification($xml->userEmailNotification == 'true'); $model->setShowCategoryScore($xml->showCategoryScore == 'true'); $model->setHideResultCorrectQuestion($xml->hideResultCorrectQuestion == 'true'); $model->setHideResultQuizTime($xml->hideResultQuizTime == 'true'); $model->setHideResultPoints($xml->hideResultPoints == 'true'); $model->setAutostart($xml->autostart == 'true'); $model->setForcingQuestionSolve($xml->forcingQuestionSolve == 'true'); $model->setHideQuestionPositionOverview($xml->hideQuestionPositionOverview == 'true'); $model->setHideQuestionNumbering($xml->hideQuestionNumbering == 'true'); //0.27 $model->setStartOnlyRegisteredUser($xml->startOnlyRegisteredUser == 'true'); $model->setSortCategories($xml->sortCategories == 'true'); $model->setShowCategory($xml->showCategory == 'true'); if (isset($xml->quizModus)) { $attr = $xml->quizModus->attributes(); if ($attr !== null) { $model->setQuestionsPerPage($attr->questionsPerPage); } } if (isset($xml->forms)) { $attr = $xml->forms->attributes(); $model->setFormActivated($attr->activated == 'true'); $model->setFormShowPosition($attr->position); } //0.29 if (isset($xml->adminEmail)) { $adminEmail = new WpProQuiz_Model_Email(); $adminEmail->setTo($xml->adminEmail->to); $adminEmail->setFrom($xml->adminEmail->form); $adminEmail->setSubject($xml->adminEmail->subject); $adminEmail->setHtml($xml->adminEmail->html == 'true'); $adminEmail->setMessage($xml->adminEmail->message); $model->setAdminEmail($adminEmail); } if (isset($xml->userEmail)) { $userEmail = new WpProQuiz_Model_Email(); $userEmail->setTo($xml->userEmail->to); $userEmail->setToUser($xml->userEmail->toUser == 'true'); $userEmail->setToForm($xml->userEmail->toForm == 'true'); $userEmail->setFrom($xml->userEmail->form); $userEmail->setSubject($xml->userEmail->subject); $userEmail->setHtml($xml->userEmail->html == 'true'); $userEmail->setMessage($xml->userEmail->message); $model->setUserEmail($userEmail); } //Check if ($model->getName() == '') { return null; } if ($model->getText() == '') { return null; } return $model; }
private function userEmailOption() { /** @var WpProQuiz_Model_Email **/ $email = $this->quiz->getUserEmail(); $email = $email === null ? WpProQuiz_Model_Email::getDefault(false) : $email; $to = $email->getTo(); ?> <div class="postbox" id="userEmailSettings"> <h3 class="hndle"><?php _e('User e-mail settings', 'wp-pro-quiz'); ?> </h3> <div class="inside"> <table class="form-table"> <tbody> <tr> <th scope="row"> <?php _e('User e-mail notification', 'wp-pro-quiz'); ?> </th> <td> <fieldset> <legend class="screen-reader-text"> <span><?php _e('User e-mail notification', 'wp-pro-quiz'); ?> </span> </legend> <label> <input type="checkbox" name="userEmailNotification" value="1" <?php $this->checked($this->quiz->isUserEmailNotification()); ?> > <?php _e('Activate', 'wp-pro-quiz'); ?> </label> <p class="description"> <?php _e('If you enable this option, an email is sent with his quiz result to the user.', 'wp-pro-quiz'); ?> </p> </fieldset> </td> </tr> <tr> <th scope="row"> <?php _e('To:', 'wp-pro-quiz'); ?> </th> <td> <label> <input type="checkbox" name="userEmail[toUser]" value="1" <?php $this->checked($email->isToUser()); ?> > <?php _e('User Email-Address (only registered users)', 'wp-pro-quiz'); ?> </label><br> <label> <input type="checkbox" name="userEmail[toForm]" value="1" <?php $this->checked($email->isToForm()); ?> > <?php _e('Custom fields', 'wp-pro-quiz'); ?> : <select name="userEmail[to]" class="emailFormVariables" data-default="<?php echo empty($to) && $to != 0 ? -1 : $email->getTo(); ?> "></select> <?php _e('(Type Email)', 'wp-pro-quiz'); ?> </label> </td> </tr> <tr> <th scope="row"> <?php _e('From:', 'wp-pro-quiz'); ?> </th> <td> <label> <input type="text" name="userEmail[from]" value="<?php echo $email->getFrom(); ?> " class="regular-text"> </label> </td> </tr> <tr> <th scope="row"> <?php _e('Subject:', 'wp-pro-quiz'); ?> </th> <td> <label> <input type="text" name="userEmail[subject]" value="<?php echo $email->getSubject(); ?> " class="regular-text"> </label> </td> </tr> <tr> <th scope="row"> <?php _e('HTML', 'wp-pro-quiz'); ?> </th> <td> <label> <input type="checkbox" name="userEmail[html]" value="1" <?php $this->checked($email->isHtml()); ?> > <?php _e('Activate', 'wp-pro-quiz'); ?> </label> </td> </tr> <tr> <th scope="row"> <?php _e('Message body:', 'wp-pro-quiz'); ?> </th> <td> <?php wp_editor($email->getMessage(), 'userEmailEditor', array('textarea_rows' => 20, 'textarea_name' => 'userEmail[message]')); ?> <div style="padding-top: 10px;"> <table style="width: 100%;"> <thead> <tr> <th style="padding: 0;"> <?php _e('Allowed variables', 'wp-pro-quiz'); ?> </th> <th style="padding: 0;"> <?php _e('Custom fields - Variables', 'wp-pro-quiz'); ?> </th> </tr> </thead> <tbody> <tr> <td style="vertical-align: top;"> <ul> <li><span>$userId</span> - <?php _e('User-ID', 'wp-pro-quiz'); ?> </li> <li><span>$username</span> - <?php _e('Username', 'wp-pro-quiz'); ?> </li> <li><span>$quizname</span> - <?php _e('Quiz-Name', 'wp-pro-quiz'); ?> </li> <li><span>$result</span> - <?php _e('Result in precent', 'wp-pro-quiz'); ?> </li> <li><span>$points</span> - <?php _e('Reached points', 'wp-pro-quiz'); ?> </li> <li><span>$ip</span> - <?php _e('IP-address of the user', 'wp-pro-quiz'); ?> </li> <li><span>$categories</span> - <?php _e('Category-Overview', 'wp-pro-quiz'); ?> </li> </ul> </td> <td style="vertical-align: top;"> <ul class="formVariables"></ul> </td> </tr> </tbody> </table> </div> </td> </tr> </tbody> </table> </div> </div> <?php }
private function isPreLockQuiz(WpProQuiz_Model_Quiz $quiz) { $userId = get_current_user_id(); if ($quiz->isQuizRunOnce()) { switch ($quiz->getQuizRunOnceType()) { case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ALL: return true; case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ONLY_USER: return $userId > 0; case WpProQuiz_Model_Quiz::QUIZ_RUN_ONCE_TYPE_ONLY_ANONYM: return $userId == 0; } } return false; }
/** * @param WpProQuiz_Model_Quiz $quiz * @param $result * @param WpProQuiz_Model_Category[] $categories * @param WpProQuiz_Model_Form[] $forms * @param $inputForms */ private function emailNote(WpProQuiz_Model_Quiz $quiz, $result, $categories, $forms, $inputForms) { $user = wp_get_current_user(); $r = array('$userId' => $user->ID, '$username' => $user->display_name, '$quizname' => $quiz->getName(), '$result' => $result['result'] . '%', '$points' => $result['points'], '$ip' => filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP), '$categories' => empty($result['cats']) ? '' : $this->setCategoryOverview($result['cats'], $categories)); if ($quiz->isFormActivated() && $forms !== null) { foreach ($forms as $form) { $value = ''; if ($form->getType() == WpProQuiz_Model_Form::FORM_TYPE_DATE) { if (isset($inputForms[$form->getFormId()])) { $value = $inputForms[$form->getFormId()]['day'] . '-' . $inputForms[$form->getFormId()]['month'] . '-' . $inputForms[$form->getFormId()]['year']; } } else { $value = isset($inputForms[$form->getFormId()]) ? $inputForms[$form->getFormId()] : ''; } $r['$form{' . $form->getSort() . '}'] = esc_html($value); } } if ($user->ID == 0) { $r['$username'] = $r['$ip']; } if ($quiz->isUserEmailNotification()) { $userEmail = $quiz->getUserEmail(); $userAdress = null; if ($userEmail->isToUser() && get_current_user_id() > 0) { $userAdress = $user->user_email; } else { if ($userEmail->isToForm() && $quiz->isFormActivated()) { foreach ($forms as $form) { if ($form->getSort() == $userEmail->getTo()) { if (isset($inputForms[$form->getFormId()])) { $userAdress = $inputForms[$form->getFormId()]; } break; } } } } if (!empty($userAdress) && filter_var($userAdress, FILTER_VALIDATE_EMAIL) !== false) { $msg = str_replace(array_keys($r), $r, $userEmail->getMessage()); $headers = ''; $email = $userEmail->getFrom(); if (!empty($email)) { $headers = 'From: ' . $userEmail->getFrom(); } if ($userEmail->isHtml()) { add_filter('wp_mail_content_type', array($this, 'htmlEmailContent')); } wp_mail($userAdress, $userEmail->getSubject(), $msg, $headers); if ($userEmail->isHtml()) { remove_filter('wp_mail_content_type', array($this, 'htmlEmailContent')); } } } if ($quiz->getEmailNotification() == WpProQuiz_Model_Quiz::QUIZ_EMAIL_NOTE_ALL || get_current_user_id() > 0 && $quiz->getEmailNotification() == WpProQuiz_Model_Quiz::QUIZ_EMAIL_NOTE_REG_USER) { $adminEmail = $quiz->getAdminEmail(); $msg = str_replace(array_keys($r), $r, $adminEmail->getMessage()); $headers = ''; $email = $adminEmail->getFrom(); if (!empty($email)) { $headers = 'From: ' . $adminEmail->getFrom(); } if ($adminEmail->isHtml()) { add_filter('wp_mail_content_type', array($this, 'htmlEmailContent')); } wp_mail($adminEmail->getTo(), $adminEmail->getSubject(), $msg, $headers); if ($adminEmail->isHtml()) { remove_filter('wp_mail_content_type', array($this, 'htmlEmailContent')); } } }