more URL rewriting

more URL rewriting

by Stan Bogdanov -
Number of replies: 11

Hi Gordon,

currently, I use two methods to do audio and video with HotPot: the simple HTML <object> tag and the dynamic publishing through javascript with JW mediaplayer.

HotPot rewrites the URLs in the <object> tag just fine, but with the dynamic method (code below) it doesn't. It only rewrites the path to the javascript swfobject.js (in green below).

What I'd like HotPot to be able to do (in red in the code) is rewrite the URLs to the .swf, .flv, .xml, .mp3, or .mp4 (if used)

Here's the example:

 1: <script type="text/javascript" src="swfobject.js"></script>
 2: <div id="player">
 3: <a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this movie.
 4: </div>
 5: <script type="text/javascript">
 6:  var s = new SWFObject("flash/flvplayer.swf","flash/movie_file.flv","320","240","9");
 7:  s.addParam("allowfullscreen","true");
 8:  s.addVariable("file","flash/movie_file.flv");
 9:  s.addVariable("displayheight","225");
10:  s.addVariable("backcolor","0x111111");
11:  s.addVariable("frontcolor","0xdddddd");
12:  s.addVariable("lightcolor","0x99cc00");
13:  s.addVariable("width","320");
14:  s.addVariable("height","240");
15:  s.write("player");
16: </script>

OR with an xml playlist

 1: <script type="text/javascript" src="swfobject.js"></script>
 2: <div id="player2" style="margin-left:auto;margin-right:auto;text-align:center;display:block;">
3: <a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this movie.
4: </div> 5: <script type="text/javascript"> 6: var s2 = new SWFObject("player.swf","playlist","340","455","10"); 7: s2.addParam("allowfullscreen","true"); 8: s2.addVariable("file","playlist.xml"); 9: s2.addVariable("displayheight","340"); 10: s2.addVariable("backcolor","0x000000"); 11: s2.addVariable("frontcolor","0xcccccc"); 12: s2.addVariable("lightcolor","0x99cc00"); 13: s2.addVariable("width","340"); 14: s2.addVariable("height","455"); 15: s2.write("player2"); 16: </script>

It should be relatively easy to make HotPot aware of the path to the .swf and .flv files in line 6,
but
how feasible is it to have HotPot rewrite the URLs to the 'file' variable in the javascript code (line 8)
so they point correctly to the .flv, .mp3, or .mp4, .xml?


A bit further, when I upload the xml. playlist, I've got to have the full urls hard-coded - no other way, naturally,
but is it possible, as an option, to apply the same filtering to the xml playlist and rewrite the paths to the absolute URLs in it?


Cheers
Stan
Average of ratings: -
In reply to Stan Bogdanov

Re: more URL rewriting

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Stan,
the rewriting of URLs is certainly possible.

One trick that I have used before is to insert a link to a relative url. HotPot will then convert that to an absolute URL. From the absolute URL you can remove the file name to leave you with the base URL of the folder containing your media files. Then you just add that base URL to the start of the your media URLs.

<script type="type/javascript">
    var a = '<a href="a.htm">';
    if (a.length > 16) {
        var baseurl = 'a.substring(9, a.length - 12)';
    } else {
        var baseurl = ''; // shouldn't happen !!
    }
    var s2 = new SWFObject(baseurl + "player.swf","playlist","340","455","10");
    s2.addVariable("file", baseurl + "playlist.xml");
</script>

If you would like to try something else, please could you make a HotPot activity on my testing server.

thanks !
Gordon

Average of ratings: Useful (1)
In reply to Gordon Bateson

Re: more URL rewriting

by Stan Bogdanov -

Hi Gordon,

I'm afarid I can't get it to work. The only thing that gets re-written is this line

 var a = '<a href="a.htm">';
to
 var a = '<a href="http://full-url.htm">';
Where and what exactly must I do? HotPot doesn't change anything that is inside javascript. Can you provide more detailed instructions please?
Cheers! And thanks!
Stan
In reply to Stan Bogdanov

Re: more URL rewriting

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Stan,
thanks for confirming that the link has been converted to an absolute URL.

Now we can extract tha baseurl from that and use it to convert the media player URLs.

