Example #1
0
function parse_quiz($id, $type)
{
    $database = JFactory::getDBO();
    $q = "SELECT * FROM #__guru_config WHERE id = '1' ";
    $database->setQuery($q);
    $configs = $database->loadObject();
    if ($type == "quiz") {
        $q = "SELECT * FROM #__guru_quiz WHERE id = " . $id;
        $database->setQuery($q);
        $result = $database->loadObject();
        $the_media = $result;
        $the_media->type = "quiz";
    } else {
        $q = "SELECT * FROM #__guru_media WHERE id = " . $id;
        $database->setQuery($q);
        $result = $database->loadObject();
        $the_media = $result;
    }
    if ($the_media->type == 'text') {
        $media = $the_media->code;
    }
    if ($the_media->type == 'Article') {
        $media = $the_media->code;
    }
    if ($the_media->type == 'docs') {
        $the_base_link = explode('administrator/', $_SERVER['HTTP_REFERER']);
        $the_base_link = $the_base_link[0];
        $media = 'The selected element is a text file that can\'t have a preview';
        if ($the_media->source == 'local' && (substr($the_media->local, strlen($the_media->local) - 3, 3) == 'txt' || substr($the_media->local, strlen($the_media->local) - 3, 3) == 'pdf') && $the_media->width > 1) {
            $media = '<div class="contentpane">
					<iframe id="blockrandom"
						name="iframe"
						src="' . $the_base_link . '/' . $configs->docsin . '/' . $the_media->local . '"
						width="' . $the_media->width . '"
						height="' . $the_media->height . '"
						scrolling="auto"
						align="top"
						frameborder="2"
						class="wrapper">
						This option will not work correctly. Unfortunately, your browser does not support inline frames.</iframe>
					</div>';
        } elseif ($the_media->source == 'url' && (substr($the_media->url, strlen($the_media->url) - 3, 3) == 'txt' || substr($the_media->url, strlen($the_media->url) - 3, 3) == 'pdf') && $the_media->width > 1) {
            $media = '<div class="contentpane">
					<iframe id="blockrandom"
						name="iframe"
						src="' . $the_media->url . '"
						width="' . $the_media->width . '"
						height="' . $the_media->height . '"
						scrolling="auto"
						align="top"
						frameborder="2"
						class="wrapper">
						This option will not work correctly. Unfortunately, your browser does not support inline frames.</iframe>
					</div>';
        }
        if ($the_media->source == 'local' && $the_media->width == 1) {
            $media = '<br /><a href="' . $the_base_link . '/' . $configs->docsin . '/' . $the_media->local . '" target="_blank">' . $the_media->name . '</a>';
        }
        if ($the_media->source == 'url' && $the_media->width == 0) {
            $media = '<div class="contentpane">
						<iframe id="blockrandom"
						name="iframe"
						src="' . $the_media->url . '"
						width="100%"
						height="600"
						scrolling="auto"
						align="top"
						frameborder="2"
						class="wrapper">
						This option will not work correctly. Unfortunately, your browser does not support inline frames.</iframe>
					</div>';
        }
        if ($the_media->source == 'url' && $the_media->width == 1) {
            $media = '<a href="' . $the_media->url . '" target="_blank">' . $the_media->name . '</a>';
        }
    }
    if ($the_media->type == 'quiz') {
        $the_media->source = $the_media->id;
        $media = '';
        $q = "SELECT * FROM #__guru_quiz WHERE id = " . $the_media->source;
        $database->setQuery($q);
        $result_quiz = $database->loadObject();
        $media .= '<span class="guru_quiz_title">' . $result_quiz->name . '</span>';
        $media .= '<span class="guru_quiz_description">' . $result_quiz->description . '</span>';
        if ($result_quiz->is_final == 1) {
            $sql = "SELECT \tquizzes_ids FROM #__guru_quizzes_final WHERE qid=" . $the_media->source;
            $database->setQuery($sql);
            $database->query();
            $result = $database->loadResult();
            $result_qids = explode(",", trim($result, ","));
            $q = "SELECT * FROM #__guru_questions_v3 WHERE qid IN (" . implode(",", $result_qids) . ") and published=1 order by question_order";
        } else {
            $q = "SELECT * FROM #__guru_questions_v3 WHERE qid =" . $the_media->source . " and published=1 order by question_order";
        }
        $database->setQuery($q);
        $database->query();
        $quiz_questions = $database->loadObjectList();
        $media = $media . '<div id="the_quiz">';
        $question_number = 1;
        for ($i = 0; $i < count($quiz_questions); $i++) {
            $question_answers_number = 0;
            $media_associated_question = json_decode($quiz_questions[$i]->media_ids);
            $media_content = "";
            $result_media = array();
            $q = "SELECT * FROM #__guru_question_answers WHERE question_id = " . intval($quiz_questions[$i]->id) . " ORDER BY id";
            $database->setQuery($q);
            $question_answers = $database->loadObjectList();
            for ($j = 0; $j < count($media_associated_question); $j++) {
                @($media_that_needs_to_be_sent = getMediaFromId($media_associated_question[$j]));
                if (isset($media_that_needs_to_be_sent) && count($media_that_needs_to_be_sent) > 0) {
                    $result_media[] = create_media_using_plugin($media_that_needs_to_be_sent["0"], $configs, '', '', '100px', 100);
                }
            }
            $media .= '<div style="width:100%; clear:both;">';
            $media .= '		<div style="width:50%; float:left;">';
            $media .= $quiz_questions[$i]->question_content . "<br/>" . implode("", $result_media);
            $media .= '		</div>';
            $media .= '<div style="width:50%; float:left;">';
            if ($quiz_questions[$i]->type == "true_false") {
                $media .= ' <div>
									<div class="pull-left">
										<input type="radio" name="truefs_ans" value="0" />
										<span class="lbl"></span>
									</div>
									<div class="pull-left">
										&nbsp;' . JText::_("GURU_QUESTION_OPTION_TRUE") . '&nbsp;&nbsp;
									</div>
									<div class="pull-left">
										<input type="radio" name="truefs_ans" value="1" />
										&nbsp;
										<span class="lbl"></span>
									</div>
									<div class="pull-left">
										&nbsp;' . JText::_("GURU_QUESTION_OPTION_FALSE") . '&nbsp;&nbsp;
									</div>
								</div>';
            } elseif ($quiz_questions[$i]->type == "single") {
                if (isset($question_answers) && count($question_answers) > 0) {
                    foreach ($question_answers as $question_answer) {
                        $media_associated_answers = json_decode($question_answer->media_ids);
                        $media_content = "";
                        $result_media_answers = array();
                        if (isset($media_associated_answers) && count($media_associated_answers) > 0) {
                            foreach ($media_associated_answers as $media_key => $answer_media_id) {
                                $media_that_needs_to_be_sent = getMediaFromId($answer_media_id);
                                if (isset($media_that_needs_to_be_sent) && count($media_that_needs_to_be_sent) > 0) {
                                    $result_media_answers[] = create_media_using_plugin($media_that_needs_to_be_sent["0"], $configs, '', '', '100px', 100);
                                }
                            }
                        }
                        $option_value = '<input type="radio" id="ans' . $question_answer->id . '" name="answers_single" value="' . $question_answer->id . '"/><span class="lbl"></span>&nbsp;' . $question_answer->answer_content_text . '<br/>' . implode("", $result_media_answers) . "<br/>";
                        $media .= $option_value;
                    }
                }
            } elseif ($quiz_questions[$i]->type == "multiple") {
                if (isset($question_answers) && count($question_answers) > 0) {
                    foreach ($question_answers as $question_answer) {
                        $media_associated_answers = json_decode($question_answer->media_ids);
                        $media_content = "";
                        $result_media_answers = array();
                        if (isset($media_associated_answers) && count($media_associated_answers) > 0) {
                            foreach ($media_associated_answers as $media_key => $answer_media_id) {
                                $media_that_needs_to_be_sent = getMediaFromId($answer_media_id);
                                if (isset($media_that_needs_to_be_sent) && count($media_that_needs_to_be_sent) > 0) {
                                    $result_media_answers[] = create_media_using_plugin($media_that_needs_to_be_sent["0"], $configs, '', '', '100px', 100);
                                }
                            }
                        }
                        $option_value = '<input type="checkbox" value="' . $question_answer->id . '"/>&nbsp;' . $question_answer->answer_content_text . '<br/>' . implode("", $result_media_answers) . "<br/>";
                        $media .= $option_value;
                    }
                }
            }
            $media .= '</div>';
            $media .= '</div>';
        }
        $media = $media . '<input type="hidden" value="' . ($question_number - 1) . '" name="question_number" id="question_number" />';
        $media = $media . '<input type="hidden" value="' . $result_quiz->name . '" id="quize_name" name="quize_name"/>';
        //$media = $media.'<br /><div align="left" style="clear:both;"><input type="submit" class ="btn" value="Submit" onclick="get_quiz_result()" /></div>';
        $media = $media . '</div>';
    }
    return $media;
}
Example #2
0
            preg_match('/(?P<domain>[a-z0-9][a-z0-9\\-]{1,63}\\.[a-z\\.]{2,6})$/i', $parsedVideoLink['host'], $matches);
            $domain = $matches['domain'];
            if (!empty($domain)) {
                $provider = explode('.', $domain);
                $providerName = JString::strtolower($provider[0]);
                $libraryPath = JPATH_ROOT . '/components/com_guru/helpers/videos' . '/' . $providerName . '.php';
                require_once $libraryPath;
                $className = 'PTableVideo' . JString::ucfirst($providerName);
                $videoObj = new $className();
                $videoObj->init($the_media->url);
                $video_id = $videoObj->getId();
                $videoPlayer = $videoObj->getViewHTML($video_id, '100%', $the_media->height);
                $media = $videoPlayer;
            }
        } else {
            $media = create_media_using_plugin($the_media, $configs, $awidth, $aheight, $vwidth, $vheight);
        }
    } else {
        $media = $the_media->code;
    }
}
if ($the_media->type == 'quiz' || $the_media->type == 'docs') {
    $media = parse_quiz($the_media->id, $the_media->type);
    $media = str_replace('type="submit"', 'type="button"', $media);
    $media = str_replace("type='submit'", "type='button'", $media);
}
if ($the_media->type == 'url') {
    if ($the_media->width == 1) {
        $src = $the_media->url;
        $media = '<a href="' . $src . '" target="_blank">' . $src . '</a>';
    } else {