Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: Filters.

Development:Filters: Difference between revisions

From MoodleDocs
No edit summary
 
No edit summary
Line 1: Line 1:
'''Darek'''  
'''Please note:''' This page contains information for developers. You may wish to read the [[Filters | information about filters for teachers and administrators]].
== Headline text ==
 
----
-----
[[Link title]]
 
----
'''Filters''' allow for the for the automatic transformation of entered text into different, often more complex forms. For example the titles of [[Resources]] can automatically become hyperlinks that take you to the relevant resource, URLs pointing to [[mp3]] files can become [[Flash]] controls embedded in the webpage that let you pause and rewind the audio. The possibilities are endless and there are a number of standard filters included with Moodle and many more specialized filters contributed by the community.
''Italic text''
 
[http://www.onet.pl link onet]
 
==To create a filter==
 
To create a filter that removes all occurrences of the letter "x" - we'll call it "removex":
 
# Create a new folder inside Moodle's /filter/ folder, called "removex"
# Create a new PHP script file inside the folder you've just created - name it "filter_removex.php"
# Write a new PHP function in this file, called "filter_removex()" which takes two parameters - a piece of text to be filtered and a course ID - and returns the processed text.
 
For our example the function would look like:
 
function filter_removex($text, $courseid) {
    return str_replace('x', '', $text);
}
 
When trying this out, remember to make sure that you activate the filter in Moodle's admin screen.
 
==See also==
 
* [[Filters schema]] - a page containing some ideas and thoughts about modifications to the filters system
* [[Text filters]] - description for teachers/administrators

Revision as of 18:49, 31 March 2006

Please note: This page contains information for developers. You may wish to read the information about filters for teachers and administrators.


Filters allow for the for the automatic transformation of entered text into different, often more complex forms. For example the titles of Resources can automatically become hyperlinks that take you to the relevant resource, URLs pointing to mp3 files can become Flash controls embedded in the webpage that let you pause and rewind the audio. The possibilities are endless and there are a number of standard filters included with Moodle and many more specialized filters contributed by the community.


To create a filter

To create a filter that removes all occurrences of the letter "x" - we'll call it "removex":

  1. Create a new folder inside Moodle's /filter/ folder, called "removex"
  2. Create a new PHP script file inside the folder you've just created - name it "filter_removex.php"
  3. Write a new PHP function in this file, called "filter_removex()" which takes two parameters - a piece of text to be filtered and a course ID - and returns the processed text.

For our example the function would look like:

function filter_removex($text, $courseid) {
    return str_replace('x', , $text);
}

When trying this out, remember to make sure that you activate the filter in Moodle's admin screen.

See also

  • Filters schema - a page containing some ideas and thoughts about modifications to the filters system
  • Text filters - description for teachers/administrators