Adding SpeakPipe selectively to your Moodle pages

Adding SpeakPipe selectively to your Moodle pages

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

Hi y'all!

I've just discovered SpeakPipe.com as an interesting way to get immediate voice recording feedback from surfers.

I've enabled it for my Moodle site, but I notice that the recording icon appears on each and every page of my Moodle site. 

Is there any way of making the recording icon appear selectively on certain Moodle pages only. For example, I want it to appear when the student is doing a Moodle quiz. Or when the student accesses a particular Forum page. What is the Moodle php code that allows me to distinguish one Moodle resource page from another? I want to write php code to detect the name of the current php file being accessed, and if it is Forum so and so, then only the SpeakPipe recorder will protrude from the right side of my Moodle site.

Any help or pointers will be most appreciated. And to anyone or everyone who gives some pointers on the code, I will make a special attribution mention of you and your code/help on Moodlenews.com once I manage to blog about it.

Exploring the possiblities.
Frankie Kam

APPENDIX

How it works is I embed the SpeakPipe code just above the </body> close tag of header.html of my theme.

...
<!-- Begin SpeakPipe code -->
<script type="text/javascript">
(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);
</script>
<!-- End SpeakPipe code -->
</body>

Is there a way to do this (in pseudocode):

if(resource is a Moodle Forum on Green Computing)
{
<!-- Begin SpeakPipe code -->

<script type="text/javascript">
(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);
</script>
<!-- End SpeakPipe code -->

}
</body>

Average of ratings: -
In reply to Frankie Kam

Re: Adding SpeakPipe selectively to your Moodle pages

by Frankie Kam -
Picture of Plugin developers

Dear All

Okay, I got it, all thanks to a certain Howard Miller who inspired me to love cats and to .... get the solution.
See: http://moodle.org/mod/forum/discuss.php?d=208602#p909301

And the code that I used is duplicated here:

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.

 

What are the possibilities now? Well I could created several SpeakPipe accounts, each with their own embed code.
So I could have one SpeakPipe used for whenever the user is accessing a Moodle forum (because I check for the substring
"forum"), and yet another SpeakPipe for when the user is on a quiz page (by checking for the substring "quiz").
And then I could check for the specific resource based on whether the id of the resource is detected or not.
For example, if I wanted the SpeakPipe to be activated not by all forums, but only by a forum with id 3885, as in the URL:
http://www.moodurian.com/mod/forum/view.php?id=3885
t
hen I could check if the substring "forum" and substring "id=3885" appears in the partial URL returned by the me() PHP function!

Ah yes, I am just wondering if the possibilities this opens up.

The drawback is that the header.html file content could get cluttered with hardcoded code just checking for resource types
or resource ids.

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

All this has got me thinking of how to go one notch higher: what other Web2.0 resource like SpeakPipe can I embed inside my
Moodle pages, that I can selectively turn on or turn off? This is getting more interesting.....hmm.....what do you think?

Regards
Frankie Kam
Malaysia
http://moodurian.blogspot.com

In reply to Frankie Kam

Re: Adding SpeakPipe selectively to your Moodle pages

by Hubert Chathi -

If you are using Moodle 2.x, you should be able to fetch all sorts of useful information from the $PAGE global.  Look at the phpdoc header in lib/pagelib.php.  All the "@property-read" items are attributes that you can read from $PAGE.  In particular, $PAGE->activityname and $PAGE->course may be of interest to you.