


Stara szkoła - Legacy |
![]() |
![]() |
Redaktor: Stefan Wajda | |
19.06.2007. | |
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}happy.png{$suffix}", "{$prefix}sad.png{$suffix}" ) ); $row ⇒ text = <a href="http://www.php.net/str_replace">str_replace</a> ( $smiles_src, $smiles_img, $row ⇒ text ); } define( '_MOS_CONVERT_SMILES_MAMBOT', 1 ); } MAMBOT_convert_smiles( $row ); A number of things are set up for a mambot. The mossmiles.php has access to a number of variables:
In addition, the Row
is passed by address to the 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ł |
---|