*** Mosaddphp Mambot
*** by Neni
*** Short usage description
*** for MOS 4.5 1.0.3 and above
*** Version 1.01, added output buffering (many thanks to chipjack)
With this mambot you can call any and unlimited number
of custom php-scripts from inside your content, which
can be either typed- or section/category-content.
You won't need to use an IFRAME nor to install a new
component, the customly generated content will just be
integrated in the standard mambo content-framework. As
the name of the mambot (mosaddphp.php) has been chosen
to be executed before the other mambots, you have the
option to include other mambot-tags (like {mosimage} or
{mospagebreak}) in your customly generated output and
they will be evaluated properly. Just imagine generating
a long list of items from a custom database and just
inserting {mospagebreak} every 10 lines or so and letting
mambo do the 'hard' work of pagination :-).
The syntax for the mosaddphp-mambot is like this:
{mosaddphp:<php-file>[,<parameter>]...}
Example:
{mosaddphp:subfolder/sample.php,12,14.325,blabla}
For security reasons the string "mosaddphp/" is always
added before the folder/filename, so all your custom
php-scripts have to reside in a mosaddphp-folder in
mambo-root or any subfolders of it. In the example above
it would evaluate to mosaddphp/subfolder/sample.php.
If the file doesn't exist, the tag is replaced by an
empty string.
Your script can be any 'normal' php-script with php-code parts
enclosed in php-tags and direct HTML in between.
You can specify as many parameters as you want in the tag.
The parameters are stored in an array called $mosaddphp_params
(index 0 for the first parameter and so on), which you can simply
access in your custom php-script.
Of course in your script you will also have full access to any defined
mambo-variables, -functions, -classes, -objects, -methods, constants etc...,
and to any php-variables/arrays (like $_REQUEST, $_POST, $_GET, $_FILES,
$_SESSION etc.), so the possibilities for custom php-scripts are enormeous.
You can have either direct HTML-code/text and echo/print-statements in your script or
you can put the output of your script into the variable $mosaddphp_output, the
mosaddphp-mambot will then replace the full mosaddphp-tag with the output of your script.
When using both options in one script, keep in mind that HTML/text put directly into
$mosaddphp_output is always displayed before all other output in your script, regardless
of the order of appearance in your script.
You can have unlimited number of mosaddphp-tags in your content with any HTML/text in between.
Just the tag itself will be replaced by the generated output, it works just like with
the other mambot-tags. The mosaddphp-tags are evaluated sequentially from first to last,
so variables defined in global php-scope in a first executed script will be available in
the next ones. You can even have the same script executed as many times as you wish with
changing parameters and global variables etc. It's also clear, that by design the variables
$mosaddphp_params and $mosaddphp_output are always only valid for the currently executed
script.
Installation:
Just copy mosaddphp.php to your mambots-Folder in mambo-root and create in mambo-root
a new Folder called mosaddphp, where you can place your custom php-scripts then.
After that enjoy the almost limitless possibilities :-).
The code in mosaddphp.php is quite small and simple, so you may easily tweak it to your
needs, if you need a different behaviour (for example other parameter separating character
instead of ",").
Incompatibility:
There's only one so far i tested. The PDF-output-function in mambo doesn't evaluate
mambot-tags like normal content display does before rendering the PDF, so you will see
the mosaddphp-tag instead of the script-output in the PDF. This was in MOS 4.5 1.0.3,
i didn't check 1.0.4. But this should be easy to resolve by simple tweaks of the
corresponding core file.