/
var
/
www
/
html
/
mogi
/
mod
/
videoaula
/
Upload File
HOME
<?php /** * Private videoaula module utility functions * * @package mod * @subpackage videoaula */ defined('MOODLE_INTERNAL') || die; require_once("$CFG->libdir/filelib.php"); require_once("$CFG->libdir/resourcelib.php"); require_once("$CFG->dirroot/mod/videoaula/lib.php"); /** * File browsing support class */ class videoaula_content_file_info extends file_info_stored { public function get_parent() { if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') { return $this->browser->get_file_info($this->context); } return parent::get_parent(); } public function get_visible_name() { if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') { return $this->topvisiblename; } return parent::get_visible_name(); } } function videoaula_get_editor_options($context) { global $CFG; return array('subdirs'=>1, 'maxbytes'=>$CFG->maxbytes, 'maxfiles'=>-1, 'changeformat'=>1, 'context'=>$context, 'noclean'=>1, 'trusttext'=>0); } /* //VIDEOAULA FIELDS: paidkey, video, file, checkpoints, captions, logo, skin, thumbnails, position, chapters, width, height, subtitle */ function videoaula_build_player($page){ global $CFG; $playertext = get_string('playertext', 'videoaula'); $getSources = videoaula_get_sources($page->video); $getTracks = videaula_get_tracks($page->thumbnails, $page->captions, $page->chapters); $getOnTime = videoaula_build_onTime(); $getOnReady = videoaula_build_onReady($page); $getOnSeek = videoaula_build_onSeek(); $str = <<<player <div id="videoaula-player">$playertext</div> <script type="text/javascript"> $(function(){ var actualSec, actualSecBlock, nextPos, finalPos, block, prevBlock, checkpoints, isFirstSeek = flagScroll = true; jwplayer("videoaula-player") .setup({ flashplayer: "$CFG->wwwroot/jwplayer/jwplayer.flash.swf", playlist:[{ $getSources $getTracks image: "$page->poster", logo:{hide:true} }] }) $getOnReady $getOnSeek $getOnTime; function va_goToSeek(nextBlock){ va_setPrevBlock(); va_setAndPosBlock(nextBlock); va_testAndAnimeBlock(); } function va_setPrevBlock(){ if(typeof(block) != "undefined"){ prevBlock = block; prevBlock.css("background-color","#ffffff"); } } function va_setAndPosBlock(nextBlock){ block = nextBlock; block.css("background-color","#eee"); nextPos = block.position().top-$(".va-fulltext").position().top; } function va_testAndAnimeBlock(){ if((nextPos + block.outerHeight()) > $(".va-fulltext").height() || nextPos < 0){ finalPos = nextPos + $(".va-fulltext").scrollTop(); $(".va-fulltext").animate({scrollTop: finalPos}, 600); } } function va_findAndGoToSeek(event){ var allSecs = $('[data-sec]'); var idx; var tempSec; var nextSec = event.offset; if(allSecs.size() > 0){ for(var x=0; x<allSecs.length; x++){ tempSec = parseInt(allSecs.eq(x).attr('data-sec')); if(tempSec >= nextSec){ idx = (tempSec == nextSec || x == 0)? x : x-1;//pega data-sec correpondente ao seek va_goToSeek(allSecs.eq(idx)); break; } } } } function va_saveCheckpoint(){ var jqxhr = $.ajax({"url":"$CFG->wwwroot/mod/videoaula/setCheckPoint.php?&checkpoint="+actualSec+"&videoaulaid=$page->id","dataType":"text"}) .done(function(data) { if(data == 'erro'){ console.log('Não foi possível registrar o tópico atual.'); }else{ console.log(data); } }) .fail(function() { console.log('Erro no acesso ao servidor para registrar o tópico atual.'); }); } function va_saveTimePosition(){ if(typeof(actualSec) != "undefined"){ $.ajax({ url: "$CFG->wwwroot/mod/videoaula/setStartAt.php", dataType:"text", type: 'POST', async: false, data: { "actualsec": actualSec, "videoaulaid": $page->id } }); } } //botoes de controle if($('[data-sec]').size() > 0 && $(window).width() > 768){ $('.va-fulltext:eq(0)').before('<div class="va-scroll-controls"><button id="va-stop" class="btn"><i class="icon-stop"></i></button><button id="va-go" class="btn"><i class="icon-play"></i></button></div>'); $('#va-stop').click(function(){ flagScroll = false; $('.va-fulltext').stop(); $(this).hide(); $('#va-go').show(); }); $('#va-go').click(function(){ flagScroll = true; $(this).hide(); $('#va-stop').show(); }).hide(); $('[data-sec]').on({ click:function(e){ jwplayer("videoaula-player").seek(parseInt($(e.target).attr('data-sec'))); }, mouseover:function(e){ $(e.target).addClass('va-sec-hover'); }, mouseout:function(e){ $(e.target).removeClass('va-sec-hover'); } }); } $(window).on({beforeunload: va_saveTimePosition}); }); </script> player; return $str; } function videoaula_get_sources($str){ $strSources = ""; $character_mask = " \t\n\r\0\x0B"; if($str != ''){ $str = explode("\n", $str); if(sizeof($str) > 1){ $strSources = 'sources:['; for($i=0; $i<sizeof($str); $i++){ if($str[$i] != ""){ $strSources .= '{'; $str[$i] = explode(",",$str[$i]); $strSources .= 'file:"'.$str[$i][0].'",'; $strSources .= 'label:"'.$str[$i][1].'",'; $str[$i][2] = trim($str[$i][2], $character_mask); if($str[$i][2] == "true"){ $strSources .= 'default:"true"'; } $strSources .= '},'; } } $strSources .= '],'; }else{ $prop = explode(",", $str[0]); $strSources = 'file: "'.$prop[0].'",'; } } return $strSources; } function videaula_get_tracks($strThumbs, $strCaptions, $strChapters){ $strTracks = ""; $character_mask = " \t\n\r\0\x0B"; if(trim($strThumbs, $character_mask) != ""){ $strTracks .= '{file:""'.$strThumbs.'",kind:"thumbnails"},'; } if(trim($strCaptions, $character_mask) != ""){ $strTracks .= '{file:"'.$strCaptions.'",kind:"captions"},'; } if(trim($strChapters, $character_mask) != ""){ $strTracks .= '{file:"'.$strChapters.'",kind:"chapters"},'; } return 'tracks:['.$strTracks.'],'; } function videoaula_build_onTime(){ $strOnTime = <<<points .onTime(function(e){ var sec = parseInt(e.position); var nextBlock; //onTime dispara 10x/sec., por isso faz executar apenas 1x/sec if(sec != actualSec){ actualSec = sec; if(checkpoints.length > 0){ for(var i=0; i<checkpoints.length; i++){ if(sec == parseInt(checkpoints[i])){ $("#flag").fadeIn().delay(1000).fadeOut(); va_saveCheckpoint(); checkpoints.splice(i,1);//retira o checkpoint já salvo break; } } } nextBlock = $('[data-sec="'+actualSec+'"]'); if(nextBlock.size() > 0 && flagScroll && $(window).width() > 768) { va_goToSeek(nextBlock.eq(0)); } } }) points; return $strOnTime; } function videoaula_build_onSeek(){ $strOnSeek = <<<seek .onSeek(function(e){ va_findAndGoToSeek(e); }) seek; return $strOnSeek; } function videoaula_build_onReady($page){ global $USER, $DB; $character_mask = " \t\n\r\0\x0B"; $strSeek = ""; $seek; $strOnReady=""; $strCheckpoints = trim($page->checkpoints, $character_mask); $dbman = $DB->get_manager(); $table = new xmldb_table('videoaula_startat'); if($dbman->table_exists($table)){ $seek = $DB->get_field('videoaula_startat', 'startat', array('userid'=>$USER->id, 'videoaulaid'=>$page->id), $strictness=IGNORE_MISSING); if ($seek != ""){ $strSeek = <<<seek actualSec = $seek; jwplayer("videoaula-player").seek(actualSec); seek; } } if($strCheckpoints != ""){ $table = new xmldb_table('videoaula_checkpoint'); if($dbman->table_exists($table)){ $arr_all_checkpoints = explode(',',$strCheckpoints); $select = 'userid = '.$USER->id.' and videoaulaid = '.$page->id; $arr_sel_checkpoints = $DB->get_fieldset_select('videoaula_checkpoint', 'checkpoint', $select); if(sizeof($arr_sel_checkpoints) > 0){ $arr_diff_checkpoints = array_diff($arr_all_checkpoints,$arr_sel_checkpoints); $strCheckpoints = implode(',', $arr_diff_checkpoints); } $strCheckpoints = 'checkpoints = ['.$strCheckpoints.'];'; } } $strOnReady = <<<ready .onReady(function(e){ $strCheckpoints $strSeek $('#videoaula-player').append('<div id="flag"></div>'); }) ready; return $strOnReady; }