Exemple #1
0
 function adjust_media_urls()
 {
     if ($this->forceplugins) {
         // make sure the Moodle media plugin is available
         global $CFG;
         //include_once "$CFG->dirroot/filter/mediaplugin/filter.php";
         include_once "{$CFG->dirroot}/mod/hotpot/mediaplayers/moodle/filter.php";
         $space = '\\s(?:.+\\s)?';
         $quote = '["' . "']?";
         // single, double, or no quote
         // patterns to media files types and paths
         $filetypes = "avi|mpeg|mpg|mp3|mov|wmv|flv";
         if ($CFG->filter_mediaplugin_enable_swf) {
             $filetypes .= '|swf';
         }
         $filepath = '[^"' . "']*" . '\\.(?:' . $filetypes . ')[^"' . "']*";
         $tagopen = '(?:(<)|(\\\\u003C))';
         // left angle-bracket (uses two parenthese)
         $tagchars = '(?(1)[^>]|(?(2).(?!\\\\u003E)))*?';
         // string of chars inside the tag
         $tagclose = '(?(1)>|(?(2)\\\\u003E))';
         // right angle-bracket (to match the left one)
         $tagreopen = '(?(1)<|(?(2)\\\\u003C))';
         // another left angle-bracket (to match the first one)
         // pattern to match <param> tags which contain the file path
         $param_names = 'movie|src|url|flashvars';
         //  wmp        : url
         //  quicktime  : src
         //  realplayer : src
         //  flash      : movie, flashvars
         $param_url = '/' . $tagopen . 'param' . '\\s' . $tagchars . 'name="(?:' . $param_names . ')"' . $tagchars . 'value="(' . $filepath . ')"' . $tagchars . $tagclose . '/is';
         // pattern to match <a> tags which link to multimedia files
         $link_url = '/' . $tagopen . 'a' . '\\s' . $tagchars . 'href="(' . $filepath . ')"' . $tagchars . $tagclose . '.*?' . $tagreopen . '\\/a' . $tagclose . '/is';
         // extract <object> tags
         $object_tag = '/' . $tagopen . 'object' . '\\s' . $tagchars . $tagclose . '(.*?)' . '(?:' . $tagreopen . '\\/object' . $tagclose . ')+/is';
         preg_match_all($object_tag, $this->html, $objects);
         $i_max = count($objects[0]);
         for ($i = 0; $i < $i_max; $i++) {
             // extract URL from <param> or <a>
             $url = '';
             if (preg_match($param_url, $objects[3][$i], $matches) || preg_match($link_url, $objects[3][$i], $matches)) {
                 $url = $matches[3];
             }
             if ($url) {
                 // strip inner tags (e.g. <embed>)
                 $txt = preg_replace("/{$tagopen}.*?{$tagclose}/", '', $objects[3][$i]);
                 // if url is in the query string, remove the leading characters
                 $url = preg_replace('/^([^=]+=[^&]*&)*[^=]+=(http:[^&]*)$/', '$2', $url, 1);
                 $link = '<a href="' . $url . '">' . $txt . '</a>';
                 $new_object = hotpot_mediaplayer_moodle($this, $link);
                 $new_object = str_replace($link, '', $new_object);
                 $new_object = str_replace('&amp;', '&', $new_object);
                 $this->html = str_replace($objects[0][$i], $new_object, $this->html);
             }
         }
     }
 }
Exemple #2
0
 function adjust_media_urls()
 {
     if ($this->forceplugins) {
         // make sure the Moodle media plugin is available
         global $CFG;
         //include_once "$CFG->dirroot/filter/mediaplugin/filter.php";
         include_once "{$CFG->dirroot}/mod/hotpot/mediaplayers/moodle/filter.php";
         $space = '\\s(?:.+\\s)?';
         $quote = '["' . "']?";
         // single, double, or no quote
         // patterns to media files types and paths
         $filetype = "avi|mpeg|mpg|mp3|mov|wmv|flv";
         if ($CFG->filter_mediaplugin_enable_swf) {
             $filetype .= '|swf';
         }
         $filepath = ".*?\\.({$filetype})";
         $tagopen = '(?:(<)|(\\\\u003C))';
         // left angle-bracket (uses two parenthese)
         $tagclose = '(?(1)>|(?(2)\\\\u003E))';
         // right angle-bracket (to match the left one)
         $tagreopen = '(?(1)<|(?(2)\\\\u003C))';
         // another left angle-bracket (to match the first one)
         // pattern to match <PARAM> tags which contain the file path
         //  wmp        : url
         //  quicktime  : src
         //  realplayer : src
         //  flash      : movie (doesn't need replacing)
         $param_url = "/{$tagopen}param{$space}name={$quote}(?:movie|src|url){$quote}{$space}value={$quote}({$filepath}){$quote}.*?{$tagclose}/is";
         // pattern to match <a> tags which link to multimedia files
         $link_url = "/{$tagopen}a{$space}href={$quote}({$filepath}){$quote}.*?{$tagclose}.*?{$tagreopen}\\/a{$tagclose}/is";
         // extract <object> tags
         preg_match_all("/{$tagopen}object.*?{$tagclose}(.*?)(?:{$tagreopen}\\/object{$tagclose})+/is", $this->html, $objects);
         $i_max = count($objects[0]);
         for ($i = 0; $i < $i_max; $i++) {
             // extract URL from <PARAM> or <A>
             $url = '';
             if (preg_match($param_url, $objects[3][$i], $matches) || preg_match($link_url, $objects[3][$i], $matches)) {
                 $url = $matches[3];
             }
             if ($url) {
                 // strip inner tags (e.g. <embed>)
                 $txt = preg_replace("/{$tagopen}.*?{$tagclose}/", '', $objects[3][$i]);
                 // if url is in the query string, remove the leading characters
                 $url = preg_replace('/^[^?]*\\?([^=]+=[^&]*&)*[^=]+=([^&]*)$/', '$2', $url, 1);
                 $link = '<a href="' . $url . '">' . $txt . '</a>';
                 $new_object = hotpot_mediaplayer_moodle($this, $link);
                 $new_object = str_replace($link, '', $new_object);
                 $new_object = str_replace('&amp;', '&', $new_object);
                 $this->html = str_replace($objects[0][$i], $new_object, $this->html);
             }
         }
     }
 }