Traq Project Forums

Full Version: Creating Plugins for Traq 0.5 and earlier
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
----------------------------------------------------------
NOTICE: In version 0.6 the methods in this example plugin won't work as the updated plugin API doesn't have a filter function. When 0.6 is close to being released this post will be updated.
----------------------------------------------------------

Creating a plugin for Traq is quite easy, all you need to do is copy and paste the code below, which is needed in all plugins.

PHP Code:
<?php
/**
 * Plugin Info
 * Author: Your Name
 * Name: Plugin Name
 * Info: Plugin Description
 * Version: Plugin Version
 */

?>

Now that the base of the plugin file is created it will show up in the AdminCP.
Next we need to create our plugin functions.

I want to create a plugin that will filter out bad words wherever the formattext() function is used.

To do this we need to find a plugin hook in the function, the plugin hook used is a Filter:
PHP Code:
$text FishHook::filter('common_formattext_text',$text); 

Now for our plugin to use that hook we need to create a function with the code to filter bad words:

PHP Code:
function filterbadwords($text) {
    
$badwords = array('shit' => 'sh**',
                      
'asshole' => 'a******',
                      );
    
$text str_replace(array_keys($badwords),array_values($badwords),$text);
    return 
$text;
}
FishHook::add('filterbadwords','common_formattext_text',true); 

The FishHook::add() function has 3 things that can be passed to it, the function to run, the hook name and true or false if its a filter or not.

And here is our plugin:
PHP Code:
<?php
/**
 * Plugin Info
 * Author: Jack Polgar
 * Name: Filter Bad Words
 * Info: Filters bad words and replaces them with ****
 * Version: 1.0
 */

function filterbadwords($text) {
    
$badwords = array('shit' => 'sh**',
                      
'asshole' => 'a******',
                      );
    
$text str_replace(array_keys($badwords),array_values($badwords),$text);
    return 
$text;
}
FishHook::add('filterbadwords','common_formattext_text',true);
?>
_______________________________________________
Please note that in version 0.5 there aren't a lot of plugin hooks,
I will be adding as many as I can in 0.6. If you wish to request plugin hooks create a ticket,
set it as an enhancement and select Plugins as the component.
Don't forget to tell me where in what file you want the plugin hook.
Reference URL's