예제 #1
0
    function test_filter_mediaplugin_link()
    {
        $this->resetAfterTest(true);
        // we need to enable the plugins somehow and the flash fallback.
        \core\plugininfo\media::set_enabled_plugins('vimeo,youtube,videojs,html5video,swf,html5audio');
        set_config('useflash', true, 'media_videojs');
        $filterplugin = new filter_mediaplugin(null, array());
        $longurl = '<a href="http://moodle/.mp4">my test file</a>';
        $longhref = '';
        do {
            $longhref .= 'a';
        } while (strlen($longhref) + strlen($longurl) < 4095);
        $longurl = '<a href="http://moodle/' . $longhref . '.mp4">my test file</a>';
        $validtexts = array('<a href="http://moodle.org/testfile/test.mp3">test mp3</a>', '<a href="http://moodle.org/testfile/test.ogg">test ogg</a>', '<a id="movie player" class="center" href="http://moodle.org/testfile/test.mp4">test mp4</a>', '<a href="http://moodle.org/testfile/test.webm">test</a>', '<a href="http://www.youtube.com/watch?v=JghQgA2HMX8" class="href=css">test file</a>', '<a href="http://www.youtube-nocookie.com/watch?v=JghQgA2HMX8" class="href=css">test file</a>', '<a href="http://youtu.be/JghQgA2HMX8" class="href=css">test file</a>', '<a href="http://y2u.be/JghQgA2HMX8" class="href=css">test file</a>', '<a class="youtube" href="http://www.youtube.com/watch?v=JghQgA2HMX8">test file</a>', '<a class="_blanktarget" href="http://moodle.org/testfile/test.flv?d=100x100">test flv</a>', '<a class="hrefcss" href="http://www.youtube.com/watch?v=JghQgA2HMX8">test file</a>', '<a  class="content"     href="http://moodle.org/testfile/test.ogg">test ogg</a>', '<a     id="audio"      href="http://moodle.org/testfile/test.mp3">test mp3</a>', '<a  href="http://moodle.org/testfile/test.mp3">test mp3</a>', '<a     href="http://moodle.org/testfile/test.mp3">test mp3</a>', '<a     href="http://www.youtube.com/watch?v=JghQgA2HMX8?d=200x200">youtube\'s</a>', '<a
                            href="http://moodle.org/testfile/test.mp3">
                            test mp3</a>', '<a                         class="content"


                            href="http://moodle.org/testfile/test.wav">test wav
                                    </a>', '<a             href="http://www.youtube.com/watch?v=JghQgA2HMX8?d=200x200"     >youtube\'s</a>', $longurl);
        //test for valid link
        foreach ($validtexts as $text) {
            $msg = "Testing text: " . $text;
            $filter = $filterplugin->filter($text);
            $this->assertNotEquals($text, $filter, $msg);
        }
        $insertpoint = strrpos($longurl, 'http://');
        $longurl = substr_replace($longurl, 'http://pushover4096chars', $insertpoint, 0);
        $originalurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;">' . '<a href="https://www.youtube.com/watch?v=uUhWl9Lm3OM">Valid link</a></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">';
        $paddedurl = str_pad($originalurl, 6000, 'z');
        $validpaddedurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;"><span class="mediaplugin mediaplugin_youtube">
<iframe title="Valid link" width="400" height="300"
  src="https://www.youtube.com/embed/uUhWl9Lm3OM?rel=0&amp;wmode=transparent" frameborder="0" allowfullscreen="1"></iframe>
</span></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">';
        $validpaddedurl = str_pad($validpaddedurl, 6000 + (strlen($validpaddedurl) - strlen($originalurl)), 'z');
        $invalidtexts = array('<a class="_blanktarget">href="http://moodle.org/testfile/test.mp3"</a>', '<a>test test</a>', '<a >test test</a>', '<a     >test test</a>', '<a >test test</a>', '<ahref="http://moodle.org/testfile/test.mp3">sample</a>', '<a href="" test></a>', '<a href="http://www.moodle.com/path/to?#param=29">test</a>', '<a href="http://moodle.org/testfile/test.mp3">test mp3', '<a href="http://moodle.org/testfile/test.mp3"test</a>', '<a href="http://moodle.org/testfile/">test</a>', '<href="http://moodle.org/testfile/test.avi">test</a>', '<abbr href="http://moodle.org/testfile/test.mp3">test mp3</abbr>', '<ahref="http://moodle.org/testfile/test.mp3">test mp3</a>', '<aclass="content" href="http://moodle.org/testfile/test.mp3">test mp3</a>', $longurl);
        //test for invalid link
        foreach ($invalidtexts as $text) {
            $msg = "Testing text: " . $text;
            $filter = $filterplugin->filter($text);
            $this->assertEquals($text, $filter, $msg);
        }
        // Valid mediaurl followed by a longurl.
        $precededlongurl = '<a href="http://moodle.org/testfile/test.mp3">test.mp3</a>' . $longurl;
        $filter = $filterplugin->filter($precededlongurl);
        $this->assertEquals(1, substr_count($filter, '</audio>'));
        $this->assertContains($longurl, $filter);
        // Testing for cases where: to be filtered content has 6+ text afterwards.
        $filter = $filterplugin->filter($paddedurl);
        $this->assertEquals($validpaddedurl, $filter, $msg);
    }
