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 = JURI::root(); $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="100%" 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="100%" 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; include_once JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "models" . DS . "gurutask.php"; $quiz_content = guruModelguruTask::parse_media(intval($the_media->id), 12); $media = $quiz_content; } return $media; }
function parse_media($id, $layout_id) { $db = JFactory::getDBO(); $sql = "SELECT * FROM #__guru_config LIMIT 1"; $db->setQuery($sql); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } $configs = $db->loadObject(); if (!isset($media)) { $media = ""; } $default_size = $configs->default_video_size; $default_width = ""; $default_height = ""; if (trim($default_size) != "") { $default_size = explode("x", $default_size); $default_width = $default_size["1"]; $default_height = $default_size["0"]; } if ($layout_id != 15) { $sql = "SELECT * FROM #__guru_media WHERE id = " . $id; $db->setQuery($sql); $db->query(); $the_media = $db->loadObject(); @($the_media->code = stripslashes($the_media->code)); } else { $sql = "SELECT * FROM #__guru_quiz\r\n\t\t\t\t\t\tWHERE id = " . $id; $db->setQuery($sql); $db->query(); $the_media = $db->loadObject(); $the_media->type = "quiz"; $the_media->code = ""; } $no_plugin_for_code = 0; $aheight = 0; $awidth = 0; $vheight = 0; $vwidth = 0; if (@$the_media->type == 'video') { if ($the_media->source == 'url' || $the_media->source == 'local') { if (($the_media->width == 0 || $the_media->height == 0) && $the_media->option_video_size == 1) { $vheight = 300; $vwidth = 400; } elseif ($the_media->width != 0 && $the_media->height != 0 && $the_media->option_video_size == 1) { $vheight = $the_media->height; $vwidth = $the_media->width; } elseif ($the_media->option_video_size == 0) { $vheight = $default_height; $vwidth = $default_width; } } elseif ($the_media->source == 'code') { if (($the_media->width == 0 || $the_media->height == 0) && $the_media->option_video_size == 1) { $begin_tag = strpos($the_media->code, 'width="'); if ($begin_tag !== false) { $remaining_code = substr($the_media->code, $begin_tag + 7, strlen($the_media->code)); $end_tag = strpos($remaining_code, '"'); $vwidth = substr($remaining_code, 0, $end_tag); $begin_tag = strpos($the_media->code, 'height="'); if ($begin_tag !== false) { $remaining_code = substr($the_media->code, $begin_tag + 8, strlen($the_media->code)); $end_tag = strpos($remaining_code, '"'); $vheight = substr($remaining_code, 0, $end_tag); $no_plugin_for_code = 1; } else { $vheight = 300; $vwidth = 400; } } else { $vheight = 300; $vwidth = 400; } } elseif (($the_media->width != 0 || $the_media->height != 0) && $the_media->option_video_size == 1) { $replace_with = 'width="' . $the_media->width . '"'; $the_media->code = preg_replace('#width="[0-9]+"#', $replace_with, $the_media->code); $replace_with = 'height="' . $the_media->height . '"'; $the_media->code = preg_replace('#height="[0-9]+"#', $replace_with, $the_media->code); $replace_with = 'name="width" value="' . $the_media->width . '"'; $the_media->code = preg_replace('#name="width" value="[0-9]+"#', $replace_with, $the_media->code); $replace_with = 'name="height" value="' . $the_media->height . '"'; $the_media->code = preg_replace('#name="height" value="[0-9]+"#', $replace_with, $the_media->code); $vheight = $the_media->height; $vwidth = $the_media->width; } elseif ($the_media->option_video_size == 0) { $replace_with = 'width="' . $default_width . '"'; $the_media->code = preg_replace('#width="[0-9]+"#', $replace_with, $the_media->code); $replace_with = 'height="' . $default_height . '"'; $the_media->code = preg_replace('#height="[0-9]+"#', $replace_with, $the_media->code); $replace_with = 'name="width" value="' . $default_width . '"'; $the_media->code = preg_replace('#value="[0-9]+" name="width"#', $replace_with, $the_media->code); $replace_with = 'name="height" value="' . $default_height . '"'; $the_media->code = preg_replace('#value="[0-9]+" name="height"#', $replace_with, $the_media->code); $replace_with = 'name="width" value="' . $default_width . '"'; $the_media->code = preg_replace('/name="width" value="[0-9]+"/', $replace_with, $the_media->code); $replace_with = 'name="height" value="' . $default_height . '"'; $the_media->code = preg_replace('/name="height" value="[0-9]+"/', $replace_with, $the_media->code); $vheight = $default_height; $vwidth = $default_width; } } } elseif (@$the_media->type == 'audio') { if ($the_media->source == 'url' || $the_media->source == 'local') { if ($the_media->width == 0 || $the_media->height == 0) { $aheight = 20; $awidth = 300; } else { $aheight = $the_media->height; $awidth = $the_media->width; } } elseif ($the_media->source == 'code') { if ($the_media->width == 0 || $the_media->height == 0) { $begin_tag = strpos($the_media->code, 'width="'); if ($begin_tag !== false) { $remaining_code = substr($the_media->code, $begin_tag + 7, strlen($the_media->code)); $end_tag = strpos($remaining_code, '"'); $awidth = substr($remaining_code, 0, $end_tag); $begin_tag = strpos($the_media->code, 'height="'); if ($begin_tag !== false) { $remaining_code = substr($the_media->code, $begin_tag + 8, strlen($the_media->code)); $end_tag = strpos($remaining_code, '"'); $aheight = substr($remaining_code, 0, $end_tag); $no_plugin_for_code = 1; } else { $aheight = 20; $awidth = 300; } } else { $aheight = 20; $awidth = 300; } } else { $replace_with = 'width="' . $the_media->width . '"'; $the_media->code = preg_replace('#width="[0-9]+"#', $replace_with, $the_media->code); $replace_with = 'height="' . $the_media->height . '"'; $the_media->code = preg_replace('#height="[0-9]+"#', $replace_with, $the_media->code); $aheight = $the_media->height; $awidth = $the_media->width; } } } $parts = explode(".", @$the_media->local); $extension = strtolower($parts[count($parts) - 1]); if (@$the_media->type == 'video' || @$the_media->type == 'audio') { if ($the_media->type == 'video' && $extension == "avi") { $media = '<object width="' . $vwidth . '" height="' . $vheight . '" type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" id="MediaPlayer1"> <param value="' . JURI::root() . $configs->videoin . "/" . $the_media->local . '" name="fileName"> <param value="true" name="animationatStart"> <param value="true" name="transparentatStart"> <param value="true" name="autoStart"> <param value="true" name="showControls"> <param value="10" name="Volume"> <param value="false" name="autoplay"> <embed width="' . $vwidth . '" height="' . $vheight . '" type="video/x-msvideo" src="' . JURI::root() . $configs->videoin . "/" . $the_media->local . '" name="plugin"> </object>'; } elseif ($no_plugin_for_code == 0) { $helper = new guruHelper(); $media = $helper->create_media_using_plugin($the_media, $configs, $awidth, $aheight, $vwidth, $vheight); } } if (@$the_media->type == 'docs') { $the_base_link = JURI::root(); $media = JText::_('GURU_NO_PREVIEW'); //$media = JText::_("GURU_TASKS"); 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>'; return stripslashes($media . '<div style="text-align:center"><i>' . $the_media->instructions . '</i></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>'; return stripslashes($media . '<div style="text-align:center"><i>' . $the_media->instructions . '</i></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>'; return stripslashes($media . '<div style="text-align:center"><i>' . $the_media->instructions . '</i></div>'); } 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 == 'url') { $src = $the_media->url; $media = '<a href="' . $src . '" target="_blank">' . $src . '</a>'; } if (@$the_media->type == 'Article') { $media = self::getArticleById($the_media->code); } if (@$the_media->type == 'image') { $img_size = @getimagesize(JPATH_SITE . DS . $configs->imagesin . DS . 'media' . DS . 'thumbs' . $the_media->local); //echo "~~~~".var_dump($img_size)."~~~~"; $img_width = $img_size[0]; $img_height = $img_size[1]; if ($img_width > 0 && $img_height > 0) { $thumb_width = 0; $thumb_height = 0; if ($the_media->width > 0) { $thumb_width = $the_media->width; $thumb_height = $img_height / ($img_width / $the_media->width); } elseif ($the_media->height > 0) { $thumb_height = $the_media->height; $thumb_width = $img_width / ($img_height / $the_media->height); } else { $thumb_height = 200; $thumb_width = $img_width / ($img_height / 200); } $media = '<img width="' . $thumb_width . '" height="' . $thumb_height . '" src="' . JURI::root() . DS . $configs->imagesin . '/media/thumbs' . $the_media->local . '" />'; } if (!isset($media)) { $media = NULL; } } if (@$the_media->type == 'quiz') { $document = JFactory::getDocument(); $document->addStyleSheet(JURI::root() . "components/com_guru/css/quiz.css"); include_once JPATH_SITE . DS . "components" . DS . "com_guru" . DS . "models" . DS . "gurutask.php"; $quiz_content = guruModelguruTask::parse_media(intval($the_media->id), 12); $media = $quiz_content; } if (@$the_media->type == "file") { $media = '<a target="_blank" href="' . JURI::ROOT() . $configs->filesin . '/' . $the_media->local . '">' . $the_media->name . '</a><br/><br/>' . $the_media->instructions; } return stripslashes($media); }
} } } 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 = guruModelguruTask::getMediaFromId($answer_media_id); if (isset($media_that_needs_to_be_sent) && count($media_that_needs_to_be_sent) > 0) { if ($media_that_needs_to_be_sent["0"]->type == "text") { $result_media_answers[] = guruModelguruTask::parse_txt($media_that_needs_to_be_sent["0"]->id); } else { $result_media_answers[] = guruModelguruTask::parse_media($media_that_needs_to_be_sent["0"]->id, 0); } } } } $multiple_ans_given = explode(",", @$answer_given_by_user[$question_answer->question_id]["answers_given"]); $checked = ''; if (in_array($question_answer->id, $multiple_ans_given)) { $checked = 'checked="checked"'; } $option_value = '<input type="checkbox" ' . $checked . ' disabled name="multiple_ans[' . intval($quiz_questions[$i]->id) . '][]" value="' . $question_answer->id . '"/> ' . $question_answer->answer_content_text . '<br/>' . implode("", $result_media_answers) . "<br/>"; $quiz_form_content .= $option_value; } } } elseif ($quiz_questions[$i]->type == "essay") { $essay_exists = TRUE;