TPLN - Documentation

I. Presentation of TPLN
II. Templates files
  1. Declaration of a variable
  2. Declaration of a bloc
  3. Before beginning
III. The functions
  - Open()
  - Parse()
  - Loop()
  - EraseItem()
  - EraseBloc()
  - ParseBloc()
  - GetBlocInFile()
  - Write()
  - OutPut()

IV. The special functions MySQL 
1. The Functions for MySQL
    - SetHost, SetLogin(), SetPassword(), SetBase()
    - DbConnect()
    - DbClose()
    - DoQuery()
    - GetData()
    - GetRowsCount()  
2. Function ShowRecords()
    - ShowRecords()
    - SetNavLabels()
    - SetNavColor()

V.The special functions of TPLN
   - AddChrono()
    - AddLogo()

 

I. Presentation of TPLN

TPLN is a template class wirtten in Php for Php.

The Php code separated of the design what facilitates the update of the design of your documents and to permit to separate work between developer Php and the Webdesigner.

Top

II. Templates files

1. Declaration of a variable

The declaration of the variables makes itself with the help of the accolades {} in your file template

Example :

<html>
<body>

             {ma_variable}
</body>
</html>

 

2. Declaration of a bloc

The declaration of the blocks makes itself with the help of the accolades <> in your file template

Example :

<html>
<body>

            <mon_bloc>  {ma_variable} </mon_bloc>
</body>
</html>

3. Before beginning

Before beginning, you need configure the present global variables in the TPLN_Cfg.php file within the TPLN directory.

Example :

/***************************** Configuration *******************************************/
define('ABSPATH', ''); // Absolute path
define('TPLN_PATH',"../../../TPLN/"); // TPLN path slash at end !
define('TPLN_CACHE_DIR',TPLN_PATH."cached/"); // default cache dir slash at end !
define('TPLN_CACHE_TIME',"3600"); // default cache time

// Db configuration
$TPLN_DB_HOST_DEFAULT = "localhost"; // your host by defaut
$TPLN_DB_LOGIN_DEFAULT = "root"; // your login by defaut
$TPLN_DB_PASSWORD_DEFAULT = ""; // your password by defaut
$TPLN_DB_BASE_DEFAULT = "my_base"; // your base by defaut

$TPLN_DB_UrlBngTxt = "[<<]";
$TPLN_DB_UrlPrevTxt = "[< Prev]";
$TPLN_DB_UrlNextTxt = "[Next >]";
$TPLN_DB_UrlEndTxt = "[>>]";

$TPLN_DB_NavColorFirst = "#CCCCCC"; // alternate ligne color
$TPLN_DB_NavColorSecond = "#FFFFFF"; // alternate ligne color
/**********************************************************************************/

Top

III. The functions

TPLN is a PHP class. It requires this declaration.

<?php

include
("TPLN/TPLN.php");
// Include file
$TPLN = new TPLN; // Object declaration

// ... continuation of the program


?>

- Open()

The Open() function serves to open the file template the file can have any extension (. htm. html. tpl,...).

Open( string filename [, CACHED, int time ] )

Example :

Simple opening :

$TPLN->Open("nomfichier");

Opening with cache to 3600 seconds is 1 hour :

if ( !$TPLN ->Open("nomfichier",CACHED, 3600) ){
/ / code to execute to generate the file

}

$
TPLN->Write(); // print result


Top

- Parse()

The Parse() function serves to replace a variable defined in your file template.
TPLN uses a pseudo language object of style javascript to reach your variable thanks to the separator ". ".

This function also possesses a parameter optional functions.
The one serves to format the text here of replace.
These options are the following :

  • |B adds <b></b> to replace what makes it bold
  • |I adds <i></i> to replace what makes it italic
  • |U adds<u></u> to replace what makes it underline
  • |Php function name any Php functions (ucfirst for Example)

Parse( string item , string replace [, string functions ] )

Example :

Parse:

$TPLN->Parse("ma_variable","replace");

Parse in bloc:

$TPLN->Parse("mon_bloc.ma_variable","replace");

Parse in bloc with format:

$TPLN->Parse("monbloc.ma_variable","replace","|B");


Top

- Loop()

The Loop() function is applied to a block to signal its repetition.

You can also write this manner
Loop(this) orLoop() to make a Loop of the last definite Bloc

Attention : it is counseled to use the complete path of the block if it is an overlapped bloc !

Loop( [ string blocname ] )

Example :

Loop :

for($i=0,$i < 10;$i++){
$TPLN
->Parse("mon_bloc.ma_variable","$i");
$TPLN
->Loop("monbloc");

or

$TPLN->Loop();

or
$TPLN->Loop(this);
}


Top

- EraseItem()

the EraseItem() function serves to erase a variable.

EraseItem( string item )

Example :

Simple EraseItem :

$TPLN->EraseItem("my_var");

EraseItem in abloc:

$TPLN->EraseItem("my_bloc.my_var");


Top

- EraseBloc()

The EraseBloc() functions serves to erase a bloc.

EraseBloc( string blocname )

Example :

EraseBloc :

$TPLN->EraseBloc("my_bloc");


