Can theme code in the header.html detect Moodle resources and dynamically execute embed code?

Can theme code in the header.html detect Moodle resources and dynamically execute embed code?

by Frankie Kam -
Number of replies: 4
Picture of Plugin developers

I've asked this question on the General Developer's FOrum, but so far zilch. So I thought maybe some theme designer might be able to help.

Basically I have an embed code pasted just above the </body> tag of my theme's header.html file. Is there anyway of my header.html code detecting that, oh the student's now in a Moodle forum, let's enable that embed code. Oh, the student's now accessing  a Moodle quiz page, now don't load that embed code. Something like that.

Too vague? This should be clearer:
http://moodle.org/mod/forum/discuss.php?d=208569

Anyone?

Frankie "DurianMan" Kam

Average of ratings: -
In reply to Frankie Kam

Re: Can theme code in the header.html detect Moodle resources and dynamically execute embed code?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Which version of Moodle are we talking about? I'm assuming you mean 1.9 as 2.x doesn't have a header.html.

You have access to the URL and the parameters for the page you are displaying so, yes, you can work out what sort of page it is and fiddle with the layout/header.

A forum will always look something like http://path.to/moodle/mod/forum/view.php. You can grab that through the me() and qualified_me() functions from lib/weblib.php.
In reply to Howard Miller

Re: Can theme code in the header.html detect Moodle resources and dynamically execute embed code?

by Frankie Kam -
Picture of Plugin developers

Hi Howard!

Ah, I didn't know that the me() and qualified_me() functions existed. So now I have something to start with. Thank you for your speedy reply.

Frankie Kam
P.S., Say hello to your cats for me. I don't know what you look like, but at least I know what one of your cats look like. LOL! wink

In reply to Frankie Kam

Re: Can theme code in the header.html detect Moodle resources and dynamically execute embed code?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Just to put a downer on things that's a deceased cat now, but there are another five where that came from.... it's my wife not me tongueout
In reply to Howard Miller

Re: Can theme code in the header.html detect Moodle resources and dynamically execute embed code?

by Frankie Kam -
Picture of Plugin developers

Hi Howard

Sorry to hear about the late great cat. <a moment of silence, with head bowed down briefly>
...

<Head lifted up again>
Anyway, the Good News is that I achieved what I sought out to do! Here's the code snippet of my Moodle theme's header.html file:

<body>
...

<?php

$haystack = me();
$needle = "forum";
$pos = strpos(strtolower($haystack),strtolower($needle));
//echo $pos;
if($pos === false) {
// string needle NOT found in haystack
// do nothing!

}
else {
// string needle found in haystack
// so, go ahead and activate the embed code!
echo "<script type='text/javascript'>";

echo "(function(d){
var app = d.createElement('script'); app.type = 'text/javascript'; app.async = true;
var pt = ('https:' == document.location.protocol ? 'https://' : 'http://');
app.src = pt + 'www.speakpipe.com/loader/7si4wqs7jgqocgr318inx135q75ovcmg.js';
var s = d.getElementsByTagName('script')[0]; s.parentNode.insertBefore(app, s);
})(document);";
echo"</script>";
}
?>
</body>
...

You can test it out here:

http://www.moodurian.com/mod/forum/view.php?id=3885
and the SpeakPipe voice recorder gets activated! See below image, right edge.


-OR-

http://www.moodurian.com 
(or any part of the website that does not have the word "forum" in its URL) and
the SpeakPipe embed code is not activated! It's nowhere to be seen.


Chalk up another success in Moodle coding and doing what was previously not
thought possible (at least by me!). All thanks to you, Howard!


Regards
Frankie Kam