Dynamic Articles with TinyButStrong

This plug-in allows to include dynamic content in Joomla articles using the TinyButStrong Template Engine.
The possibilities of dynamic content are very rich. For example, it can be listing data from MySQL tables, or it can complete user interface asking and processing data given by the user.
TinyButStrong is very well adapted for CMS because, unlike other Template Engines, it allows to have templates build with visual or WYSIWYG editors. It means that a template can be a Joomla article build with the inline Html editor provide by default (TinyMCE).

Requirement:

Joomla 1.5 or higher.

How it works:

Since the plug-in is installed and activated in the Joomla website, you can use 3 types of plugin tags (Direct MergeBlock, External Script and Internal Script) that you can put anywhere in your articles.
Because adding active content in articles can be powerfull, the plug-in has also several parameters to manage security levels that can be tuned for all articles or for specific articles.

Please note:

You can have several plugin tags (defined by {tbs} and {/tbs}) in the same article. They will be processed in order.

All plugin tags can be placed anywhere, they will be deleted before the display.

You can tune several security parameters at the Joomla Administration interface.

The default Joomla PDF button won't work correctly with dynamic articles, unless you make some changes.

This help file assumes that you understand the basic concepts of Template Engines and more specifically the TinyButStrong Template Engine.

Type #1: Direct MergeBlock

Syntax:
{tbs}mergeblock=blockname;db=dbname;sql=sqlstatement{/tbs}

This type of plugin tag takes the current article as current template and performs a TBS->MergeBlock() over it.
The result of the merging is displayed instead of the original article.
There is no need to code any PHP to use this type of plugin tag.

blockname:

Name of the TBS block to merge. Assuming that such a block exists in the current article.

dbname:

Optional. Name of the database where to use the SQL statement. The database must be available with the current Joomla connection. You can specify the keyword %current% for the Joomla database. (keyword %joomla% is also supported for compatibility with version 1.0 of this plugin)
If you want to connect to a database with another account and password, you must use another type of plugin tag because this one cannot do it.

sqlstatement:

The SQL statement that should return the data to display.
Since version 1.02 of this plugin: In order to facilitate the usage of operators '<' and '>' in the SQL statement, the plugin automatically replaces strings '-+' and '+-' with those operators. You can prevent this behavior by adding the parameter sql_preserve in the plugin tag.
Example:{tbs}mergeblock=u;sql=SELECT name FROM t_user WHERE id+-0{/tbs}
is the same as{tbs}mergeblock=u;sql=SELECT name FROM t_user WHERE id>0;sql_preserve{/tbs}

Example:

Joomla article:

{tbs}mergeblock=u;sql=SELECT name, email FROM jos_users ORDER BY name{/tbs}

Name

Email

[u.name;block=tr]

[u.email]

Type #2: External script

Syntax:
{tbs}script=scriptname.php;db=dbname{/tbs}

This type of plugin tag is the same as the previous one but instead of a simple TBS->MergeBlock(), it run the specified PHP script.
The script should drive the merging assuming that the current article is already loaded as the current template. There is no need to call TBS->Show() because the plugin will do it. Please note that your PHP script is run in the same context as a function and that the local variable $TBS contains the ready to use TBS instance. The local variable $PrmLst contains the parameters of the plugin tag if you need it. You can leave the current script and return to the Joomla process using command return; in your main script (it hasn't the same behavior inside a function of course). They are other coding facilities given somewhere below.

scriptname.php:

The PHP script to run. You can specify a path. The default path for all scripts can also be specified in the plug-in parameters.

dbname:

Optional. Name of the database to select before the script is run. The database must be available with the current Joomla connection. You can specify the keyword %joomla% for the Joomla database.
If you want to connect to a database with another account and password, then your script must open this connection by itself, and you should specify explicitly the new open connected for any use of MergeBlock().

Example:

Joomla article:

{tbs}script=myappli.php{/tbs}

Name

Email

[u.name;block=tr]

[u.email]

myappli.php: (external script using the same MySQL connection and database)

Coding help:

Three properties are given by the TinyButStrong plug-in to retrieve information about the current Joomla context:

$TBS->JoomlaArticle: A reference to the article that is being rendered by the view. For example: $TBS->JoomlaParams->title and $TBS->JoomlaParams->id

$TBS->JoomlaParams: A reference to an associative array of relevant parameters.

$TBS->JoomlaLimitstart: An integer that determines the "page" of the content that is to be generated.

Two functions are given by the TinyButStrong plug-in to work with the Joomla Database Object which is a database connectivity tool. It helps to query and execute SQL statements in the Joomla database and other databases available with the same MySQL connection as Joomla.

tbs_plugin_SqlGetRows($sql, $err_prefix=''): Return the result of a query, first row is index 0, and each row is an associative PHP array.
Return an empty array if the query gives no data. In case of error, the function return false and a message is displayed. You can prefix the error message using argument $err_prefix.

tbs_plugin_SqlExecute($sql, $err_prefix=''): Execute the query and return true if there is no error, otherwise return false and display an error message.

Tips and trics using the Joomla framework:

How to get

Code

Comments

Current Article's id:

$id = $TBS->JoomlaArticle->id;

Current Article's title:

$title = $TBS->JoomlaArticle->title;

read/write

URL of the current article:

$url = JRoute::_(ContentHelperRoute::getArticleRoute($art_id));

$art_id must be the current article id.
This expression give the good URL coresponding to the current URL mode configured in the Joomla instance (long, short, with html extension or not)

Type #3: Internal script

Syntax:
{tbs}embedded;db=dbname{/tbs}

This type of plugin tag is the same as the previous one but instead of an external script, it run the parts of PHP code which are embedded in the current article. This can be very dangerous because all PHP commands are available. The parts of PHP code must be placed between tags <!--TBS and -->. Those tags are compatible with HTML comment tags, which means that they won't destroy the article looking, but they cannot be seen is visual mode. You must edit them by editing the HTML source. The PHP code is deleted before the article is displayed.

dbname:

Optional. Name of the database to select before the script is run. The database must be available with the current Joomla connection. You can specify the keyword %joomla% for the Joomla database.
If you want to connect to a database with another account and password, then your script must open this connection by itself, and you should specify explicitly the new open connected for any use of MergeBlock().

TBS Dynamic articles and PDF documents:

In the original Joomla 1.5.x installation, the generation of PDF document (using the PDF button available on any article by default) does not run any Joomla plug-ins. Therefore your TBS Dynamic Article will not be converted as we can expect when a user will click on the PDF button. Instead he will see the article like the Admin can see it.
In order to avoid this behaviour, you can try two solutions:
• Deactivate the PDF generation for all articles or for the current article only. This can be done by tuning the global property or only the property of the article.