function parse_audio($id) { $db = JFactory::getDBO(); $helperclass = new guruAdminHelper(); $sql = "SELECT * FROM #__guru_config LIMIT 1"; $db->setQuery($sql); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } $configs = $db->loadObject(); $sql = "SELECT * FROM #__guru_media\r\n\t\t\t\t\tWHERE id = " . $id; $db->setQuery($sql); $the_media = $db->loadObject(); $the_media->code = stripslashes($the_media->code); $no_plugin_for_code = 0; $aheight = 0; $awidth = 0; $vheight = 0; $vwidth = 0; if ($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; } } } $awidth = "200"; $aheight = "20"; if ($the_media->type == 'audio') { if (!isset($layout_id)) { $layout_id = ""; } if ($no_plugin_for_code == 0) { $media = $helperclass->create_media_using_plugin($the_media, $configs, $awidth, $aheight, $vwidth, $vheight, $layout_id); } else { $media = $the_media->code; } } if (!isset($media)) { $media = NULL; } return stripslashes($media); }
$db->setQuery($answer_given_by_user); $db->query(); $answer_given_by_user = $db->loadAssocList("question_idd"); $sql = "select `id` as answer_id from #__guru_question_answers where `question_id`=" . intval($quiz_questions[$i]->id) . " and correct_answer=1"; $db->setQuery($sql); $db->query(); $answers_right = $db->loadAssocList("answer_id"); $css_validate_class = "question-false"; $validate_answer = guruAdminModelguruTask::validateAnswer($answers_right, $answer_given_by_user[$quiz_questions[$i]->id]); if ($validate_answer) { $css_validate_class = "question-true"; } for ($j = 0; $j < count($media_associated_question); $j++) { @($media_that_needs_to_be_sent = guruAdminModelguruTask::getMediaFromId($media_associated_question[$j])); if (isset($media_that_needs_to_be_sent) && count($media_that_needs_to_be_sent) > 0) { $result_media[] = $helperclass->create_media_using_plugin($media_that_needs_to_be_sent["0"], $configs, '', '', '100px', 100); } } $quiz_form_content .= '<div class="row-fluid">'; $quiz_form_content .= ' <div class="span12">'; $quiz_form_content .= ' <div class="span5 pull-left clearfix ' . $css_validate_class . '">'; $quiz_form_content .= $quiz_questions[$i]->question_content . "<br/>" . implode("", $result_media); $quiz_form_content .= ' </div>'; $quiz_form_content .= '<div class="span6 pull-left clearfix">'; if ($quiz_questions[$i]->type == "true_false") { $quiz_form_content .= '<div>'; foreach ($question_answers as $question_answer) { if (isset($answer_given_by_user[$question_answer->question_id]["answers_given"]) && $answer_given_by_user[$question_answer->question_id]["answers_given"] == $question_answer->id) { $checked = 'checked="checked"'; } else { $checked = '';
function parse_media($media) { $db = JFactory::getDBO(); $configs = $this->getConfig(); $no_plugin_for_code = 0; $aheight = 0; $awidth = 0; $vheight = 0; $vwidth = 0; //start video if ($media->type == 'video') { if ($media->source == 'url' || $media->source == 'local') { if ($media->width == 0 || $media->height == 0) { $media->width = 300; $media->height = 400; } } elseif ($media->source == 'code') { if ($media->width == 0 || $media->height == 0) { //parse the code to get the width and height $begin_tag = strpos($media->code, 'width="'); if ($begin_tag !== false) { $remaining_code = substr($media->code, $begin_tag + 7, strlen($media->code)); $end_tag = strpos($remaining_code, '"'); $media->width = substr($remaining_code, 0, $end_tag); $begin_tag = strpos($media->code, 'height="'); if ($begin_tag !== false) { $remaining_code = substr($media->code, $begin_tag + 8, strlen($media->code)); $end_tag = strpos($remaining_code, '"'); $media->height = substr($remaining_code, 0, $end_tag); $no_plugin_for_code = 1; } else { $media->height = 300; $media->width = 400; } } else { $media->height = 300; $media->width = 400; } } else { $replace_with = 'width="' . $media->width . '"'; $media->code = preg_replace('#width="[0-9]+"#', $replace_with, $media->code); $replace_with = 'height="' . $media->height . '"'; $media->code = preg_replace('#height="[0-9]+"#', $replace_with, $media->code); $replace_with = 'name="width" value="' . $media->width . '"'; $media->code = preg_replace('#name="width" value="[0-9]+"#', $replace_with, $media->code); $replace_with = 'name="height" value="' . $media->height . '"'; $media->code = preg_replace('#name="height" value="[0-9]+"#', $replace_with, $media->code); } } $vwidth = $media->width; $vheight = $media->height; } elseif ($media->type == 'audio') { if ($media->source == 'url' || $media->source == 'local') { if ($media->width == 0 || $media->height == 0) { $media->width = 20; $media->height = 300; } } elseif ($media->source == 'code') { if ($media->width == 0 || $media->height == 0) { $begin_tag = strpos($media->code, 'width="'); if ($begin_tag !== false) { $remaining_code = substr($media->code, $begin_tag + 7, strlen($media->code)); $end_tag = strpos($remaining_code, '"'); $media->width = substr($remaining_code, 0, $end_tag); $begin_tag = strpos($media->code, 'height="'); if ($begin_tag !== false) { $remaining_code = substr($media->code, $begin_tag + 8, strlen($media->code)); $end_tag = strpos($remaining_code, '"'); $media->height = substr($remaining_code, 0, $end_tag); $no_plugin_for_code = 1; } else { $media->height = 20; $media->width = 300; } } else { $media->height = 20; $media->width = 300; } } else { $replace_with = 'width="' . $media->width . '"'; $media->code = preg_replace('#width="[0-9]+"#', $replace_with, $media->code); $replace_with = 'height="' . $media->height . '"'; $media->code = preg_replace('#height="[0-9]+"#', $replace_with, $media->code); } } $awidth = $media->width; $aheight = $media->height; } $parts = explode(".", $media->local); $extension = strtolower($parts[count($parts) - 1]); if ($media->type == 'video' || $media->type == 'audio') { if ($media->type == 'video' && $extension == "avi") { $media->code = '<object id="MediaPlayer1" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" type="application/x-oleobject" width="' . $media->width . '" height="' . $media->height . '"> <param name="fileName" value="' . JURI::root() . $configs->videoin . "/" . $media->local . '"> <param name="animationatStart" value="true"> <param name="transparentatStart" value="true"> <param name="autoStart" value="true"> <param name="showControls" value="true"> <param name="Volume" value="10"> <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="' . JURI::root() . $configs->videoin . "/" . $media->local . '" name="MediaPlayer1" width="' . $media->width . '" height="' . $media->height . '" autostart="1" showcontrols="1" volume="10"> </object>'; } elseif ($no_plugin_for_code == 0) { if ($media->type == 'video' && $media->source == "url") { require_once JPATH_ROOT . '/components/com_guru/helpers/videos/helper.php'; $parsedVideoLink = parse_url($media->url); 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]); if ($providerName == "youtu") { $providerName = "youtube"; } $libraryPath = JPATH_ROOT . '/components/com_guru/helpers/videos' . '/' . $providerName . '.php'; require_once $libraryPath; $className = 'PTableVideo' . JString::ucfirst($providerName); $videoObj = new $className(); $videoObj->init($media->url); $video_id = $videoObj->getId(); $videoPlayer = $videoObj->getViewHTML($video_id, $media->width, $media->height); $media->code = $videoPlayer; } } else { $helper = new guruAdminHelper(); $media->code = $helper->create_media_using_plugin($media, $configs, $awidth, $aheight, $vwidth, $vheight); } } } //end audio //start docs type if ($media->type == 'docs') { $media->code = 'The selected element is a text file that can\'t have a preview'; if ($media->source == 'local' && (substr($media->local, strlen($media->local) - 3, 3) == 'txt' || substr($media->local, strlen($media->local) - 3, 3) == 'pdf') && $media->width > 1) { $media->code = '<div class="contentpane"> <iframe id="blockrandom" name="iframe" src="' . JURI::root() . $configs->docsin . '/' . $media->local . '" width="' . $media->width . '" height="' . $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 ($media->show_instruction == 2) { $media->code = stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } elseif ($media->show_instruction == 1) { $media->code = stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br /><div style="text-align:center"><i>' . $media->instructions . '</i></div>'; } elseif ($media->show_instruction == 0) { $media->code = '<div style="text-align:center"><i>' . $media->instructions . '</i></div>' . stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } return $media->code; } elseif ($media->source == 'local' && $media->width == 1) { $media->code = '<br /><a href="' . JURI::root() . $configs->docsin . '/' . $media->local . '" target="_blank">' . $media->name . '</a>'; if ($media->show_instruction == 2) { $media->code = stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } elseif ($media->show_instruction == 1) { $media->code = stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br /><div style="text-align:center"><i>' . $media->instructions . '</i></div>'; } elseif ($media->show_instruction == 0) { $media->code = '<div style="text-align:center"><i>' . $media->instructions . '</i></div>' . stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } return $media->code; } elseif ($media->source == 'url' && $media->width == 0) { $media->code = '<div class="contentpane"> <iframe id="blockrandom" name="iframe" src="' . $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>'; } else { if ($media->source == 'url' && $media->width == 1) { $media->code = '<a href="' . $media->url . '" target="_blank">' . $media->name . '</a>'; } } } //end doc //start url if ($media->type == 'url') { if ($media->width > 1) { $media->code = '<div class="contentpane"> <iframe id="blockrandom" name="iframe" src="' . $media->url . '" width="800px" height="600px" 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 ($media->show_instruction == 2) { $media->code = stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } elseif ($media->show_instruction == 1) { $media->code = stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br /><div style="text-align:center"><i>' . $media->instructions . '</i></div>'; } elseif ($media->show_instruction == 0) { $media->code = '<div style="text-align:center"><i>' . $media->instructions . '</i></div>' . stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } return $media->code; } else { $media->code = '<a href="' . $media->url . '" target="_blank">' . $media->url . '</a>'; } } //end url //start image if ($media->type == 'image') { $media->code = '<img width="' . $media->width . '" height="' . $media->height . '" src="' . JURI::root() . $configs->imagesin . '/media/thumbs/' . $media->local . '" />'; } //end image //start text if ($media->type == 'text') { $media->code = $media->code; } //end text //start docs type if ($media->type == 'file') { //var_dump($media); $media->code = JText::_('GURU_NO_PREVIEW'); $x = filesize(JPATH_SITE . DS . $configs->filesin . '/' . $media->local) / (1024 * 1024); $x = number_format($x, 2, '.', ''); if ($media->source == 'local' && (substr($media->local, strlen($media->local) - 3, 3) == 'zip' || substr($media->local, strlen($media->local) - 3, 3) == 'exe')) { $media->code = '<br /><a href="' . JURI::root() . $configs->filesin . '/' . $media->local . '" target="_blank">' . $media->local . " (" . $x . " Ko)" . '</a>'; //return stripslashes($media->code); if ($media->show_instruction == 2) { $media->code = stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } elseif ($media->show_instruction == 1) { $media->code = stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br /><div style="text-align:center"><i>' . $media->instructions . '</i></div>'; } elseif ($media->show_instruction == 0) { $media->code = '<div style="text-align:center"><i>' . $media->instructions . '</i></div>' . stripslashes($media->code) . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } return $media->code; } else { if ($media->source == 'url') { $media->code = '<a href="' . $media->url . '" target="_blank">' . $media->name . '</a>'; } } } //end doc if ($media->type == 'text') { $media->code = $media->code; } else { if ($media->show_instruction == 2) { $media->code = $media->code . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } elseif ($media->show_instruction == 1) { $media->code = $media->code . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br /><div style="text-align:center"><i>' . $media->instructions . '</i></div>'; } elseif ($media->show_instruction == 0) { $media->code = '<div style="text-align:center"><i>' . $media->instructions . '</i></div>' . $media->code . '<br /><br /><div style="text-align:center"><i>' . $media->name . '</i></div><br />'; } } return stripslashes($media->code); }