Below is an example of a mambot that counts the number of words that has a content.
mostest.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
This file is nothing different than that we write for modules or components. We must complete “filename” with the .php file of the mambot itself.
mostest.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | registerFunction( 'onPrepareContent', 'botMosTest' ); function botMosTest( $published, &$row, $mask=0, $page=0 ) { global $mosConfig_absolute_path; if (!$published) { return true; } if (strpos($row->text,'mostest')===false){ return true; } $cant = str_word_count($row->text); echo ""; return true; } ?> |
$ _MAMBOTS-> registerFunction declare the trigger and the function to be called when this happens. $ Mambots should not be declared as global.
The function botMosTest receive the parameters parámetros:
published
1 if the mambot is published, 0 if not
row
Var that refer to the content objetc
mask
Current mask, default is 0
page
Number of the current page, default is 0
Instalation:
Once you create these 2 files and compress them in a .zip “mostest.zip” you can install it as any mambot.
How to use:
A Mambot is very easy to use: in the content article that we want the mambot to count the number of words included we simple add the following: {mostest}, with this, when a content is loaded, automatically will appear an alert with the amount words. If this fails, verify that the mambot is enabled.
Although the example was a bit silly, it shows the potential of Mambots. If you are creative you will be able to make things very interesting.