/** * Remove default Sensei wrappers and load * supported wrappers if the current theme is * a theme we have an integration for within core. * * @since 1.9.0 */ private function possibly_load_supported_theme_wrappers() { if (in_array($this->active_theme, $this->themes)) { // setup file and class names $supported_theme_class_file = trailingslashit(Sensei()->plugin_path) . 'includes/theme-integrations/' . $this->active_theme . '.php'; $supported_theme_class_name = 'Sensei_' . ucfirst($this->active_theme); // load the file or exit if there is no file for this theme if (!file_exists($supported_theme_class_file)) { return; } include_once $supported_theme_class_file; include_once 'twentytwelve.php'; //initialize the class or exit if there is no class for this theme if (!class_exists($supported_theme_class_name)) { return; } $supported_theme = new $supported_theme_class_name(); // remove default wrappers remove_action('sensei_before_main_content', array(Sensei()->frontend, 'sensei_output_content_wrapper'), 10); remove_action('sensei_after_main_content', array(Sensei()->frontend, 'sensei_output_content_wrapper_end'), 10); // load the supported theme wrappers add_action('sensei_before_main_content', array($supported_theme, 'wrapper_start'), 10); add_action('sensei_after_main_content', array($supported_theme, 'wrapper_end'), 10); } }
/** * Testing the quiz class to make sure it is loaded * @since 1.8.0 */ public function testClassInstance() { //test if the class exists $this->assertTrue(class_exists('WooThemes_Sensei_Lesson'), 'Sensei Lesson class does not exist'); //test if the global sensei lesson class is loaded $this->assertTrue(isset(Sensei()->lesson), 'Sensei lesson class is not loaded on the global sensei Object'); }
/** * Activate_sensei * * All the activation checks needed to ensure Sensei is ready for use * @since 1.8.0 */ function activate_sensei() { // create the teacher role on activation and ensure that it has all the needed capabilities Sensei()->teacher->create_role(); //Load the Welcome Screen add_action('activated_plugin', array('Sensei_Welcome', 'redirect')); }
/** * trigger function. * * @access public * @param integer $message_id * @return void */ function trigger($message_id = 0) { global $sensei_email_data; $this->message = get_post($message_id); $learner_username = get_post_meta($message_id, '_sender', true); $this->learner = get_user_by('login', $learner_username); $teacher_username = get_post_meta($message_id, '_receiver', true); $this->teacher = get_user_by('login', $teacher_username); $content_type = get_post_meta($message_id, '_posttype', true); $content_id = get_post_meta($message_id, '_post', true); $content_title = get_the_title($content_id); // setup the post type parameter $content_type = get_post_type($content_id); if (!$content_type) { $content_type = ''; } // Construct data array $sensei_email_data = apply_filters('sensei_email_data', array('template' => $this->template, $content_type . '_id' => $content_id, 'heading' => $this->heading, 'teacher_id' => $this->teacher->ID, 'learner_id' => $this->learner->ID, 'learner_name' => $this->learner->display_name, 'message_id' => $message_id, 'message' => $this->message->post_content, 'content_title' => $content_title, 'content_type' => $content_type), $this->template); // Set recipient (teacher) $this->recipient = stripslashes($this->teacher->user_email); // Send mail Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); wp_safe_redirect(esc_url_raw(add_query_arg(array('send' => 'complete')))); exit; }
/** * Testing the version numbers before releasing the plugin. * * The version number in the plugin information block should match the version number specified in the code. */ function testVersionNumber() { // make sure the version number was set on the new sensei instance $this->assertTrue(isset(Sensei()->version), 'The version number is not set on the global Sensei object'); // read the plugin and get the version number //--> use built in wp function // load an instance of the main class and check the version number //--> this should be loaded in global $woothemes_sensei. //test if the lesson object is loaded //$this->assertTrue( false , 'The plugin listings version and the code variable version numbers do not match' ); }
/** * Activate_sensei * * All the activation checks needed to ensure Sensei is ready for use * @since 1.8.0 */ function activate_sensei() { // create the teacher role on activation and ensure that it has all the needed capabilities Sensei()->teacher->create_role(); //Setup all the role capabilities needed Sensei()->updates->add_sensei_caps(); Sensei()->updates->add_editor_caps(); Sensei()->updates->assign_role_caps(); //Load the Welcome Screen add_action('activated_plugin', array('Sensei_Welcome', 'redirect')); }
/** * trigger function. * * @param int $learner_id * @param int $course_id * * @return void */ function trigger($learner_id = 0, $course_id = 0) { global $sensei_email_data; // Get learner user object $this->learner = new WP_User($learner_id); // Get teacher ID and user object $teacher_id = get_post_field('post_author', $course_id, 'raw'); $this->teacher = new WP_User($teacher_id); // Construct data array $sensei_email_data = apply_filters('sensei_email_data', array('template' => $this->template, 'heading' => $this->heading, 'teacher_id' => $teacher_id, 'learner_id' => $learner_id, 'learner_name' => $this->learner->display_name, 'course_id' => $course_id), $this->template); // Set recipient (learner) $this->recipient = stripslashes($this->teacher->user_email); // Send mail Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); }
/** * Rendering the shortcode this class is responsible for. * * @return string $content */ public function render() { if (empty($this->messages_query)) { return ''; } //set the wp_query to the current messages query global $wp_query; $wp_query = $this->messages_query; ob_start(); Sensei()->frontend->sensei_get_template_part('loop', 'message'); $shortcode_output = ob_get_clean(); // set back the global query wp_reset_query(); return $shortcode_output; }
/** * trigger function. * * @access public * @param $teacher_id * @param $course_id * @return void */ function trigger($teacher_id = 0, $course_id = 0) { global $sensei_email_data; $this->teacher = new WP_User($teacher_id); $this->recipient = stripslashes($this->teacher->user_email); $this->subject = __('New course assigned to you', 'woothemes-sensei'); //course edit link $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit'); // Course name $course = get_post($course_id); // Construct data array $sensei_email_data = apply_filters('sensei_email_data', array('template' => $this->template, 'heading' => $this->heading, 'teacher_id' => $teacher_id, 'course_id' => $course_id, 'course_name' => $course->post_title, 'course_edit_link' => $course_edit_link), $this->template); // Send mail Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); }
/** * trigger function. * * @access public * * @param int $user_id * @param int $course_id * * @return void */ function trigger($user_id = 0, $course_id = 0) { global $sensei_email_data; // Get learner user object $this->user = new WP_User($user_id); // Get passed status $passed = __('passed', 'woothemes-sensei'); if (!Sensei_Utils::sensei_user_passed_course($course_id, $user_id)) { $passed = __('failed', 'woothemes-sensei'); } // Construct data array $sensei_email_data = apply_filters('sensei_email_data', array('template' => $this->template, 'heading' => $this->heading, 'user_id' => $user_id, 'course_id' => $course_id, 'passed' => $passed), $this->template); // Set recipient (learner) $this->recipient = stripslashes($this->user->user_email); // Send mail Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); }
/** * This tests Woothemes_Sensei()->quiz->get_question_type */ public function testGetQuestionType() { // doe this method exist on the quiz class? $this->assertTrue(method_exists('WooThemes_Sensei_Quiz', 'submit_answers_for_grading'), 'The method get_question_type does not exist '); // does this method return false for the wrong data? $should_be_false = Sensei()->question->get_question_type(''); $this->assertFalse($should_be_false, 'The method get_question_type should return false for an empty string parameter'); // does this method return false for the wrong data? $should_be_false = Sensei()->question->get_question_type(''); $this->assertFalse($should_be_false, 'The method get_question_type should return false for an empty string parameter'); $should_be_false = Sensei()->question->get_question_type(2000); $this->assertFalse($should_be_false, 'The method get_question_type should return false for an empty string parameter'); // does this method return a string for a valid question id $questions = get_posts('post_type=question'); $should_be_question_type = Sensei()->question->get_question_type($questions[array_rand($questions)]->ID); $sensei_question_types = array_keys(Sensei()->question->question_types()); $this->assertTrue(in_array($should_be_question_type, $sensei_question_types), 'The method get_question_type should return false for an empty string parameter'); }
/** * Rendering the shortcode this class is responsible for. * * @return string $content */ public function render() { if (empty($this->id)) { return __('Please supply a course ID for this shortcode.', 'woothemes-sensei'); } //set the wp_query to the current courses query global $wp_query; $wp_query = $this->course_page_query; if (have_posts()) { the_post(); } else { return __('No posts found.', 'woothemes-sensei'); } ob_start(); Sensei()->frontend->sensei_get_template('content-single-course.php'); $shortcode_output = ob_get_clean(); // set back the global query wp_reset_query(); return $shortcode_output; }
/** * Rendering the shortcode this class is responsible for. * * @return string $content */ public function render() { if (!is_user_logged_in()) { Sensei()->notices->add_notice(__('Please login to view your messages.', 'woothemes-sensei'), 'alert'); } elseif (0 == $this->messages_query->post_count) { Sensei()->notices->add_notice(__('You do not have any messages.', 'woothemes-sensei'), 'alert'); } $messages_disabled_in_settings = !(!isset(Sensei()->settings->settings['messages_disable']) || !Sensei()->settings->settings['messages_disable']); // don't show anything if messages are disable if ($messages_disabled_in_settings) { return ''; } //set the wp_query to the current messages query global $wp_query; $wp_query = $this->messages_query; ob_start(); Sensei()->notices->print_notices(); Sensei_Templates::get_part('loop', 'message'); $messages_html = ob_get_clean(); // set back the global query wp_reset_query(); return $messages_html; }
/** * trigger function. * * @param int $user_id * @param int $quiz_id * @param int $grade * @param int $passmark * * @return void */ function trigger($user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0) { global $sensei_email_data; // Get learner user object $this->user = new WP_User($user_id); // Get passed flag $passed = __('failed', 'woothemes-sensei'); if ($grade >= $passmark) { $passed = __('passed', 'woothemes-sensei'); } // Get grade tye (auto/manual) $grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); if ('auto' == $grade_type) { $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have completed a quiz', 'woothemes-sensei'), get_bloginfo('name')), $this->template); $this->heading = apply_filters('sensei_email_heading', __('You have completed a quiz', 'woothemes-sensei'), $this->template); } $lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true); // Construct data array $sensei_email_data = apply_filters('sensei_email_data', array('template' => $this->template, 'heading' => $this->heading, 'user_id' => $user_id, 'user_name' => stripslashes($this->user->display_name), 'lesson_id' => $lesson_id, 'quiz_id' => $quiz_id, 'grade' => $grade, 'passmark' => $passmark, 'passed' => $passed, 'grade_type' => $grade_type), $this->template); // Set recipient (learner) $this->recipient = stripslashes($this->user->user_email); // Send mail Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); }
// Get User Meta get_currentuserinfo(); // exit if no lessons exist if (!($total_lessons > 0)) { return; } $html .= '<section class="course-lessons">'; $html .= '<header>'; $html .= '<h2>' . apply_filters('sensei_lessons_text', __('Lessons', 'woothemes-sensei')) . '</h2>'; $html .= '</header>'; $lesson_count = 1; $lessons_completed = count(Sensei()->course->get_completed_lesson_ids($post->ID, $current_user->ID)); $show_lesson_numbers = false; foreach ($course_lessons as $lesson_item) { //skip lesson that are already in the modules if (false != Sensei()->modules->get_lesson_module($lesson_item->ID)) { continue; } $single_lesson_complete = false; $post_classes = array('course', 'post'); $user_lesson_status = false; if (is_user_logged_in()) { // Check if Lesson is complete $single_lesson_complete = WooThemes_Sensei_Utils::user_completed_lesson($lesson_item->ID, $current_user->ID); if ($single_lesson_complete) { $post_classes[] = 'lesson-completed'; } // End If Statement } // End If Statement // Get Lesson data
/** * Display output to the admin view * * This view is shown when grading a quiz for a single user in admin under grading * * @since 1.3.0 * @return html */ public function display() { // Get data for the user //echo do_shortcode("[i4w_get_contactId]"); //die(); $questions = $this->build_data_array(); global $woothemes_sensei; $count = 0; $graded_count = 0; $user_quiz_grade_total = 0; $quiz_grade_total = 0; $quiz_grade = 0; $lesson_id = $this->lesson_id; $user_id = $this->user_id; ?> <form name="<?php esc_attr_e('quiz_' . $this->quiz_id); ?> " action="" method="post"> <?php wp_nonce_field('sensei_manual_grading', '_wp_sensei_manual_grading_nonce'); ?> <input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e($this->quiz_id); ?> " /> <input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e($this->user_id); ?> " /> <div class="total_grade_display"> <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?> </span> <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?> </span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?> </span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?> </span>%) </div> <div class="buttons"> <input type="submit" value="<?php esc_attr_e(__('Save', 'woothemes-sensei')); ?> " class="grade-button button-primary" title="Saves grades as currently marked on this page" /> <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?> " class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?> " class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> </div> <div class="clear"></div><br/><?php $lesson_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value(array('post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID')); $user_quiz_grade = get_comment_meta($lesson_status_id, 'grade', true); $correct_answers = 0; foreach ($questions as $question) { $question_id = $question->ID; ++$count; $type = false; $type_name = ''; $type = Sensei()->question->get_question_type($question_id); $question_answer_notes = $woothemes_sensei->quiz->get_user_question_feedback($lesson_id, $question_id, $user_id); $question_grade_total = get_post_meta($question_id, '_question_grade', true); if (!$question_grade_total || 0 == intval($question_grade_total)) { $question_grade_total = 1; } $quiz_grade_total += $question_grade_total; $right_answer = get_post_meta($question_id, '_question_right_answer', true); $user_answer_content = $woothemes_sensei->quiz->get_user_question_answer($lesson_id, $question_id, $user_id); $type_name = __('Multiple Choice', 'woothemes-sensei'); $grade_type = 'manual-grade'; switch ($type) { case 'boolean': $type_name = __('True/False', 'woothemes-sensei'); $right_answer = ucfirst($right_answer); $user_answer_content = ucfirst($user_answer_content); $grade_type = 'auto-grade'; break; case 'multiple-choice': $type_name = __('Multiple Choice', 'woothemes-sensei'); $grade_type = 'auto-grade'; break; case 'gap-fill': $type_name = __('Gap Fill', 'woothemes-sensei'); $right_answer_array = explode('||', $right_answer); if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } if (!$user_answer_content) { $user_answer_content = '______'; } $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; $user_answer_content = $gapfill_pre . ' <span class="highlight">' . $user_answer_content . '</span> ' . $gapfill_post; $grade_type = 'auto-grade'; break; case 'multi-line': $type_name = __('Multi Line', 'woothemes-sensei'); $grade_type = 'manual-grade'; break; case 'single-line': $type_name = __('Single Line', 'woothemes-sensei'); $grade_type = 'manual-grade'; break; case 'file-upload': $type_name = __('File Upload', 'woothemes-sensei'); $grade_type = 'manual-grade'; // Get uploaded file if ($user_answer_content) { $attachment_id = $user_answer_content; $answer_media_url = $answer_media_filename = ''; if (0 < intval($attachment_id)) { $answer_media_url = wp_get_attachment_url($attachment_id); $answer_media_filename = basename($answer_media_url); if ($answer_media_url && $answer_media_filename) { $user_answer_content = sprintf(__('Submitted file: %1$s', 'woothemes-sensei'), '<a href="' . esc_url($answer_media_url) . '" target="_blank">' . esc_html($answer_media_filename) . '</a>'); } } } else { $user_answer_content = ''; } break; default: // Nothing break; } $user_answer_content = (array) $user_answer_content; $right_answer = (array) $right_answer; $question_title = sprintf(__('Question %d: ', 'woothemes-sensei'), $count) . $type_name; $graded_class = ''; $user_question_grade = $woothemes_sensei->quiz->get_user_question_grade($lesson_id, $question_id, $user_id); $graded_class = 'ungraded'; if (intval($user_question_grade) > 0) { $graded_class = 'user_right'; ++$correct_answers; $user_quiz_grade_total += $user_question_grade; ++$graded_count; } else { if (!is_string($user_question_grade) && intval($user_question_grade) == 0) { $graded_class = 'user_wrong'; ++$graded_count; } $user_question_grade = 0; } ?> <div class="postbox question_box <?php esc_attr_e($type); ?> <?php esc_attr_e($grade_type); ?> <?php esc_attr_e($graded_class); ?> " id="<?php esc_attr_e('question_' . $question_id . '_box'); ?> "> <div class="handlediv" title="Click to toggle"><br></div> <h3 class="hndle"><span><?php echo $question_title; ?> </span></h3> <div class="inside"> <div class="sensei-grading-actions"> <div class="actions"> <input type="hidden" class="question_id" value="<?php esc_attr_e($question_id); ?> " /> <input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo $question_grade_total; ?> " /> <span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e('question_' . $question_id . '_right_option'); ?> " name="<?php esc_attr_e('question_' . $question_id); ?> " value="right" <?php checked($graded_class, 'user_right', true); ?> /></span> <span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e('question_' . $question_id . '_wrong_option'); ?> " name="<?php esc_attr_e('question_' . $question_id); ?> " value="wrong" <?php checked($graded_class, 'user_wrong', true); ?> /></span> <input type="number" class="question-grade" name="<?php esc_attr_e('question_' . $question_id . '_grade'); ?> " id="<?php esc_attr_e('question_' . $question_id . '_grade'); ?> " value="<?php esc_attr_e($user_question_grade); ?> " min="0" max="<?php esc_attr_e($question_grade_total); ?> " /> <span class="question-grade-total"><?php echo $question_grade_total; ?> </span> </div> </div> <div class="sensei-grading-answer"> <h4><?php echo apply_filters('sensei_question_title', $question->post_title); ?> </h4> <?php echo apply_filters('the_content', $question->post_content); ?> <p class="user-answer"><?php foreach ($user_answer_content as $_user_answer) { if ('multi-line' == Sensei()->question->get_question_type($question->ID)) { $_user_answer = htmlspecialchars_decode(nl2br(esc_html($_user_answer))); } echo apply_filters('sensei_answer_text', $_user_answer) . "<br>"; } ?> </p> <div class="right-answer"> <h5><?php _e('Correct answer', 'woothemes-sensei'); ?> </h5> <span class="correct-answer"><?php foreach ($right_answer as $_right_answer) { echo apply_filters('sensei_answer_text', $_right_answer) . "<br>"; } ?> </span> </div> <div class="answer-notes"> <h5><?php _e('Grading Notes', 'woothemes-sensei'); ?> </h5> <textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e($question_id); ?> ]" placeholder="<?php _e('Add notes here...', 'woothemes-sensei'); ?> "><?php echo $question_answer_notes; ?> </textarea> </div> </div> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <div> <?php //floyd code to get the note history $historynotes = get_user_meta($_GET['user'], '_grading_notes_history', true); $historyanswers = get_user_meta($_GET['user'], '_grading_answer_history', true); //echo "<pre>"; //echo $question_id." ".$lesson_id; //print_r($historyanswers); //echo "</pre>"; if (is_array($historynotes)) { //print_r($historynotes[$question_id]); if (array_key_exists($question_id, $historynotes) || isset($historynotes[$question_id])) { echo "<table class='table striped'>"; echo "<tr><th colspan='3'>Question History</th></tr>"; echo "<tr>"; echo "<th>DATE</th>"; echo "<th>Answer</th>"; echo "<th>Notes</th>"; echo "</tr>"; foreach ($historynotes[$question_id] as $dateTime => $noteentry) { echo "<tr>"; echo "<td>" . $dateTime . "</td>"; echo "<td>" . $historyanswers[$question_id][$dateTime] . "</td>"; echo "<td>" . $noteentry . "</td>"; echo "</tr>"; } echo "</table>"; } } ?> </div> </div> </div><?php } $quiz_grade = intval($user_quiz_grade); $all_graded = 'no'; if (intval($count) == intval($graded_count)) { $all_graded = 'yes'; } ?> <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e($user_quiz_grade_total); ?> " /> <input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e($count); ?> " /> <input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e($quiz_grade_total); ?> " /> <input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e($graded_count); ?> " /> <input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e($all_graded); ?> " /> <div class="total_grade_display"> <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?> </span> <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?> </span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?> </span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?> </span>%) </div> <div class="buttons"> <input type="submit" value="<?php esc_attr_e('Save'); ?> " class="grade-button button-primary" title="Saves grades as currently marked on this page" /> <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?> " class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?> " class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> </div> <div class="clear"></div> <script type="text/javascript"> jQuery( window ).load( function() { // Calculate total grade on page load to make sure everything is set up correctly jQuery.fn.autoGrade(); }); </script> </form><?php }
/** * Grading logic specifically for the gap fill questions * * @since 1.9.0 * @param $question_id * @param $user_answer * * @return bool | int false or the grade given to the user answer */ public static function grade_gap_fill_question($question_id, $user_answer) { $right_answer = get_post_meta($question_id, '_question_right_answer', true); $gapfill_array = explode('||', $right_answer); if (0 == get_magic_quotes_gpc()) { // deprecated from PHP 5.4 but we still support PHP 5.2 $user_answer = wp_unslash($user_answer); } /** * case sensitive grading filter * * alter the value simply use this code in your plugin or the themes functions.php * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' ); * * @param bool $do_case_sensitive_comparison default false. * * @since 1.9.0 */ $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false); if ($do_case_sensitive_comparison) { // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer if (trim($gapfill_array[1]) == trim($user_answer)) { return Sensei()->question->get_question_grade($question_id); } else { if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { return Sensei()->question->get_question_grade($question_id); } else { return false; } } else { return false; } } } else { // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer if (trim(strtolower($gapfill_array[1])) == trim(strtolower($user_answer))) { return Sensei()->question->get_question_grade($question_id); } else { if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) { if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) { return Sensei()->question->get_question_grade($question_id); } else { return false; } } else { return false; } } } }
/** * Load in CSS styles for field types where necessary. * @access public * @since 1.0.0 * @return void */ public function enqueue_field_styles() { global $woothemes_sensei; if ($this->has_range) { wp_enqueue_style('woothemes-sensei-settings-ranges', esc_url($woothemes_sensei->plugin_url . 'assets/css/ranges.css'), '', Sensei()->version); } wp_register_style('woothemes-sensei-settings-imageselectors', esc_url($woothemes_sensei->plugin_url . 'assets/css/image-selectors.css'), '', Sensei()->version); if ($this->has_imageselector) { wp_enqueue_style('woothemes-sensei-settings-imageselectors'); } }
/** * On the lesson archive limit the number of words the show up if the access settings are enabled * * @since 1.9.0 * @param $content * @return string */ public static function limit_archive_content($content) { if (is_archive('lesson') && Sensei()->settings->get('access_permission')) { return wp_trim_words($content, $num_words = 30, $more = '…'); } return $content; }
/** * Check if a user has completed a lesson or not * * @uses Sensei() * @param mixed $lesson lesson_id or sensei_lesson_status entry * @param int $user_id * @return boolean */ public static function user_completed_lesson($lesson = 0, $user_id = 0) { if ($lesson) { $lesson_id = 0; if (is_object($lesson)) { $user_lesson_status = $lesson->comment_approved; $lesson_id = $lesson->comment_post_ID; } elseif (!is_numeric($lesson)) { $user_lesson_status = $lesson; } else { if (!$user_id) { $user_id = get_current_user_id(); } // the user is not logged in if (!$user_id > 0) { return false; } $_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id); if ($_user_lesson_status) { $user_lesson_status = $_user_lesson_status->comment_approved; } else { return false; // No status means not complete } $lesson_id = $lesson; } if ('in-progress' != $user_lesson_status) { // Check for Passed or Completed Setting // Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting // $course_completion = Sensei()->settings->settings[ 'course_completion' ]; // if ( 'passed' == $course_completion ) { switch ($user_lesson_status) { case 'complete': case 'graded': case 'passed': return true; break; case 'failed': // This may be 'completed' depending on... if ($lesson_id) { // Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); if ($lesson_quiz_id) { // ...the quiz pass setting $pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true); if (empty($pass_required)) { // We just require the user to have done the quiz, not to have passed return true; } } } return false; break; } } // End If Statement } return false; }
/** * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args * on the sensei settings page. * * The function * * @since 1.8.7 */ public static function install_pages() { // only fire on the settings page if (!isset($_GET['page']) || 'woothemes-sensei-settings' != $_GET['page'] || 1 == get_option('skip_install_sensei_pages')) { return; } // Install/page installer $install_complete = false; // Add pages button $settings_url = ''; if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) { Sensei()->admin->create_pages(); update_option('skip_install_sensei_pages', 1); $install_complete = true; $settings_url = remove_query_arg('install_sensei_pages'); // Skip button } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) { update_option('skip_install_sensei_pages', 1); $install_complete = true; $settings_url = remove_query_arg('skip_install_sensei_pages'); } if ($install_complete) { // refresh the rewrite rules on init update_option('sensei_flush_rewrite_rules', '1'); // Set installed option update_option('sensei_installed', 0); $complete_url = add_query_arg('sensei_install_complete', 'true', $settings_url); wp_redirect($complete_url); } }
/** * Setup the certificate post type, it's admin menu item and the appropriate labels and permissions. * * @access public * @since 1.0.0 * @return void */ public function setup_certificate_templates_post_type() { $args = array('labels' => array('name' => sprintf(_x('%s', 'post type general name', 'sensei-certificates'), 'Certificate Templates'), 'singular_name' => sprintf(_x('%s', 'post type singular name', 'sensei-certificates'), 'Certificate Template'), 'add_new' => sprintf(_x('Add New %s', 'post type add_new', 'sensei-certificates'), 'Certificate Template'), 'add_new_item' => sprintf(__('Add New %s', 'sensei-certificates'), 'Certificate Template'), 'edit_item' => sprintf(__('Edit %s', 'sensei-certificates'), 'Certificate Template'), 'new_item' => sprintf(__('New %s', 'sensei-certificates'), 'Certificate Template'), 'all_items' => sprintf(__('%s', 'sensei-certificates'), 'Certificate Templates'), 'view_item' => sprintf(__('View %s', 'sensei-certificates'), 'Certificate Template'), 'search_items' => sprintf(__('Search %s', 'sensei-certificates'), 'Certificate Templates'), 'not_found' => sprintf(__('No %s found', 'sensei-certificates'), strtolower('Certificate Templates')), 'not_found_in_trash' => sprintf(__('No %s found in Trash', 'sensei-certificates'), strtolower('Certificate Templates')), 'parent_item_colon' => '', 'menu_name' => sprintf(__('%s', 'sensei-certificates'), 'Certificate Templates')), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => 'edit.php?post_type=certificate', 'query_var' => true, 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_certificate_templates_slug', 'certificate-template')), 'with_front' => true, 'feeds' => true, 'pages' => true), 'map_meta_cap' => true, 'has_archive' => false, 'hierarchical' => false, 'menu_icon' => esc_url(Sensei()->plugin_url . 'assets/images/certificate.png'), 'supports' => array('title')); register_post_type('certificate_template', $args); }
/** * Hooked into sensei_course_content_inside_after * * Prints out the course action buttons * * @param $course */ public static function attach_course_buttons($course) { Sensei()->course->the_course_action_buttons($course); }
/** * Loading the quick edit fields defaults. * * This function will localise the default values along with the script that will * add these values to the inputs. * * NOTE: this function runs for each row in the edit column * * @since 1.8.0 * @return void */ public function set_quick_edit_admin_defaults($column_name, $post_id) { if ('lesson-course' != $column_name) { return; } // load the script $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array('jquery'), Sensei()->version, true); // setup the values for all meta fields $data = array(); foreach ($this->meta_fields as $field) { $data[$field] = get_post_meta($post_id, '_' . $field, true); } // add quiz meta fields $quiz_id = Sensei()->lesson->lesson_quizzes($post_id); foreach (Sensei()->quiz->meta_fields as $field) { $data[$field] = get_post_meta($quiz_id, '_' . $field, true); } wp_localize_script('sensei-lesson-quick-edit', 'sensei_quick_edit_' . $post_id, $data); }
/** * Link to the users my messages page * * @since 1.9.0 */ public static function the_my_messages_link() { if (!Sensei()->settings->get('messages_disable')) { ?> <p class="my-messages-link-container"> <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?> " title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?> "> <?php _e('My Messages', 'woothemes-sensei'); ?> </a> </p> <?php } }
/** * The the course result lessons template * * @since 1.9.0 */ function sensei_the_course_results_lessons() { // load backwards compatible template name if it exists in the users theme $located_template = locate_template(Sensei()->template_url . 'course-results/course-lessons.php'); if ($located_template) { Sensei_Templates::get_template('course-results/course-lessons.php'); return; } Sensei_Templates::get_template('course-results/lessons.php'); }
/** * Load the desired component, if a method is available for it. * @param string $component The component to potentially be loaded. * * @since 1.0.0 * @return void */ protected function load_component($instance) { global $current_user; $course_ids = array(); if ('activecourses' == esc_attr($instance['component'])) { $courses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'in-progress'), true); // Need to always return an array, even with only 1 item if (!is_array($courses)) { $courses = array($courses); } foreach ($courses as $course) { $course_ids[] = $course->comment_post_ID; } } elseif ('completedcourses' == esc_attr($instance['component'])) { $courses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'complete'), true); // Need to always return an array, even with only 1 item if (!is_array($courses)) { $courses = array($courses); } foreach ($courses as $course) { $course_ids[] = $course->comment_post_ID; } } // End If Statement $posts_array = array(); // course_query() is buggy, it doesn't honour the 1st arg if includes are provided, so instead slice the includes if (!empty($instance['limit']) && intval($instance['limit']) >= 1 && intval($instance['limit']) < count($course_ids)) { $course_ids = array_slice($course_ids, 0, intval($instance['limit'])); // This does mean the order by is effectively ignored } if (!empty($course_ids)) { $posts_array = Sensei()->course->course_query(intval($instance['limit']), esc_attr($instance['component']), $course_ids); } else { if ('activecourses' == esc_attr($instance['component']) || 'completedcourses' == esc_attr($instance['component'])) { $posts_array = array(); } else { $course_args = array('post_type' => 'course', 'orderby' => 'date', 'order' => 'DESC', 'post_status' => 'publish', 'posts_per_page' => $instance['limit']); $posts_array = get_posts($course_args); } } // End If Statement if (count($posts_array) > 0) { ?> <ul> <?php foreach ($posts_array as $post_item) { $post_id = absint($post_item->ID); $post_title = $post_item->post_title; $user_info = get_userdata(absint($post_item->post_author)); $author_link = get_author_posts_url(absint($post_item->post_author)); $author_display_name = $user_info->display_name; $author_id = $post_item->post_author; ?> <li class="fix"> <?php do_action('sensei_course_image', $post_id); ?> <a href="<?php echo esc_url(get_permalink($post_id)); ?> " title="<?php echo esc_attr($post_title); ?> "><?php echo $post_title; ?> </a> <br /> <?php if (isset(Sensei()->settings->settings['course_author']) && Sensei()->settings->settings['course_author']) { ?> <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?> <a href="<?php echo esc_url($author_link); ?> " title="<?php echo esc_attr($author_display_name); ?> "><?php echo esc_html($author_display_name); ?> </a></span> <br /> <?php } // End If Statement ?> <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($post_id) . ' ' . __('Lessons', 'woothemes-sensei'); ?> </span> <br /> <?php sensei_simple_course_price($post_id); ?> </li> <?php } // End For Loop ?> <?php if ('activecourses' == esc_attr($instance['component']) || 'completedcourses' == esc_attr($instance['component'])) { $my_account_page_id = intval(Sensei()->settings->settings['my_course_page']); echo '<li class="my-account fix"><a href="' . esc_url(get_permalink($my_account_page_id)) . '">' . __('My Courses', 'woothemes-sensei') . ' <span class="meta-nav"></span></a></li>'; } // End If Statement ?> </ul> <?php } else { // No posts returned. This means the user either has no active or no completed courses. if (isset($instance['component'])) { if ('featuredcourses' == $instance['component']) { _e('You have no featured courses.', 'woothemes-sensei'); } elseif ('activecourses' == $instance['component']) { _e('You have no active courses.', 'woothemes-sensei'); } elseif ('completedcourses' == $instance['component']) { _e('You have no completed courses.', 'woothemes-sensei'); } else { _e('You have no courses.', 'woothemes-sensei'); } } // end if compoenetn status instance } // End If Statement }
/** * Returns all lessons for the given module ID * * @since 1.8.0 * * @param $course_id * @param $term_id * @return array $lessons */ public function get_lessons($course_id, $term_id) { $lessons = array(); if (empty($term_id) || empty($course_id)) { return $lessons; } $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course_id), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => 'module', 'field' => 'id', 'terms' => intval($term_id))), 'orderby' => 'menu_order', 'order' => 'ASC', 'suppress_filters' => 0); if (version_compare(Sensei()->version, '1.6.0', '>=')) { $args['meta_key'] = '_order_module_' . intval($term_id); $args['orderby'] = 'meta_value_num date'; } $lessons = new WP_Query($args); return $lessons->posts; }
/** * enqueue_styles function. * * @description Load in CSS styles where necessary. * @access public * @since 1.0.0 * @return void */ public function enqueue_styles() { global $woothemes_sensei; wp_enqueue_style($woothemes_sensei->token . '-admin'); wp_enqueue_style('woothemes-sensei-settings-api', $woothemes_sensei->plugin_url . 'assets/css/settings.css', '', Sensei()->version); }
/** * This functions take answers submitted by a user, extracts ones that is of type file-upload * and then creates and array of test $_FILES * * @param array $test_user_quiz_answers * @return array $files */ public function generate_test_files($test_user_quiz_answers) { $files = array(); //check if there are any file-upload question types and generate the dummy file data foreach ($test_user_quiz_answers as $question_id => $answer) { //Setup the question types $question_type = Sensei()->question->get_question_type($question_id); if ('file-upload' == $question_type) { //setup the sample image file location within the test folders $test_images_directory = dirname(dirname(__FILE__)) . '/images/'; // make a copy of the file intended for upload as // it will be moved to the new location during the upload // and no longer available for the next test $new_test_image_name = 'test-question-' . $question_id . '-greenapple.jpg'; $new_test_image_location = $test_images_directory . $new_test_image_name; copy($test_images_directory . 'greenapple.jpg', $new_test_image_location); $file = array('name' => $new_test_image_name, 'type' => 'image/jpeg', 'tmp_name' => $new_test_image_location, 'error' => 0, 'size' => 4576); // pop the file on top of the car $files['file_upload_' . $question_id] = $file; } } // end for each $test_user_quiz_answers return $files; }