UWAGA: Strona zawiera materiały archiwalne. Większość artykułów dotyczy Joomla! 1.0
Start arrow Programowanie arrow Boty arrow Stara szkoła - Legacy
Stara szkoła - Legacy Drukuj Email
Redaktor: Stefan Wajda   
This example is for writing Mambo 4.5.0 mambots. You can still write mambots in this style for Mambo 4.5.1 and later providing they are saved in the /mambots directory. These mambots are loaded every time a Content Item is displayed. So, for the Frontpage component, the same file could be loaded five, ten or twenty times depending on the number of content items displayed which is extremely inefficent. You are encouraged to look at upgrading your mambots to gain better performance and flexibility. Additionally, you should upgrade as this method will be deprecated in future versions (after Mambo 4.5.1 / Joomla 1.0).

For our development example, we'll imagine we are creating a Mambot to replace smile text with smile images.

The file for the mambot will be called mossmiles.php and it is saved in /mambots/mossmiles.php. It looks like this:

if (!defined( '_MOS_CONVERT_SMILES_MAMBOT' )) {
 // only define the function once
 function MAMBOT_convert_smiles( &$row ) {
  $smiles_src = array(
  $prefix = '<img src="images/smiles/';
  $suffix = ' height="12" width="12" alt="" />';
  $smiles_img = <a href="http://www.php.net/array">array</a>(
   "{$prefix}sad.png{$suffix}" )
  $row ⇒ text = <a href="http://www.php.net/str_replace">str_replace</a>
     ( $smiles_src, $smiles_img, $row ⇒ text );
MAMBOT_convert_smiles( $row );

A number of things are set up for a mambot. The mossmiles.php has access to a number of variables:

the current mosContent object. This is an object with all of the fields in the mos_content table.

a variable holding masks for various display options

In addition, the $row object has a property called text that the mambot will operate on to make changes to the text.

Row is passed by address to the MAMBOT_convert_smiles function so that any changes to the object made within the Mambot function are retained.

Because a mambot is called more than once during the code execution, you must ensure that the function is defined only once. Hence, a constant is defined the first time the mambot is loaded. On subsequent load, the function definition is ignored.

All modifications to the content text are made to the $row ⇒ text property variable.

« poprzedni artykuł