Dynamic Content with TinyButStrong

version 1.5.0-beta
a module for Drupal 6
(help file updated on 2011-03-01)

This module allows to include dynamic content in Drupal pages 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:

Drupal 6.x. Does not work with Drupal 7 yet.

Installation:

Extract the archive of the module into your Drupal installation (normally into sites/all/modules).
Then enable the module in Administer > Site building > Modules.
You can eventually configure the module behavior in Home › Administer › Site configuration › TinyButStrong.

How it works:

Since the module is installed and activated in the Drupal website, a new Input Format is available when you create or edit a content (a Page, a Story, or other custom content type). The new format is named "Dynamic content with TinyButStrong Template Engine". When this format is choosen in the content parameters, then you can use 2 types of TBS tags (see below) that you can put in the content's body which will be found an processed by TinyButStrong.

Because dynamic content can be dangeroulsy powerfull, by default only the Administrator has permission to apply this Input Format to a content and to edit a content that has this Input Format.

You can change this security level at you own risk. Permissions about Input Formats can be changed in Administer > Site configuration > Input Formats.

Please note:

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.
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 users WHERE uid+-0{/tbs}
is the same as
{tbs}mergeblock=u;sql=SELECT name FROM users WHERE uid>0;sql_preserve{/tbs}

Example:
Drupal Page:
{tbs}mergeblock=u;sql=SELECT uid, name FROM users{/tbs}

This is my first dynamic content in Drupal.

<table border="1">
  <tr bgcolor="#CCCCCC">
    <td>uid</td>
    <td>name</td>
  </tr>
  <tr>
    <td>[u.uid;block=tr]</td>
    <td>[u.name]</td>
  </tr>
</table>

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 Drupal 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 %current% for the Drupal 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}

<table border="1">
  <tr bgcolor="#CCCCCC">
    <td>uid</td>
    <td>name</td>
  </tr>
  <tr>
    <td>[u.uid;block=tr]</td>
    <td>[u.name]</td>
  </tr>
</table>

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

global $active_db;

$key = (isset($_GET['key'])) ? intval($_GET['key']) : 0;

$TBS->MergeBlock('u', $active_db, 'SELECT id, name FROM t_user WHERE id='.$key);

?>

myappli.php: (external script using a different MySQL connection)
<?php
$key = (isset($_GET['key'])) ? intval($_GET['key']) : 1;
$cid2 = mysql_connect('localhost', 'user', 'password');
$TBS->MergeBlock('u','mysql','SELECT uid, name FROM users WHERE uid='.$key);
mysql_close($cid2);
?>

Coding help:

Moreover, the module gives to you other coding facilities:

Two functions are given by the TinyButStrong plug-in to work with the Drupal database connectivity. It helps to query and execute SQL statements in the Drupal database and other databases available with the same MySQL connection as Drupal.

Tips and trics using the Drupal framework:

How to get Code Comments
Current Node's id:   (na)   Not possible because this plug-in is a Drupal Filter and can be applied on a text string which may be a combination of contents.
Database connection   global $active_db;   a MySQLi object.
User information:   global $user;   an array of information

You can found more coding ressource at the Drupal API Reference

Change-log

Verion 1.5.0-beta: first version