Пример #1
0
/**
 * This will scan all the content pages that wordpress outputs for our special code. If the code is found, it will replace the requested quiz.
 */
function watupro_shortcode($attr)
{
    global $wpdb, $post;
    $exam_id = $attr[0];
    $contents = '';
    if (!is_numeric($exam_id)) {
        return $contents;
    }
    watupro_vc_scripts();
    ob_start();
    // select exam
    $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE id=%d", $exam_id));
    if (watupro_intel()) {
        WatuPROIntelligence::conditional_scripts($exam_id);
    }
    watupro_conditional_scripts($exam);
    // passed question ids?
    if (!empty($attr['question_ids'])) {
        $passed_question_ids = $attr['question_ids'];
    }
    // submitting without ajax?
    if (!empty($_POST['no_ajax']) and !empty($exam->no_ajax)) {
        require WATUPRO_PATH . "/show_exam.php";
        $contents = ob_get_clean();
        $contents = apply_filters('watupro_content', $contents);
        return $contents;
    }
    // other cases, show here
    if (empty($_GET['waturl']) or !$exam->shareable_final_screen) {
        // showing the exam
        if ($exam->mode == 'practice' and watupro_intel()) {
            WatuPracticeController::show($exam);
        } else {
            include WATUPRO_PATH . '/show_exam.php';
        }
        $contents = ob_get_contents();
    } else {
        // showing taking results
        $url = @base64_decode($_GET['waturl']);
        list($exam_id, $tid) = explode("|", $url);
        if (!is_numeric($exam_id) or !is_numeric($tid)) {
            return $contents;
        }
        // must check if public URL is allowed
        $taking = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_TAKEN_EXAMS . " WHERE ID=%d", $tid));
        $contents = WatuPRO::cleanup($taking->details, 'web');
        $post->ID = 0;
        $post->comment_status = 'closed';
    }
    ob_end_clean();
    $contents = apply_filters('watupro_content', $contents);
    return $contents;
}