Try this:

  • after this line:
    var a = '<a href="a.htm">';
  • insert this line:
    alert('Length:' + a.length + ', substring = ' + a.substring(9, a.length - 12))
  • adjust the "9" and "12" numbers until you get the right URL, then use those numbers when setting the baseurl variable

If you need further help, please upload the quiz file and its associated media files to a HotPot activity on my server:

all the best
Gordon

Average of ratings: Useful (1)
In reply to Gordon Bateson

Re: more URL rewriting

by Stan Bogdanov -

Hi Gordon,

after some guess work with the numbers, this is what the alert pop-up says: 

Length:94, substring = http://www.server.com/moodle/pluginfile.php/217/mod_hotpot/sourcefile/a.htm

What's next?

Cheers

Stan

In reply to Stan Bogdanov

Re: more URL rewriting

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

> What's next?

Hmm, if you are asking me that, then I don't think you have yet grasped what we are tryng to do. Please set up the files as a HotPot on my server, and I will show you what I mean.

Gordon

In reply to Gordon Bateson

Re: more URL rewriting

by Stan Bogdanov -

Frankly, I've no idea what I'm doing! Too much work recently and my multitasking skills are failing me.

I removed the alert line in the hope that the urls will now get rewritten, but to no avail.

I'll upload the exercise in question to your server so we could both look at it.

Cheers. And thanks.

Stan

Edit: Just uploaded ...

In reply to Stan Bogdanov

Re: more URL rewriting

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Thanks for uploading the exercise Stan.

I have changed the javascript a little ...

  • removed the double-slash comment "//"
  • changed the numbers in the subscript() function

And now I think it'll work. At least I can say that the javascript extracts the correct baseurl from the link, and adds it to the urls for the swf and xml files.

When I tried actually viewing the quiz via Moodle 2.2, I must confess I ran into problems. The player appeared but there seemed to be a problem downloading the xml file. When I tried to then edit the quiz in Moodle, the file picker for the source file seemed to be caught in a loop as if it was unable to find the files on the server. Not sure why ?

Anyway, I attach the modified exercise.htm. It should work inside and outside of Moodle - any Moodle, not just Moodle 2.x but also Moodle 1.x, and not just the HotPot module, but the QuizPort and TaskChain modules too.

Please let me know how you get on.

regards
Gordon

Average of ratings: Useful (1)
In reply to Gordon Bateson

Re: more URL rewriting

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Stan,

I think I have found the cause of the player not playing, and that is that the URLs in playlist.xml need to be relative to the domain root, but there is no way using javascript to convert them to what they should be.

The only immediate workaround would be to convert the URLs yourself. I thnk this is what you had done, so probably the playlist.xml you supplied file would work on your Moodle site, but not on mine.

The long term solution would be to develop the player so that if the URLs in the playlist.xml are relative URLs, it would use the base url of the player, i.e. the swf file, not the baseurl of the page, i.e. the HotPot activity, as the baseurl for the media files.

cheers
Gordon

Average of ratings: Useful (1)
In reply to Gordon Bateson

Re: more URL rewriting

by Stan Bogdanov -

Hi Gordon,

I was just about to say the same. One needs to have the absolute urls in the playlist xml, where the urls to the sound files and the thumbs live. The file I uploaded to your test server has relative urls like this: pluginfile.php/217/mod_hotpot/sourcefile/sound-file.mp3

I have the absolute urls on my server and I confirm that it works perfectly on my Moodle 2.2!

I uploaded the playlist.xml with the absolute url of your server to your server and it plays just as perfectly as well! You can now enjoy the music!

Thank you Gordon, this is just great!

I believe this adds to the numerous amazing things HotPot and Quizport do. And you'll take them further into TaskChain!

Cheers

Stan

In reply to Gordon Bateson

Re: more URL rewriting

by Stan Bogdanov -

Gordon,

Re: the file picker for the source file seemed to be caught in a loop

That happend when I was uploading the mp3 which is about 2,5Mb. The loop took a bit longish but I just waited and it eventually refreshed and I saw the file had been uploaded.

Cheers

Stan

Average of ratings: Useful (1)