Skip to content

Commit

Permalink
filter/mediaplugin MDL-19006 Add auto-embedding of images that are li…
Browse files Browse the repository at this point in the history
…nked to.
  • Loading branch information
moodler committed Apr 29, 2009
1 parent ea78989 commit c159f28
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions filter/mediaplugin/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ function filter($text) {
$newtext = preg_replace_callback($search, 'mediaplugin_filter_youtube_callback', $newtext);
}

if ($CFG->filter_mediaplugin_enable_img) {
$search = '/<a.*?href="([^<]+\.jpg)"[^>]*>(.*?)<\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_img_callback', $newtext);
$search = '/<a.*?href="([^<]+\.png)"[^>]*>(.*?)<\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_img_callback', $newtext);
$search = '/<a.*?href="([^<]+\.gif)"[^>]*>(.*?)<\/a>/is';
$newtext = preg_replace_callback($search, 'mediaplugin_filter_img_callback', $newtext);
}

if (empty($newtext) or $newtext === $text) {
// error or not filtered
unset($newtext);
Expand Down Expand Up @@ -230,6 +239,16 @@ class="mediaplugin mediaplugin_youtube" type="application/x-shockwave-flash"
'</object>';
}

/**
* Change links to images into embedded images
*/
function mediaplugin_filter_img_callback($link, $autostart=false) {
$url = addslashes_js($link[1]);
$info = addslashes_js($link[2]);

return '<img class="mediaplugin mediaplugin_img" alt="" title="'.$info.'" src="'.$url.'" />';
}

/**
* Embed video using window media player if available
*/
Expand Down
2 changes: 2 additions & 0 deletions filter/mediaplugin/filtersettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@

$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_youtube', get_string('mediapluginyoutube','admin'), '', 1));

$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_img', get_string('mediapluginimg','admin'), '', 1));

?>
1 change: 1 addition & 0 deletions lang/en_utf8/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
$string['mediapluginrpm'] = 'Enable .rpm filter';
$string['mediapluginswf'] = 'Enable .swf filter';
$string['mediapluginyoutube'] = 'Enable YouTube links filter';
$string['mediapluginimg'] = 'Enable auto-embedding of linked images';
$string['mediapluginswfnote'] = 'As a default security measure, normal users should not be allowed to embed swf flash files.';
$string['mediapluginwmv'] = 'Enable .wmv filter';
$string['memcachedhosts'] = 'memcached hosts';
Expand Down

0 comments on commit c159f28

Please sign in to comment.