Filter in 1.6 not working

Filter in 1.6 not working

by kevin metcalf -
Number of replies: 3
I may be missing something obvious, but I'm unable to create the simplist of filters.

I'm simplifying what I really want to do in order to make it more obvious what's happening...  I want to replace every occurance of a word (let's say "cat") within a URL linked from my moodle server with another word (let's say "dog.")  For example Topic 1 in a course has the following HTML (I've removed the space between a and href because the forum wants to translate it for me. GRRRR):
<ahref="rtsp://somesite.streams.com/mystreamfolder/cat/video1.rm">Video 1</a>

I want it to say:
<ahref="rtsp://somesite.streams.com/mystreamfolder/dog/video1.rm">Video 1</a>

I have 100 courses that each have 20 links.  I want to update just one filter every quarter and have all the animal names changed.

So here's what I did.  I followed the instructions here:
http://docs.moodle.org/en/Filters_%28developer%29
which did nothing.  Allow me to elaborate...

I made a folder called wordreplace and put the following files in it:

filter_wordreplace.php
function filter_wordreplace($text, $courseid) {
        return str_replace($CFG->filter_wordreplace_old, $CFG->filter_wordreplace_new, $text);
}

filterconfig.html
<?PHP
 echo "Swap out...<br />\n";
 echo "<input type="text" name="filter_wordreplace_old" size="60" value="$CFG->filter_wordreplace_old"><br />";
 echo "With...<br />\n";
 echo "<input type="text" name="filter_wordreplace_new" size="60" value="$CFG->filter_wordreplace_new">";
?>


I went to the filter admin area, and could not find anything there about the "wordreplace" filter.  I went rooting around in the /admin/filters.php file and figured out I probably should be using "filter.php" instead of "filter_wordreplace.php"  So I changed the filename from "filter_wordreplace.php" to "filter.php" and that allowed me to see everything on the admin screen.  I enabled the filter and put "dog" and "cat" in their respective locations, but it didn't replace the text like I wanted it to.  It just added the function (in plaintext) to text to the top of every course.  I wrapped the function in PHP tags and that got rid of the function text at the top of every course, but the function still doesn't work.

I'm at a loss.  Has anyone built a working filter in 1.6?  Can someone give me some pointers about what I might be doing wrong?
Average of ratings: -
In reply to kevin metcalf

Re: Filter in 1.6 not working

by kevin metcalf -
OK.  The documentation I followed is either out of date or just wrong.  I finally got it working.  How do I go about updating the documentation to make it right?  I tried clicking on 'edit' but I guess I don't have permission.

Will someone else edit it, or should I just email my instructions to Martin?
In reply to kevin metcalf

Re: Filter in 1.6 not working

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Which page? You should be able to edit anything in the docs if you're logged in.
In reply to Martin Dougiamas

Re: Filter in 1.6 not working

by kevin metcalf -
AH!  Got it.  I had to login twice.  I think there might be a weird issue with my browser.  Odd...

Anyway, I've updated the docs on the Filters (Developer) page ( http://docs.moodle.org/en/Filters_(developer) ) to reflect the appropriate functionallity of the system.

Changed:
* The order of the function parameters for passing data to filters.
* The filename for the filter.
* Modified example script to include PHP tags for easier viewing.