Skip to content

Commit

Permalink
MDL-16089 some resource lib and lang pack cleanup
Browse files Browse the repository at this point in the history
AMOS START
 MOV [displayauto,mod_resource],[resourcedisplayauto,core]
 MOV [displaydownload,mod_resource],[resourcedisplaydownload,core]
 MOV [displayembed,mod_resource],[resourcedisplayembed,core]
 MOV [displayframe,mod_resource],[resourcedisplayframe,core]
 MOV [displaynew,mod_resource],[resourcedisplaynew,core]
 MOV [displayopen,mod_resource],[resourcedisplayopen,core]
 MOV [displaypopup,mod_resource],[resourcedisplaypopup,core]

AMOS END
  • Loading branch information
skodak committed May 22, 2010
1 parent bf34822 commit 9b56a34
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 144 deletions.
1 change: 0 additions & 1 deletion admin/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions auth/cas/cas_ldap_sync_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
2 changes: 0 additions & 2 deletions auth/db/auth_db_sync_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
2 changes: 0 additions & 2 deletions auth/ldap/auth_ldap_sync_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
7 changes: 7 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
57 changes: 48 additions & 9 deletions lib/resourcelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion mod/imscp/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
63 changes: 1 addition & 62 deletions mod/lesson/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
*
Expand Down
63 changes: 63 additions & 0 deletions mod/lesson/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 0 additions & 4 deletions mod/lesson/mediafile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions mod/page/lang/en/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
3 changes: 1 addition & 2 deletions mod/page/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 2 additions & 41 deletions mod/resource/db/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}
Expand Down
Loading

0 comments on commit 9b56a34

Please sign in to comment.