예제 #2
0
 /**
  * Obtains the list of core_media_player objects currently in use to render
  * items.
  *
  * The list is in rank order (highest first) and does not include players
  * which are disabled.
  *
  * @return core_media_player[] Array of core_media_player objects in rank order
  */
 protected function get_players()
 {
     // Save time by only building the list once.
     if (!$this->players) {
         // Get raw list of players.
         $allplayers = $this->get_players_raw();
         $sortorder = \core\plugininfo\media::get_enabled_plugins();
         $this->players = [];
         foreach ($sortorder as $key) {
             if (array_key_exists($key, $allplayers)) {
                 $this->players[] = $allplayers[$key];
             }
         }
     }
     return $this->players;
 }
예제 #3
0
 /**
  * Returns if the current player is enabled.
  *
  * @deprecated since Moodle 3.2
  * @return bool True if player is enabled
  */
 public function is_enabled()
 {
     debugging('Function core_media_player::is_enabled() is deprecated without replacement', DEBUG_DEVELOPER);
     $enabled = \core\plugininfo\media::get_enabled_plugins();
     if ($enabled && preg_match('/^media_(.*)_plugin$/', get_class($this), $matches)) {
         return array_key_exists($matches[1], $enabled);
     }
     return false;
 }
예제 #4
0
 /**
  * Assert other players do not apply after videojs was applied.
  */
 public function test_prevent_other_players()
 {
     \core\plugininfo\media::set_enabled_plugins('videojs,html5video');
     $url = new moodle_url('http://example.org/some_filename.webm');
     $text = html_writer::link($url, 'Apply one player only');
     $content = format_text($text, FORMAT_HTML);
     $this->assertRegExp('~mediaplugin_videojs~', $content);
     $this->assertEquals(1, substr_count($content, '</video>'));
     $this->assertNotRegExp('~mediaplugin_html5video~', $content);
     $this->assertRegExp('~<a class="mediafallbacklink" href="http://example.org/some_filename.webm">Apply one player only</a>~', $content);
 }
예제 #5
0
    $filterplugin->filter($sample);
}
filter_mediaplugin_perf_stop('No links');
// Second test: filter text with one link added (that doesn't match).
$link = '<a href="http://www.example.org/another/link/">Link</a>';
$linksamples = array();
foreach ($samplebank as $sample) {
    // Make it the same length but with $link replacing the end part.
    $linksamples[] = substr($sample, 0, -strlen($link)) . $link;
}
filter_mediaplugin_perf_start();
foreach ($linksamples as $sample) {
    $filterplugin->filter($sample);
}
filter_mediaplugin_perf_stop('One link (no match)');
// Third test: filter text with one link added that does match (mp3).
$link = '<a href="http://www.example.org/another/file.mp3">MP3 audio</a>';
$linksamples = array();
foreach ($samplebank as $sample) {
    // Make it the same length but with $link replacing the end part.
    $linksamples[] = substr($sample, 0, -strlen($link)) . $link;
}
filter_mediaplugin_perf_start();
foreach ($linksamples as $sample) {
    $filterplugin->filter($sample);
}
filter_mediaplugin_perf_stop('One link (mp3)');
\core\plugininfo\media::set_enabled_plugins($enabledmediaplugins);
// End page.
echo html_writer::end_tag('ul');
print $OUTPUT->footer();
예제 #6
0
 /**
  * Test that plugin is returned as enabled media plugin.
  */
 public function test_is_installed()
 {
     $sortorder = \core\plugininfo\media::get_enabled_plugins();
     $this->assertEquals(['swf' => 'swf'], $sortorder);
 }
예제 #7
0
파일: locallib.php 프로젝트: rezaies/moodle
/**
 * Verifies sloppy swf embedding - this should have been removed long ago!!
 * @param bool $detailed
 * @return object result
 */
function report_security_check_mediafilterswf($detailed=false) {
    global $CFG;

    $result = new stdClass();
    $result->issue   = 'report_security_check_mediafilterswf';
    $result->name    = get_string('check_mediafilterswf_name', 'report_security');
    $result->info    = null;
    $result->details = null;
    $result->status  = null;
    $result->link    = "<a href=\"$CFG->wwwroot/$CFG->admin/settings.php?section=managemediaplayers\">" .
        get_string('managemediaplayers', 'media') . '</a>';

    $activefilters = filter_get_globally_enabled();

    $enabledmediaplayers = \core\plugininfo\media::get_enabled_plugins();
    if (array_search('mediaplugin', $activefilters) !== false and array_key_exists('swf', $enabledmediaplayers)) {
        $result->status = REPORT_SECURITY_CRITICAL;
        $result->info   = get_string('check_mediafilterswf_error', 'report_security');
    } else {
        $result->status = REPORT_SECURITY_OK;
        $result->info   = get_string('check_mediafilterswf_ok', 'report_security');
    }

    if ($detailed) {
        $result->details = get_string('check_mediafilterswf_details', 'report_security');
    }

    return $result;
}
예제 #8
0
 /**
  * Obtains the list of core_media_player objects currently in use to render
  * items.
  *
  * The list is in rank order (highest first) and does not include players
  * which are disabled.
  *
  * @return core_media_player[] Array of core_media_player objects in rank order
  */
 protected function get_players()
 {
     // Save time by only building the list once.
     if (!$this->players) {
         $sortorder = \core\plugininfo\media::get_enabled_plugins();
         $this->players = [];
         foreach ($sortorder as $name) {
             $classname = "media_" . $name . "_plugin";
             if (class_exists($classname)) {
                 $this->players[] = new $classname();
             }
         }
     }
     return $this->players;
 }
예제 #9
0
파일: media.php 프로젝트: lucaboesch/moodle
$plugins = core_plugin_manager::instance()->get_plugins_of_type('media');
$sortorder = array_values(\core\plugininfo\media::get_enabled_plugins());
$return = new moodle_url('/admin/settings.php', array('section' => 'managemediaplayers'));
if (!array_key_exists($media, $plugins)) {
    redirect($return);
}
switch ($action) {
    case 'disable':
        $plugins[$media]->set_enabled(false);
        break;
    case 'enable':
        $plugins[$media]->set_enabled(true);
        break;
    case 'up':
        if (($pos = array_search($media, $sortorder)) > 0) {
            $tmp = $sortorder[$pos - 1];
            $sortorder[$pos - 1] = $sortorder[$pos];
            $sortorder[$pos] = $tmp;
            \core\plugininfo\media::set_enabled_plugins($sortorder);
        }
        break;
    case 'down':
        if (($pos = array_search($media, $sortorder)) !== false && $pos < count($sortorder) - 1) {
            $tmp = $sortorder[$pos + 1];
            $sortorder[$pos + 1] = $sortorder[$pos];
            $sortorder[$pos] = $tmp;
            \core\plugininfo\media::set_enabled_plugins($sortorder);
        }
        break;
}
redirect($return);