Permalink
Browse files

MDL-19927: add new plugins for ogg and ogv file and also removing som…

…e extra whitespaces within the file.
  • Loading branch information...
rwijaya committed Oct 7, 2010
1 parent d5abaa6 commit f030e2a7939bcc3f2bdbcae1e122359ae134adf1
@@ -40,6 +40,16 @@ function mediaplugin_filter($courseid, $text) {
$newtext = preg_replace_callback($search, 'mediaplugin_filter_mp3_callback', $newtext);
}
+ if ($CFG->filter_mediaplugin_enable_ogg) {
+ $search = '/<a[^>]*?href="([^<]+\.ogg)"[^>]*>.*?<\/a>/is';
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_ogg_callback', $newtext);
+ }
+
+ if ($CFG->filter_mediaplugin_enable_ogv) {
+ $search = '/<a[^>]*?href="([^<]+\.ogv)"[^>]*>.*?<\/a>/is';
+ $newtext = preg_replace_callback($search, 'filter_mediaplugin_ogv_callback', $newtext);
+ }
+
if ($CFG->filter_mediaplugin_enable_swf) {
$search = '/<a.*?href="([^<]+\.swf)(\?d=([\d]{1,4}%?)x([\d]{1,4}%?))?"[^>]*>.*?<\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $newtext);
@@ -147,6 +157,44 @@ function mediaplugin_filter_mp3_callback($link) {
</script>';
}
+function filter_mediaplugin_ogg_callback($link) {
+ global $CFG, $OUTPUT, $PAGE;
+
+ static $count = 0;
+ $count++;
+ $id = 'filter_ogg_'.time().$count; //we need something unique because it might be stored in text cache
+
+ $url = addslashes_js($link[1]);
+ $printlink = html_writer::link($url, get_string('oggaudio', 'filter_mediaplugin'));
+ $unsupportedplugins = get_string('unsupportedplugins', 'filter_mediaplugin', $printlink);
+ $output = <<<OET
+ <audio id="$id" src="$url" controls="true" width="100">
+ $unsupportedplugins
+ </audio>
+OET;
+
+ return $output;
+}
+
+function filter_mediaplugin_ogv_callback($link) {
+ global $CFG, $OUTPUT, $PAGE;
+
+ static $count = 0;
+ $count++;
+ $id = 'filter_ogv_'.time().$count; //we need something unique because it might be stored in text cache
+
+ $url = addslashes_js($link[1]);
+ $printlink = html_writer::link($url, get_string('ogvvideo', 'filter_mediaplugin'));
+ $unsupportedplugins = get_string('unsupportedplugins', 'filter_mediaplugin', $printlink);
+ $output = <<<OET
+ <video id="$id" src="$url" controls="true" width="600" >
+ $unsupportedplugins
+ </video>
+OET;
+
+ return $output;
+}
+
function mediaplugin_filter_swf_callback($link) {
static $count = 0;
$count++;
@@ -228,8 +276,8 @@ function mediaplugin_filter_youtube_callback($link, $autostart=false) {
$url = addslashes_js($link[2]);
$info = addslashes_js($link[3]);
- return '<object title="'.$info.'"
- class="mediaplugin mediaplugin_youtube" type="application/x-shockwave-flash"
+ return '<object title="'.$info.'"
+ class="mediaplugin mediaplugin_youtube" type="application/x-shockwave-flash"
data="'.$site.'youtube.com/v/'.$url.'&amp;fs=1&amp;rel=0" width="425" height="344">'.
'<param name="movie" value="'.$site.'youtube.com/v/'.$url.'&amp;fs=1&amp;rel=0" />'.
'<param name="FlashVars" value="playerMode=embedded" />'.
@@ -21,4 +21,8 @@
$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_rm', get_string('mediapluginrm','admin'), '', 1));
$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_youtube', get_string('mediapluginyoutube','admin'), '', 0));
+
+$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_ogg', get_string('mediapluginogg','admin'), '', 1));
+
+$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_ogv', get_string('mediapluginogv','admin'), '', 1));
?>
View
@@ -510,6 +510,8 @@
$string['mediapluginmov'] = 'Enable .mov filter';
$string['mediapluginmp3'] = 'Enable .mp3 filter';
$string['mediapluginmpg'] = 'Enable .mpg filter';
+$string['mediapluginogg'] = 'Enable .ogg filter';
+$string['mediapluginogv'] = 'Enable .ogv filter';
$string['mediapluginram'] = 'Enable .ram filter';
$string['mediapluginrm'] = 'Enable .rm filter';
$string['mediapluginrpm'] = 'Enable .rpm filter';
@@ -1,4 +1,4 @@
-<?PHP // $Id$
+<?PHP // $Id$
// mediaplugin.php - created with Moodle 1.7 beta + (2006101003)
@@ -7,5 +7,7 @@
$string['flashanimation'] = 'Flash animation';
$string['flashvideo'] = 'Flash video';
$string['mp3audio'] = 'MP3 audio';
-
+$string['oggaudio'] = 'OGG audio';
+$string['ogvvideo'] = 'OGV video';
+$string['unsupportedplugins'] = '(The browser does not support this type of file. {$a})';
?>
View
@@ -1680,7 +1680,7 @@ function xmldb_main_upgrade($oldversion=0) {
$table = new XMLDBTable('groups');
$field = new XMLDBField('password');
- if (field_exists($table, $field)) {
+ if (field_exists($table, $field)) {
/// 1.7.*/1.6.*/1.5.* - create 'groupings' and 'groupings_groups' + rename password to enrolmentkey
/// or second run after fixing structure broken from 1.8.x
$result = $result && upgrade_17_groups();
@@ -1694,7 +1694,7 @@ function xmldb_main_upgrade($oldversion=0) {
upgrade_18_broken_groups();
notify('Warning: failed groups upgrade detected! Unfortunately this problem '.
'can not be fixed automatically. Mapping of groups to courses was lost, '.
- 'you can either revert to backup from 1.7.x and run ugprade again or '.
+ 'you can either revert to backup from 1.7.x and run ugprade again or '.
'continue and fill in the missing course ids into groups table manually.');
$result = false;
}
@@ -2355,7 +2355,7 @@ function xmldb_main_upgrade($oldversion=0) {
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/*
- * Note: mysql can not create indexes on text fields larger than 333 chars!
+ * Note: mysql can not create indexes on text fields larger than 333 chars!
*/
/// Adding indexes to table cache_flags
@@ -2400,7 +2400,7 @@ function xmldb_main_upgrade($oldversion=0) {
if (index_exists($table, $index)) {
$result = $result && drop_index($table, $index);
}
-
+
$table = new XMLDBTable('cache_flags');
$index = new XMLDBIndex('flagtype');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('flagtype'));
@@ -2562,7 +2562,7 @@ function xmldb_main_upgrade($oldversion=0) {
FROM {$CFG->prefix}user_lastaccess
WHERE NOT EXISTS (SELECT 'x'
FROM {$CFG->prefix}course c
- WHERE c.id = {$CFG->prefix}user_lastaccess.courseid)";
+ WHERE c.id = {$CFG->prefix}user_lastaccess.courseid)";
execute_sql($sql);
upgrade_main_savepoint($result, 2007100902);
@@ -2585,16 +2585,16 @@ function xmldb_main_upgrade($oldversion=0) {
upgrade_main_savepoint($result, 2007100903);
}
-
+
if ($result && $oldversion < 2007101500 && !file_exists($CFG->dataroot . '/user')) {
// Get list of users by browsing moodledata/user
$oldusersdir = $CFG->dataroot . '/users';
$folders = get_directory_list($oldusersdir, '', false, true, false);
-
+
foreach ($folders as $userid) {
$olddir = $oldusersdir . '/' . $userid;
$files = get_directory_list($olddir);
-
+
if (empty($files)) {
continue;
}
@@ -2621,30 +2621,30 @@ function xmldb_main_upgrade($oldversion=0) {
$readmefilename = $oldusersdir . '/README.txt';
if ($handle = fopen($readmefilename, 'w+b')) {
if (!fwrite($handle, get_string('olduserdirectory'))) {
- // Could not write to the readme file. No cause for huge concern
+ // Could not write to the readme file. No cause for huge concern
notify("Could not write to the README.txt file in $readmefilename.");
}
fclose($handle);
} else {
// Could not create the readme file. No cause for huge concern
notify("Could not create the README.txt file in $readmefilename.");
}
- }
+ }
if ($result && $oldversion < 2007101502) {
/// try to remove duplicate entries
-
+
$SQL = "SELECT userid, itemid, COUNT(*)
FROM {$CFG->prefix}grade_grades
GROUP BY userid, itemid
HAVING COUNT( * ) >1";
// duplicates found
-
+
if ($rs = get_recordset_sql($SQL)) {
if ($rs && $rs->RecordCount() > 0) {
while ($dup = rs_fetch_next_record($rs)) {
- if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades
+ if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades
WHERE itemid = $dup->itemid AND userid = $dup->userid
ORDER BY timemodified DESC")) {
@@ -2702,7 +2702,7 @@ function xmldb_main_upgrade($oldversion=0) {
$sql = "DELETE
FROM {$CFG->prefix}context
WHERE contextlevel=20";
-
+
execute_sql($sql);
/// Main savepoint reached
@@ -2864,7 +2864,7 @@ function xmldb_main_upgrade($oldversion=0) {
}
if ($result && $oldversion < 2007101508.04) {
- set_field('tag_instance', 'itemtype', 'post', 'itemtype', 'blog');
+ set_field('tag_instance', 'itemtype', 'post', 'itemtype', 'blog');
upgrade_main_savepoint($result, 2007101508.04);
}
@@ -2941,7 +2941,7 @@ function xmldb_main_upgrade($oldversion=0) {
/// Launch add field name
$result = $result && add_field($table, $field);
-
+
/// Copy data from old field to new field
$result = $result && execute_sql('UPDATE '.$CFG->prefix.'role_names SET name = text');
@@ -3345,6 +3345,12 @@ function xmldb_main_upgrade($oldversion=0) {
upgrade_main_savepoint($result, 2007101571.05);
}
+ if ($result && $oldversion < 2007101590.01) {
+ // add media plugins config for ogg and ogv files
+ set_config('filter_mediaplugin_enable_ogv', 1);
+ set_config('filter_mediaplugin_enable_ogg', 1);
+ upgrade_main_savepoint($result, 2007101590.01);
+ }
return $result;
}
View
@@ -5,7 +5,7 @@
function get_file_url($path, $options=null, $type='coursefile') {
global $CFG, $HTTPSPAGEREQUIRED;
- $path = str_replace('//', '/', $path);
+ $path = str_replace('//', '/', $path);
$path = trim($path, '/'); // no leading and trailing slashes
// type of file
@@ -175,11 +175,10 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers2);
}
-
if ($skipcertverify) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
-
+
// use POST if requested
if (is_array($postdata)) {
foreach ($postdata as $k=>$v) {
@@ -404,6 +403,8 @@ function get_mimetypes_array() {
'odf' => array ('type'=>'application/vnd.oasis.opendocument.formula', 'icon'=>'odf.gif'),
'odb' => array ('type'=>'application/vnd.oasis.opendocument.database', 'icon'=>'odb.gif'),
'odi' => array ('type'=>'application/vnd.oasis.opendocument.image', 'icon'=>'odi.gif'),
+ 'ogg' => array ('type'=>'audio/ogg', 'icon'=>'audio.gif'),
+ 'ogv' => array ('type'=>'video/ogg', 'icon'=>'video.gif'),
'pct' => array ('type'=>'image/pict', 'icon'=>'image.gif'),
'pdf' => array ('type'=>'application/pdf', 'icon'=>'pdf.gif'),
@@ -676,7 +677,7 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss
$requiredplayerversion = explode('.', $CFG->excludeoldflashclients);
if (($userplayerversion[0] < $requiredplayerversion[0]) ||
($userplayerversion[0] == $requiredplayerversion[0] && $userplayerversion[1] < $requiredplayerversion[1]) ||
- ($userplayerversion[0] == $requiredplayerversion[0] && $userplayerversion[1] == $requiredplayerversion[1]
+ ($userplayerversion[0] == $requiredplayerversion[0] && $userplayerversion[1] == $requiredplayerversion[1]
&& $userplayerversion[2] < $requiredplayerversion[2])) {
$path = $CFG->dirroot."/lib/flashdetect/flashupgrade.swf"; // Alternate content asking user to upgrade Flash
$filename = "flashupgrade.swf";

0 comments on commit f030e2a

Please sign in to comment.