diff --git a/admin/generator.php b/admin/generator.php index c5b0be84d7ea7..315d44e9063cf 100755 --- a/admin/generator.php +++ b/admin/generator.php @@ -28,7 +28,6 @@ require_once(dirname(__FILE__).'/../config.php'); require_once($CFG->libdir . '/formslib.php'); require_once($CFG->dirroot .'/course/lib.php'); -require_once($CFG->dirroot .'/mod/resource/lib.php'); require_once($CFG->libdir .'/filelib.php'); define('GENERATOR_RANDOM', 0); diff --git a/auth/cas/cas_ldap_sync_users.php b/auth/cas/cas_ldap_sync_users.php index 2c16f13bda5d3..e255b4c54d460 100644 --- a/auth/cas/cas_ldap_sync_users.php +++ b/auth/cas/cas_ldap_sync_users.php @@ -32,9 +32,6 @@ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); // global moodle config file. require_once($CFG->dirroot.'/course/lib.php'); -require_once($CFG->dirroot.'/mod/resource/lib.php'); -require_once($CFG->dirroot.'/mod/forum/lib.php'); -require_once($CFG->dirroot.'/lib/moodlelib.php'); if (!is_enabled_auth('cas')) { echo "Plugin not enabled!"; diff --git a/auth/db/auth_db_sync_users.php b/auth/db/auth_db_sync_users.php index fe476a5b85868..8a7f0addbd676 100644 --- a/auth/db/auth_db_sync_users.php +++ b/auth/db/auth_db_sync_users.php @@ -32,8 +32,6 @@ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); // global moodle config file. require_once($CFG->dirroot.'/course/lib.php'); -require_once($CFG->dirroot.'/mod/resource/lib.php'); -require_once($CFG->dirroot.'/mod/forum/lib.php'); if (!is_enabled_auth('db')) { echo "Plugin not enabled!"; diff --git a/auth/ldap/auth_ldap_sync_users.php b/auth/ldap/auth_ldap_sync_users.php index 45cbb8e404643..b5423445fdda8 100755 --- a/auth/ldap/auth_ldap_sync_users.php +++ b/auth/ldap/auth_ldap_sync_users.php @@ -31,8 +31,6 @@ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); // global moodle config file. require_once($CFG->dirroot.'/course/lib.php'); -require_once($CFG->dirroot.'/mod/resource/lib.php'); -require_once($CFG->dirroot.'/mod/forum/lib.php'); if (!is_enabled_auth('ldap')) { echo "Plugin not enabled!"; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 7efa6e6a0efdc..7ecca02e172fe 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1442,6 +1442,13 @@ $string['resettodefaults'] = 'Reset to defaults'; $string['resortcoursesbyname'] = 'Re-sort courses by name'; $string['resource'] = 'Resource'; +$string['resourcedisplayauto'] = 'Automatic'; +$string['resourcedisplaydownload'] = 'Force download'; +$string['resourcedisplayembed'] = 'Embed'; +$string['resourcedisplayframe'] = 'In frame'; +$string['resourcedisplaynew'] = 'New window'; +$string['resourcedisplayopen'] = 'Open'; +$string['resourcedisplaypopup'] = 'In pop-up'; $string['resources'] = 'Resources'; $string['resources_help'] = 'Resource types enable almost any kind of web content to be inserted into the course.'; $string['restore'] = 'Restore'; diff --git a/lib/resourcelib.php b/lib/resourcelib.php index 7a71e2a99f145..7dd48cb726e6d 100644 --- a/lib/resourcelib.php +++ b/lib/resourcelib.php @@ -46,6 +46,45 @@ define('RESOURCELIB_LEGACYFILES_ACTIVE', 2); +/** + * Try on demand migration of file from old course files + * @param string $filepath old file path + * @param int $cmid migrated course module if + * @param int $courseid + * @param string $filearea new file area + * @param int $itemid migrated file item id + * @return mixed, false if not found, stored_file instance if migrated to new area + */ +function resourcelib_try_file_migration($filepath, $cmid, $courseid, $filearea, $itemid) { + $fs = get_file_storage(); + + if (stripos($filepath, '/backupdata/') === 0 or stripos($filepath, '/moddata/') === 0) { + // do not steal protected files! + return false; + } + + if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) { + return false; + } + if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid)) { + return false; + } + + $pathnamehash = sha1($coursecontext->id.'course_content0'.$filepath); + if (!$file = $fs->get_file_by_hash($pathnamehash)) { + return false; + } + + // copy and keep the same path, name, etc. + $file_record = array('contextid'=>$context->id, '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 @@ -57,13 +96,13 @@ function resourcelib_get_displayoptions(array $enabled, $current=null) { $enabled[] = $current; } - $options = array(RESOURCELIB_DISPLAY_AUTO => get_string('displayauto', 'resource'), - RESOURCELIB_DISPLAY_EMBED => get_string('displayembed', 'resource'), - RESOURCELIB_DISPLAY_FRAME => get_string('displayframe', 'resource'), - RESOURCELIB_DISPLAY_NEW => get_string('displaynew', 'resource'), - RESOURCELIB_DISPLAY_DOWNLOAD => get_string('displaydownload', 'resource'), - RESOURCELIB_DISPLAY_OPEN => get_string('displayopen', 'resource'), - RESOURCELIB_DISPLAY_POPUP => get_string('displaypopup', 'resource')); + $options = array(RESOURCELIB_DISPLAY_AUTO => get_string('resourcedisplayauto'), + RESOURCELIB_DISPLAY_EMBED => get_string('resourcedisplayembed'), + RESOURCELIB_DISPLAY_FRAME => get_string('resourcedisplayframe'), + RESOURCELIB_DISPLAY_NEW => get_string('resourcedisplaynew'), + RESOURCELIB_DISPLAY_DOWNLOAD => get_string('resourcedisplaydownload'), + RESOURCELIB_DISPLAY_OPEN => get_string('resourcedisplayopen'), + RESOURCELIB_DISPLAY_POPUP => get_string('resourcedisplaypopup')); $result = array(); @@ -143,7 +182,7 @@ function resourcelib_embed_mp3($fullurl, $title, $clicktoopen) { $c .= '&volText='.get_string('vol', 'resource').'&panText='.get_string('pan','resource'); $id = 'filter_mp3_'.time(); //we need something unique because it might be stored in text cache - $ufoargs = array('movie' => $CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.addslashes_js($fullurl), + $ufoargs = array('movie' => $CFG->wwwroot.'/lib/mp3player/mp3player.swf?src='.urlencode($fullurl), 'width' => 600, 'height' => 70, 'majorversion' => 6, @@ -184,7 +223,7 @@ function resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen) { $id = 'filter_flv_'.time(); //we need something unique because it might be stored in text cache - $ufoargs = array('movie' => $CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.addslashes_js($fullurl), + $ufoargs = array('movie' => $CFG->wwwroot.'/filter/mediaplugin/flvplayer.swf?file='.urlencode($fullurl), 'width' => 600, 'height' => 400, 'majorversion' => 6, diff --git a/mod/imscp/mod_form.php b/mod/imscp/mod_form.php index f49790d3d56a9..0ed638687d5ee 100644 --- a/mod/imscp/mod_form.php +++ b/mod/imscp/mod_form.php @@ -28,7 +28,6 @@ } require_once ($CFG->dirroot.'/course/moodleform_mod.php'); -require_once($CFG->dirroot.'/mod/resource/locallib.php'); require_once($CFG->libdir.'/filelib.php'); class mod_imscp_mod_form extends moodleform_mod { diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index c51d7a732990a..5075b3767a720 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -24,6 +24,7 @@ **/ /** Include required libraries */ +//TODO: these dumb includes have to be removed and this script minimised by moving stuff to locallib.php!!! require_once($CFG->libdir.'/eventslib.php'); require_once($CFG->libdir.'/filelib.php'); require_once($CFG->dirroot.'/calendar/lib.php'); @@ -961,68 +962,6 @@ function lesson_get_file_info($browser, $areas, $course, $cm, $context, $fileare return new file_info_stored($browser, $context, $storedfile, $urlbase, $filearea, $itemid, true, true, false); } -/** - * This is a function used to detect media types and generate html code. - * - * @global object $CFG - * @global object $PAGE - * @param object $lesson - * @param object $context - * @return string $code the html code of media - */ -function lesson_get_media_html($lesson, $context) { - global $CFG, $PAGE, $OUTPUT; - - // get the media file from file pool - $browser = get_file_browser(); - $file_info = $browser->get_file_info($context, 'lesson_media_file', $lesson->id, '/', $lesson->mediafile); - $url = $file_info->get_url(); - $title = $lesson->mediafile; - - $clicktoopen = html_writer::link(new moodle_url($url), get_string('download')); - - $mimetype = resourcelib_guess_url_mimetype($url); - - // find the correct type and print it out - if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image - $code = resourcelib_embed_image($url, $title); - - } else if ($mimetype == 'audio/mp3') { - // MP3 audio file - $code = resourcelib_embed_mp3($url, $title, $clicktoopen); - - } else if ($mimetype == 'video/x-flv') { - // Flash video file - $code = resourcelib_embed_flashvideo($url, $title, $clicktoopen); - - } else if ($mimetype == 'application/x-shockwave-flash') { - // Flash file - $code = resourcelib_embed_flash($url, $title, $clicktoopen); - - } else if (substr($mimetype, 0, 10) == 'video/x-ms') { - // Windows Media Player file - $code = resourcelib_embed_mediaplayer($url, $title, $clicktoopen); - - } else if ($mimetype == 'video/quicktime') { - // Quicktime file - $code = resourcelib_embed_quicktime($url, $title, $clicktoopen); - - } else if ($mimetype == 'video/mpeg') { - // Mpeg file - $code = resourcelib_embed_mpeg($url, $title, $clicktoopen); - - } else if ($mimetype == 'audio/x-pn-realaudio-plugin') { - // RealMedia file - $code = resourcelib_embed_real($url, $title, $clicktoopen); - - } else { - // anything else - just try object tag enlarged as much as possible - $code = resourcelib_embed_general($url, $title, $clicktoopen, $mimetype); - } - - return $code; -} - /** * Abstract class to provide a core functions to the all lesson classes * diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 652fecaa794c9..09b78bc79ba02 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -569,3 +569,66 @@ function lesson_add_header_buttons($cm, $context, $extraeditbuttons=false, $less } } } + +/** + * This is a function used to detect media types and generate html code. + * + * @global object $CFG + * @global object $PAGE + * @param object $lesson + * @param object $context + * @return string $code the html code of media + */ +function lesson_get_media_html($lesson, $context) { + global $CFG, $PAGE, $OUTPUT; + require_once("$CFG->libdir/resourcelib.php"); + + // get the media file from file pool + $browser = get_file_browser(); + $file_info = $browser->get_file_info($context, 'lesson_media_file', $lesson->id, '/', $lesson->mediafile); + $url = $file_info->get_url(); + $title = $lesson->mediafile; + + $clicktoopen = html_writer::link(new moodle_url($url), get_string('download')); + + $mimetype = resourcelib_guess_url_mimetype($url); + + // find the correct type and print it out + if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image + $code = resourcelib_embed_image($url, $title); + + } else if ($mimetype == 'audio/mp3') { + // MP3 audio file + $code = resourcelib_embed_mp3($url, $title, $clicktoopen); + + } else if ($mimetype == 'video/x-flv') { + // Flash video file + $code = resourcelib_embed_flashvideo($url, $title, $clicktoopen); + + } else if ($mimetype == 'application/x-shockwave-flash') { + // Flash file + $code = resourcelib_embed_flash($url, $title, $clicktoopen); + + } else if (substr($mimetype, 0, 10) == 'video/x-ms') { + // Windows Media Player file + $code = resourcelib_embed_mediaplayer($url, $title, $clicktoopen); + + } else if ($mimetype == 'video/quicktime') { + // Quicktime file + $code = resourcelib_embed_quicktime($url, $title, $clicktoopen); + + } else if ($mimetype == 'video/mpeg') { + // Mpeg file + $code = resourcelib_embed_mpeg($url, $title, $clicktoopen); + + } else if ($mimetype == 'audio/x-pn-realaudio-plugin') { + // RealMedia file + $code = resourcelib_embed_real($url, $title, $clicktoopen); + + } else { + // anything else - just try object tag enlarged as much as possible + $code = resourcelib_embed_general($url, $title, $clicktoopen, $mimetype); + } + + return $code; +} diff --git a/mod/lesson/mediafile.php b/mod/lesson/mediafile.php index cffe0b216fdfb..4d993e51fb013 100644 --- a/mod/lesson/mediafile.php +++ b/mod/lesson/mediafile.php @@ -18,8 +18,6 @@ /** * This file plays the mediafile set in lesson settings. * - * Almost all of this code is from /mod/resource/type/file/resource.class.php so major props for resource - * * If there is a way to use the resource class instead of this code, please change to do so * * @@ -30,8 +28,6 @@ require_once('../../config.php'); require_once($CFG->dirroot.'/mod/lesson/locallib.php'); -require_once($CFG->libdir.'/filelib.php'); -require_once($CFG->libdir.'/resourcelib.php'); $id = required_param('id', PARAM_INT); // Course Module ID $printclose = optional_param('printclose', 0, PARAM_INT); diff --git a/mod/page/lang/en/page.php b/mod/page/lang/en/page.php index 79439af581bfc..0a0629179af19 100644 --- a/mod/page/lang/en/page.php +++ b/mod/page/lang/en/page.php @@ -26,8 +26,6 @@ $string['configdisplayoptions'] = 'Select all options that should be available, existing settings are not modified. Hold CTRL key to select multiple fields.'; $string['content'] = 'Page content'; $string['contentheader'] = 'Content'; -$string['displaynew'] = 'New window'; -$string['displayopen'] = 'Open'; $string['displayoptions'] = 'Available display options'; $string['displayselect'] = 'Display'; $string['displayselectexplain'] = 'Select display type.'; diff --git a/mod/page/lib.php b/mod/page/lib.php index 5a571b84410b6..35be5e2e0327b 100644 --- a/mod/page/lib.php +++ b/mod/page/lib.php @@ -367,8 +367,7 @@ function page_pluginfile($course, $cminfo, $context, $filearea, $args, $forcedow if ($page->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) { return false; } - require_once("$CFG->dirroot/mod/resource/db/upgradelib.php"); - if (!$file = resource_try_file_migration($relativepath, $cminfo->id, $cminfo->course, 'page_content', 0)) { + if (!$file = resourcelib_try_file_migration($relativepath, $cminfo->id, $cminfo->course, 'page_content', 0)) { return false; } //file migrate - update flag diff --git a/mod/resource/db/upgradelib.php b/mod/resource/db/upgradelib.php index f4d8a84a834c0..266b0d73191a0 100644 --- a/mod/resource/db/upgradelib.php +++ b/mod/resource/db/upgradelib.php @@ -23,45 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** - * Try on demand migration of file from old course files - * @param string $filepath old file path - * @param int $cmid migrated course module if - * @param int $courseid - * @param string $filearea new file area - * @param int $itemid migrated file item id - * @return mixed, false if not found, stored_file instance if migrated to new area - */ -function resource_try_file_migration($filepath, $cmid, $courseid, $filearea, $itemid) { - $fs = get_file_storage(); - - if (stripos($filepath, '/backupdata/') === 0 or stripos($filepath, '/moddata/') === 0) { - // do not steal protected files! - return false; - } - - if (!$context = get_context_instance(CONTEXT_MODULE, $cmid)) { - return false; - } - if (!$coursecontext = get_context_instance(CONTEXT_COURSE, $courseid)) { - return false; - } - - $pathnamehash = sha1($coursecontext->id.'course_content0'.$filepath); - if (!$file = $fs->get_file_by_hash($pathnamehash)) { - return false; - } - - // copy and keep the same path, name, etc. - $file_record = array('contextid'=>$context->id, '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; - } -} - /** * Migrate resource module data from 1.9 resource_old table to new resource table * @return void @@ -132,7 +93,7 @@ function resource_20_migrate() { } // try migration of main file - ignore if does not exist - if ($file = resource_try_file_migration($resource->mainfile, $candidate->cmid, $candidate->course, 'resource_content', 0)) { + if ($file = resourcelib_try_file_migration($resource->mainfile, $candidate->cmid, $candidate->course, 'resource_content', 0)) { $resource->mainfile = $file->get_filepath().$file->get_filename(); } @@ -166,7 +127,7 @@ function resource_20_migrate() { } // try migration of main file - ignore if does not exist - if ($file = resource_try_file_migration($resource->mainfile, $candidate->cmid, $candidate->course, 'resource_content', 0)) { + if ($file = resourcelib_try_file_migration($resource->mainfile, $candidate->cmid, $candidate->course, 'resource_content', 0)) { $resource->mainfile = $file->get_filepath().$file->get_filename(); } } diff --git a/mod/resource/lang/en/resource.php b/mod/resource/lang/en/resource.php index a65fcc567a588..bbd17a847de29 100644 --- a/mod/resource/lang/en/resource.php +++ b/mod/resource/lang/en/resource.php @@ -59,14 +59,7 @@ $string['directlink'] = 'Direct link to this file'; $string['directoryinfo'] = 'All the files in the chosen directory will be displayed.'; $string['display'] = 'Window'; -$string['displayauto'] = 'Automatic'; -$string['displaydownload'] = 'Force download'; -$string['displayembed'] = 'Embed'; -$string['displayframe'] = 'In frame'; -$string['displaynew'] = 'New window'; -$string['displayopen'] = 'Open'; $string['displayoptions'] = 'Available display options'; -$string['displaypopup'] = 'In pop-up'; $string['displayselect'] = 'Display'; $string['displayselectexplain'] = 'Choose display type, unfortunately not all types are suitable for all files.'; $string['editingaresource'] = 'Editing a resource'; diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 52b997e9a2def..018a169589083 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -420,8 +420,7 @@ function resource_pluginfile($course, $cminfo, $context, $filearea, $args, $forc if ($resource->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) { return false; } - require_once("$CFG->dirroot/mod/resource/db/upgradelib.php"); - if (!$file = resource_try_file_migration($relativepath, $cminfo->id, $cminfo->course, 'resource_content', 0)) { + if (!$file = resourcelib_try_file_migration($relativepath, $cminfo->id, $cminfo->course, 'resource_content', 0)) { return false; } // file migrate - update flag diff --git a/mod/url/lang/en/url.php b/mod/url/lang/en/url.php index 85f10139dd441..1e7f5f03f4797 100644 --- a/mod/url/lang/en/url.php +++ b/mod/url/lang/en/url.php @@ -29,13 +29,7 @@ $string['configrolesinparams'] = 'Enable if you want to include localized role names in list of avaible parameter variables.'; $string['configsecretphrase'] = 'This secret phrase is used to produce encrypted code value that can be sent to some servers as a parameter. The encrypted code is produced by an md5 value of the current user IP address concatenated with your secret phrase. ie code = md5(IP.secretphrase). Please note that this is not reliable because IP address may change and is often shared by different computers.'; $string['contentheader'] = 'Content'; -$string['displayauto'] = 'Automatic'; -$string['displayembed'] = 'Embed'; -$string['displayframe'] = 'In frame'; -$string['displaynew'] = 'New window'; -$string['displayopen'] = 'Open'; $string['displayoptions'] = 'Available display options'; -$string['displaypopup'] = 'In pop-up'; $string['displayselect'] = 'Display'; $string['displayselectexplain'] = 'Choose display type, unfortunately not all types are suitable for all URLs.'; $string['externalurl'] = 'External URL';