Top

- ParseBloc()

The ParseBloc() function serves to replace a whole block with its included beacons.

ParseBloc( string blocname , string replace )

Example :

ParseBloc :

$TPLN->ParseBloc("my_bloc" , "No more my_bloc !");


Top

- GetBlocInFile()

The GetBlocInFile() function serves to return a whole block of the template file.

GetBlocInFile( string blocname )

Example :

GetBlocInFile :

$bloc = $TPLN->GetBlocInFile("my_bloc");



Top

- Write()

The Write() function serves to print the file template.

Write( )

Example :

Write :

$TPLN->Write();



Top

- Output()

The Output() function serves to return the content of the template file.

OutPut( )

Example :

Output :

$file_parsed = $TPLN->Output();



Top
 

IV. The special functions MySQL

1. The Functions for MySQL

- SetHost(), SetLogin(), SetPassword(), SetBase()

The SetHost(), SetLogin(), SetPassword(), SetBase() functions serve to initialize the variables for the connection.

It's preferable to configure the file TPLN_Cfg.php in TPLN directory to avoid to call these functions every time.

  •  SetHost( string host )
  •  SetLogin( string login )
  •  SetPassword( string password )
  •  SetBase( string base )
Example :

SetBase :

$TPLN->SetBase("my_base"); // change base



Top

- DbConnect()

The DbConnect() function serves to connect to your MySQL database.

DbConnect( )

Example :

DbConnect() :

$TPLN->DbConnect();

 

Top

- DbClose()

The DbClose() serves to disconnect to your MySQL database.

DbClose( )

Example :

DbClose() :

$TPLN->DbClose();

 

Top

- DoQuery()

The DoQuery() function serves to make a query.

DoQuery(string query )

Example :

DoQuery() :

$TPLN->DoQuery("SELECT * FROM my_table");

 

Top

- GetData()

The GetData() function serves to return data of your query.
If COUNT parameter is present the result is returned.

GetData( [COUNT] )

Example :

GetData() for a normal query:

$TPLN->DoQuery("SELECT * FROM my_table");
$res = $TPLN->GetData();

GetData() for a count query:

$TPLN->DoQuery("SELECT COUNT(*) FROM my_table");
$count = $TPLN->GetData(COUNT);


Top

- GetRowsCount()

The GetRowsCount() function serves to return the number of rows returned by the query.

GetRowsCount( )

Example :

GetRowsCount() :

$TPLN->DoQuery("SELECT * FROM my_table");
$nb_results = $TPLN->GetRowsCount();


Top

2. The ShowRecords() function

- ShowRecords()

ShowRecords() is a function that allows you to parse data from MySQL, you only have has create your template and the function takes care of all for you!

Your template must be to configure as this:

  • <data>
  •    <loop> </loop> contains the name of your fields in variable
  •     <norecord></norecord> contains the message if there are not any results
  • </data>
Example :

<html>
<body>

<data>
  Données <br><br>
  <loop> {champs_nom} <br> </loop>
   <norecord>No result</norecord>

</data>
</body>
</html>

ShowRecords( string query , int resultsbypage )

Example :

ShowRecords() :

$query = "SELECT * FROM my_table";
$TPLN->ShowRecords($query,10);

This function possesses its variable owners who are automatically parsed those must be present in the bloc <data></data> they are noted like this {_Variable}.

  • _First indicate the position of the first result
  • _Last indicate the position of the last result
  • _Count indicate the number of results
  • _PageNumber indicate the actual page number
  • _PageCount indicate total page number
  • _UrlBng url of the first page (his text is defined in TPLN_Cfg.php or by SetNavLabels() )
  • _UrlPrev url of the previous page (his text is defined in TPLN_Cfg.php or by SetNavLabels() )
  • _UrlNext url of the next page ( his text is defined inTPLN_Cfg.php or by SetNavLabels() )
  • _UrlEnd url of the end page ( his text is defined in TPLN_Cfg.php or by SetNavLabels() )
  • _ NavColor replace by one two colors specified in TPLN_Cfg.php or by SetNavColor()
  • _AbsPath replace by ABSPATH defined in TPLN_Cfg.php

 

Top

- SetNavLabels()

The SetNavLabels() function permits to replace the present text in _UrlBng, _UrlPrev, _UrlNext, _UrlEnd.

SetNavLabels(string bngtxt , string prevtxt , string nexttxt , string endtxt )

Example :

SetNavLabels() :

$TPLN->SetNavLabels("[<<]","[<]","[>]","[>>]");

 

Top

V. The special functions of TPLN

- AddChrono()

The AddChrono() function permits to be able to know the time of generation of the template.
You must place imperatively in your file template the variable {chrono}.

AddChrono([ ALL ])

If the ALL parameter passed then in parameter the stopwatch will return the sum of all the times or TPLN has been called, otherwise return the present session.

This function must be placed before Write() or Output()

Top

- AddLogo()

The AddLogo() function permits to add the TPLN logo to your file.
You must place imperatively in your file template the variable {logo}.

AddLogo()

This function must be placed before Write() orOutput()

Top
SourceForge Logo