📄 resource.class.php
字号:
/// Set up some variables $inpopup = optional_param('inpopup', 0, PARAM_BOOL); if (resource_is_url($resource->reference)) { $fullurl = $resource->reference; if (!empty($querystring)) { $urlpieces = parse_url($resource->reference); if (empty($urlpieces['query']) or $isteamspeak) { $fullurl .= '?'.$querystring; } else { $fullurl .= '&'.$querystring; } } } else if ($CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) { // Localpath $localpath = get_user_preferences('resource_localpath', 'D:'); $relativeurl = str_replace(RESOURCE_LOCALPATH, $localpath, $resource->reference); if ($querystring) { $relativeurl .= '?'.$querystring; } $relativeurl = str_replace('\\', '/', $relativeurl); $relativeurl = str_replace(' ', '%20', $relativeurl); $fullurl = 'file:///'.htmlentities($relativeurl); $localpath = true; } else { // Normal uploaded file $forcedownloadsep = '?'; if ($resource->options == 'forcedownload') { $querys['forcedownload'] = '1'; } $fullurl = get_file_url($course->id.'/'.$resource->reference, $querys); } /// Print a notice and redirect if we are trying to access a file on a local file system /// and the config setting has been disabled if (!$CFG->resource_allowlocalfiles and (strpos($resource->reference, RESOURCE_LOCALPATH) === 0)) { if ($inpopup) { print_header($pagetitle, $course->fullname); } else { $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); } notify(get_string('notallowedlocalfileaccess', 'resource', '')); if ($inpopup) { close_window_button(); } print_footer('none'); die; } /// Check whether this is supposed to be a popup, but was called directly if ($resource->popup and !$inpopup) { /// Make a page and a pop-up window $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm)); echo "\n<script type=\"text/javascript\">"; echo "\n<!--\n"; echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n"; echo "\n-->\n"; echo '</script>'; if (trim(strip_tags($resource->summary))) { print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center"); } $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&id={$cm->id}\" " . "onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', " . "'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>"; echo '<div class="popupnotice">'; print_string('popupresource', 'resource'); echo '<br />'; print_string('popupresourcelink', 'resource', $link); echo '</div>'; print_footer($course); exit; } /// Now check whether we need to display a frameset $frameset = optional_param('frameset', '', PARAM_ALPHA); if (empty($frameset) and !$embedded and !$inpopup and ($resource->options == "frame" || $resource->options == "objectframe") and empty($USER->screenreader)) { /// display the resource into a object tag if ($resource->options == "objectframe") { /// Yahoo javascript libaries for updating embedded object size require_js(array('yui_utilities')); require_js(array('yui_container')); require_js(array('yui_dom-event')); require_js(array('yui_dom')); /// Moodle Header and navigation bar $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent")); $options = new object(); $options->para = false; if (!empty($localpath)) { // Show some help echo '<div class="mdl-right helplink">'; link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource')); echo '</div>'; } echo '</div></div>'; /// embedded file into iframe if the resource is on another domain /// /// This case is not XHTML strict but there is no alternative /// The object tag alternative is XHTML strict, however IE6-7 displays a blank object on accross domain by default, /// so we decided to use iframe for accross domain MDL-10021 if (!stristr($fullurl,$CFG->wwwroot)) { echo '<p><iframe id="embeddedhtml" src ="'.$fullurl.'" width="100%" height="600"></iframe></p>'; } else { /// embedded HTML file into an object tag echo '<p><object id="embeddedhtml" data="' . $fullurl . '" type="'.$mimetype.'" width="800" height="600"> alt : <a href="' . $fullurl . '">' . $fullurl . '</a> </object></p>'; } /// add some javascript in order to fit this object tag into the browser window echo '<script type="text/javascript"> //<![CDATA[ function resizeEmbeddedHtml() { //calculate new embedded html height size '; if (!empty($resource->summary)) { echo' objectheight = YAHOO.util.Dom.getViewportHeight() - 230; '; } else { echo' objectheight = YAHOO.util.Dom.getViewportHeight() - 120; '; } echo ' //the object tag cannot be smaller than a human readable size if (objectheight < 200) { objectheight = 200; } //resize the embedded html object YAHOO.util.Dom.setStyle("embeddedhtml", "height", objectheight+"px"); YAHOO.util.Dom.setStyle("embeddedhtml", "width", "100%"); } resizeEmbeddedHtml(); YAHOO.widget.Overlay.windowResizeEvent.subscribe(resizeEmbeddedHtml); //]]> </script> '; /// print the summary if (!empty($resource->summary)) { print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center"); } echo "</body></html>"; exit; } /// display the resource into a frame tag else { @header('Content-Type: text/html; charset=utf-8'); echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n"; echo "<html dir=\"ltr\">\n"; echo '<head>'; echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />'; echo "<title>" . format_string($course->shortname) . ": ".strip_tags(format_string($resource->name,true))."</title></head>\n"; echo "<frameset rows=\"$CFG->resource_framesize,*\">"; echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&frameset=top\" title=\"".get_string('modulename','resource')."\"/>"; if (!empty($localpath)) { // Show it like this so we interpose some HTML echo "<frame src=\"view.php?id={$cm->id}&type={$resource->type}&inpopup=true\" title=\"".get_string('modulename','resource')."\"/>"; } else { echo "<frame src=\"$fullurl\" title=\"".get_string('modulename','resource')."\"/>"; } echo "</frameset>"; echo "</html>"; exit; } } /// We can only get here once per resource, so add an entry to the log add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); /// If we are in a frameset, just print the top of it if (!empty( $frameset ) and ($frameset == "top") ) { $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent")); $options = new object(); $options->para = false; echo '<div class="summary">'.format_text($resource->summary, FORMAT_HTML, $options).'</div>'; if (!empty($localpath)) { // Show some help echo '<div class="mdl-right helplink">'; link_to_popup_window ('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp','resource'), 400, 500, get_string('localfilehelp', 'resource')); echo '</div>'; } print_footer('empty'); exit; } /// Display the actual resource if ($embedded) { // Display resource embedded in page $strdirectlink = get_string("directlink", "resource"); if ($inpopup) { print_header($pagetitle); } else { $navigation = build_navigation($this->navlinks, $cm); print_header_simple($pagetitle, '', $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "self")); } if ($resourcetype == "image") { echo '<div class="resourcecontent resourceimg">'; echo "<img title=\"".strip_tags(format_string($resource->name,true))."\" class=\"resourceimage\" src=\"$fullurl\" alt=\"\" />"; echo '</div>'; } else if ($resourcetype == "mp3") { if (!empty($THEME->resource_mp3player_colors)) { $c = $THEME->resource_mp3player_colors; // You can set this up in your theme/xxx/config.php } else { $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&'. 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&'. 'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes'; } $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource'); $c = htmlentities($c); $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache $cleanurl = addslashes_js($fullurl); // If we have Javascript, use UFO to embed the MP3 player, otherwise depend on plugins echo '<div class="resourcecontent resourcemp3">'; echo '<span class="mediaplugin mediaplugin_mp3" id="'.$id.'"></span>'. '<script type="text/javascript">'."\n". '//<![CDATA['."\n". 'var FO = { movie:"'.$CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.$cleanurl.'",'."\n". 'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"'.$c.'", quality: "high" };'."\n". 'UFO.create(FO, "'.$id.'");'."\n". '//]]>'."\n". '</script>'."\n"; echo '<noscript>'; echo "<object type=\"audio/mpeg\" data=\"$fullurl\" width=\"600\" height=\"70\">"; echo "<param name=\"src\" value=\"$fullurl\" />"; echo '<param name="quality" value="high" />'; echo '<param name="autoplay" value="true" />'; echo '<param name="autostart" value="true" />'; echo '</object>'; echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>'; echo '</noscript>'; echo '</div>'; } else if ($resourcetype == "flv") { $id = 'filter_flv_'.time(); //we need something unique because it might be stored in text cache $cleanurl = addslashes_js($fullurl); // If we have Javascript, use UFO to embed the FLV player, otherwise depend on plugins echo '<div class="resourcecontent resourceflv">'; echo '<span class="mediaplugin mediaplugin_flv" id="'.$id.'"></span>'. '<script type="text/javascript">'."\n". '//<![CDATA['."\n". 'var FO = { movie:"'.$CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.$cleanurl.'",'."\n". 'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", allowfullscreen:"true", quality: "high" };'."\n". 'UFO.create(FO, "'.$id.'");'."\n". '//]]>'."\n". '</script>'."\n"; echo '<noscript>'; echo "<object type=\"video/x-flv\" data=\"$fullurl\" width=\"600\" height=\"400\">"; echo "<param name=\"src\" value=\"$fullurl\" />"; echo '<param name="quality" value="high" />'; echo '<param name="autoplay" value="true" />'; echo '<param name="autostart" value="true" />'; echo '</object>'; echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>'; echo '</noscript>';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -