id/course/legacy/0".$filepath, '/'); do { if (!$file = $fs->get_file_by_hash(sha1($fullpath))) { if ($file = $fs->get_file_by_hash(sha1("$fullpath/.")) and $file->is_directory()) { if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.htm"))) { break; } if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.html"))) { break; } if ($file = $fs->get_file_by_hash(sha1("$fullpath/Default.htm"))) { break; } } return false; } } while (false); // copy and keep the same path, name, etc. $file_record = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid); try { return $fs->create_file_from_storedfile($file_record, $file); } catch (Exception $e) { // file may exist - highly unlikely, we do not want upgrades to stop here return false; } } /** * Returns list of available display options * @param array $enabled list of options enabled in module configuration * @param int $current current display options for existing instances * @return array of key=>name pairs */ function mplayerlib_get_displayoptions(array $enabled, $current=null) { if (is_number($current)) { $enabled[] = $current; } $options = array(MPLAYERLIB_DISPLAY_AUTO => get_string('mplayerdisplayauto'), MPLAYERLIB_DISPLAY_EMBED => get_string('mplayerdisplayembed'), MPLAYERLIB_DISPLAY_FRAME => get_string('mplayerdisplayframe'), MPLAYERLIB_DISPLAY_NEW => get_string('mplayerdisplaynew'), MPLAYERLIB_DISPLAY_DOWNLOAD => get_string('mplayerdisplaydownload'), MPLAYERLIB_DISPLAY_OPEN => get_string('mplayerdisplayopen'), MPLAYERLIB_DISPLAY_POPUP => get_string('mplayerdisplaypopup')); $result = array(); foreach ($options as $key=>$value) { if (in_array($key, $enabled)) { $result[$key] = $value; } } if (empty($result)) { // there should be always something in case admin misconfigures module $result[MPLAYERLIB_DISPLAY_OPEN] = $options[MPLAYERLIB_DISPLAY_OPEN]; } return $result; } /** * Tries to guess correct mimetype for arbitrary URL * @param string $fullurl * @return string mimetype */ function mplayerlib_guess_url_mimetype($fullurl) { global $CFG; require_once("$CFG->libdir/filelib.php"); if (preg_match("|^(.*)/[a-z]*file.php(\?file=)?(/[^&\?]*)|", $fullurl, $matches)) { // remove the special moodle file serving hacks so that the *file.php is ignored $fullurl = $matches[1].$matches[3]; } if (strpos($fullurl, '.php')){ // we do not really know what is in general php script return 'text/html'; } else if (substr($fullurl, -1) === '/') { // directory index (http://example.com/smaples/) return 'text/html'; } else if (strpos($fullurl, '//') !== false and substr_count($fullurl, '/') == 2) { // just a host name (http://example.com), solves Australian servers "audio" problem too return 'text/html'; } else { // ok, this finally looks like a real file return mimeinfo('type', $fullurl); } } /** * Returns image embedding html. * @param string $fullurl * @param string $title * @return string html */ function mplayerlib_embed_image($fullurl, $title) { $code = ''; $code .= '
'; $code .= "\"\""; $code .= '
'; return $code; } /** * Returns mp3 embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_mp3($fullurl, $title, $clicktoopen) { global $CFG, $OUTPUT, $PAGE; $c = $OUTPUT->mplayer_mp3player_colors(); // You can set this up in your theme/xxx/config.php $colors = explode('&', $c); $playercolors = array(); foreach ($colors as $color) { $color = explode('=', $color); $playercolors[$color[0]] = $color[1]; } $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache $playerpath = $CFG->wwwroot .'/filter/mediaplugin/mp3player.swf'; $audioplayerpath = $CFG->wwwroot .'/filter/mediaplugin/flowplayer.audio.swf'; $code = << OET; $PAGE->requires->js('/lib/flowplayer.js'); $code .= $PAGE->requires->js_function_call('M.util.init_mp3flowplayer', array('id'=>$id, 'playerpath'=>$playerpath, 'audioplayerpath'=>$audioplayerpath, 'fileurl'=>$fullurl, 'color'=>$playercolors)); return $code; } /** * Returns flash video embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_flashvideo($fullurl, $title, $clicktoopen) { global $CFG, $PAGE; $id = 'filter_flv_'.time(); //we need something unique because it might be stored in text cache $playerpath = $CFG->wwwroot .'/filter/mediaplugin/flvplayer.swf'; $code = << EOT; $PAGE->requires->js('/lib/flowplayer.js'); $code .= $PAGE->requires->js_function_call('M.util.init_flvflowplayer', array('id'=>$id, 'playerpath'=>$playerpath, 'fileurl'=>$fullurl)); return $code; } /** * Returns flash embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_flash($fullurl, $title, $clicktoopen) { $code = << $clicktoopen EOT; return $code; } /** * Returns ms media embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_mediaplayer($fullurl, $title, $clicktoopen) { $code = << $clicktoopen EOT; return $code; } /** * Returns quicktime embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_quicktime($fullurl, $title, $clicktoopen) { $code = << $clicktoopen EOT; return $code; } /** * Returns mpeg embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_mpeg($fullurl, $title, $clicktoopen) { $code = << $clicktoopen EOT; return $code; } /** * Returns real media embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_real($fullurl, $title, $clicktoopen) { $code = << $clicktoopen EOT; return $code; } /** * Returns general link or pdf embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_pdf($fullurl, $title, $clicktoopen) { global $CFG, $PAGE; $code = << $clicktoopen EOT; //$PAGE->requires->js_init_call('M.util.init_maximised_embed', array('mplayerobject'), true); return $code; } /** * Returns general link or file embedding html. * @param string $fullurl * @param string $title * @param string $clicktoopen * @return string html */ function mplayerlib_embed_general($fullurl, $title, $clicktoopen, $mimetype) { global $CFG, $PAGE; $iframe = false; // IE can not embed stuff properly if stored on different server // that is why we use iframe instead, unfortunately this tag does not validate // in xhtml strict mode if ($mimetype === 'text/html' and check_browser_version('MSIE', 5)) { if (preg_match('(^https?://[^/]*)', $fullurl, $matches)) { if (strpos($CFG->wwwroot, $matches[0]) !== 0) { $iframe = true; } } } if ($iframe) { $code = << EOT; } else { $code = << $clicktoopen EOT; } $PAGE->requires->js_init_call('M.util.init_maximised_embed', array('mplayerobject'), true); return $code; }