Creating mambots for Joomla 1.0.x

13 May 2009 Published in Blog

This article will explain how to create a mambot on Joomla 1.0.x (Plugins from Joomla 1.5). It is recommended to have knowledge of PHP and HTML to read this article.

What is a Mambots?

Mambots are the applications that intercept the contents (documents or items of components) before being published and displayed by the system, and add or alter information dynamically, thus completing the total content that will be delivered the end user’s browser. The Mambots can be called by special commands, or can be displayed by default for certain content / components.

Mambots are located in the directory /mambots. As the components and modules can be installed/uninstalled, configured and published from the backend of Joomla.

Triggers:

At present there are 5 factors (documented) to trigger a Mambots:

  • onPrepareContent
  • onSearch
  • onInitEditor
  • onGetEditorContents
  • onEditorArea

Each event require a numer and parameters.

Example of a Mambot:

As modules, Mambots are composed of two core files. One is the .xml file that gives the configuration for the installation, and the other is .php file that allows us to codify what the mambots will do. Al the mambot files should start with “mos”.

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

	WordCount
	Juan
	December 2008
	(C) 2008 Serfe. All rights reserved.
	https://www.gnu.org/copyleft/gpl.html GNU/GPL
	info@serfe.com
	www.serfe.com
	1.0.0
	Count words on a content
	
		mostest.php
	

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.

Serfe info(at)serfe.com https://www.serfe.com/images/serfe_logo_text.png https://www.serfe.com/images/serfe_logo_text.png MACIA 2472, S3016OCP, SANTO TOME, SANTA FE, ARGENTINA 1-305-5375397