Source for file TPLN.php

Documentation is available at TPLN.php

  1. <?php
  2. /**
  3.  * TPLN template engine - main class
  4.  *
  5.  * @package Template Engine
  6.  * @website http://tpln.sourceforge.net
  7.  * @license LGPL
  8.  */
  9.  
  10.  
  11.  
  12. // Inclusion of the configuration file and the Db
  13. define('TPLN_PATH'dirname(__FILE__));
  14.  
  15. include_once('TPLN_Cfg.php');
  16. if(TPLN_DBUG_CLASS)include_once('dBug.php');
  17. include_once('lang/error_'.TPLN_LANG.'.inc.php')// language file
  18. include_once('plugin/form/lang.inc.php')// form language file
  19.  
  20. /******************* Structure des plugins ***************************************
  21. - TPLN
  22.     |- DB
  23.             |- Form
  24.                     |- Mail
  25.                             |- Rss
  26. *********************************************************************************** @author H2LSOFT */
  27. include_once('plugin/image/image.class.php');
  28. include_once('plugin/rss/rss.class.php');
  29. include_once('plugin/mail/mail.class.php');
  30. include_once('plugin/form/form.class.php');
  31. include_once('plugin/db/db.class.php');
  32.  
  33. /******************* Structure d'un fichier ***************************************
  34.  
  35. f - f_no - name                 - string     // nom de fichier
  36. - cache_name           - string     // nom du fichier en cache
  37. - buffer               - string     // contenu du fichier
  38. - items                - array      // contient tous les items
  39. - constant_items           - array        // contient les constantes
  40. - php_items            - array      // contient les items avec $
  41. - cmd_items            - array      // contient tous les items includes
  42. - create_cached_file   - bool       // cr�e le fichier en cache ?
  43. - time_started         - long int   // d�but du chrono
  44. - cache_expire         - bool       // expiration du cache ?
  45. - execution_time       - long int   // temps d'execution
  46. - chrono_started       - long int   // chrono started
  47.  
  48. Attention par reference pour les v�rifications et performances
  49.  
  50. - shortcut_blocs       - array      //
  51. |_ all              - array      // contient le nom de tous les blocs
  52. |_ used             - array      // contient les blocs appel�s par l'utilsateur
  53. |_ name             - none       // contient le nom du bloc
  54. |_ items       - array      // contient les items
  55.  
  56. - def_blocs            - array      // contiens tous les blocs structur�s
  57.                          // definis par l'utisateur lors d'un appel'
  58.                          // voir plus bas leurs structures
  59. * @author H2LSOFT */
  60.  
  61. /******************* Structure d'un bloc ***************************************
  62.  
  63. def_blocs - name                  - string     // nom du bloc
  64. |_ structure          - string     // contenu du bloc
  65. |_ parsed             - array      // contiens les sessions de blocs
  66. |_ is_looped          - boolean    // loop� ?
  67. |_ children           - array      // contiens les bloc enfants
  68.  
  69. ************************************************************************************* @author H2LSOFT */
  70. class TPLN extends DB
  71. {
  72.     protected $def_tpl = array()// templates list defined with a name
  73.  
  74.     /**
  75.      * @var int index of template
  76.      */
  77.     public $f_no = -1// index of file
  78.     /**
  79.      * @var int index of virtual template
  80.      */
  81.     public $vf_no = -1// index of virtual file
  82.     /**
  83.      * @var array template properties
  84.      */
  85.     public $f = array()// array which contains all the properties
  86.  
  87.  
  88.     protected $chrono_type = array()// chrono of ALL or not ?
  89.     protected $HTMLCompress = 0// activate the HTML compression of the exit ?
  90.     protected $blocs_double_exceptions = array('start''end''pager''in''out''previous''next')// allows blocs in double
  91.  
  92.     // Error
  93.     public $error_msg = '';
  94.     protected $error_signaled = array();
  95.  
  96.     // debugage
  97.     protected $struct_mode = 0;
  98.     protected $struct_tab = array()// contains array entirety
  99.  
  100.     /**
  101.      * TPLN constructor
  102.      * @author H2LSOFT
  103.      */
  104.     public function TPLN()
  105.     {
  106.         // looks at the existence of the parameter by default
  107.         if(TPLN_DEFAULT_IND == 1)
  108.         {
  109.             if(!is_dir(TPLN_DEFAULT_PATH))
  110.             {
  111.                 if(!@mkdir(TPLN_DEFAULT_PATH0755))
  112.                 {
  113.                     $this->error(7.2);
  114.                     return;
  115.                 }
  116.  
  117.                 clearstatcache();
  118.             }
  119.         }
  120.     }
  121.  
  122.     /**
  123.      * this method allows to use plugin for TPLN.
  124.      *
  125.      * @param string 
  126.      *
  127.      * @deprecated
  128.      *
  129.      * @since 2.8
  130.      * @see Plugin form
  131.      * @author H2LSOFT
  132.      */
  133.     public function loadPlugin($name)
  134.     {
  135.         /*
  136.     $name = strtolower($name);
  137.  
  138.     $tmp = TPLN_PATH."/plugin/$name/$name.class.php";
  139.     include_once($tmp);
  140.     // PHP's version // création dynmique d'objet
  141.     $_php_ver = (float) PHP_VERSION;
  142.     if($_php_ver < 5.0)
  143.     aggregate($this, $name);
  144.     else
  145.     {
  146.         die('PHP version invalid no support for PHP 5');
  147.         // Création dynamique d'objet sans la fonction aggregate
  148.     }
  149.     * @author H2LSOFT */
  150.     }
  151.  
  152.     /**
  153.      * This method allows to compress the template.
  154.      *
  155.      * @param boolean $bool 
  156.      * @since 2.4
  157.      * @author H2LSOFT
  158.      */
  159.     public function htmlCompress($bool)
  160.     {
  161.         $this->htmlCompress $bool;
  162.     }
  163.  
  164.     /**
  165.      * This method allows to display the countain of a php variable to facilite debugging
  166.      *
  167.      * @param string $label 
  168.      * @param string $data 
  169.      * @param boolean $return 
  170.      *
  171.      * @return string 
  172.      * @since 2.6
  173.      * @author H2LSOFT
  174.      */
  175.     public function dump($label 'Debug'$data$return 0)
  176.     {
  177.         $format_html 1;
  178.         ($format_html$v '<pre><div style="text-align:left;margin:5px;border:1px solid #CCCCCC;background-color:#E5E5E5;">' $v '<pre>';
  179.         if(!empty($label))
  180.         {
  181.             if($format_html)$v .= '<div style="text-align:left;padding:5px;background-color:#CCCCCC;">';
  182.             $v .= "<b>$label => </b> ";
  183.             if($format_html)$v .= '</div>';
  184.         }
  185.         $v .= print_r($data1);
  186.         ($format_html$v .= '</div></pre>' $v .= '</pre>';
  187.  
  188.         if($return)
  189.             return $v;
  190.         else
  191.             echo $v;
  192.  
  193.         return;
  194.     }
  195.  
  196.     /**
  197.      * This method returns ip used.
  198.      *
  199.      * @return string 
  200.      * @author H2LSOFT */
  201.     public function getIP()
  202.     {
  203.         if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  204.             $ip $_SERVER['HTTP_X_FORWARDED_FOR'];
  205.         elseif(isset($_SERVER['HTTP_CLIENT_IP']))
  206.             $ip $_SERVER['HTTP_CLIENT_IP'];
  207.         else
  208.             $ip $_SERVER['REMOTE_ADDR'];
  209.  
  210.         return $ip;
  211.     }
  212.  
  213.     /**
  214.      * this method activates template structure
  215.      *
  216.      * @author H2LSOFT
  217.      */
  218.     public function fileStructMode()
  219.     {
  220.         $this->struct_mode = 1;
  221.     }
  222.  
  223.     /**
  224.      * this method
  225.      *
  226.      * @author H2LSOFT
  227.      */
  228.     public function traceMode()
  229.     {
  230.         $this->trace_mode 1;
  231.     }
  232.  
  233.     /**
  234.      *
  235.      * this method gets opened template
  236.      *
  237.      * @author H2LSOFT
  238.      */
  239.     protected function structOpen()
  240.     {
  241.         if($this->struct_mode == 0)
  242.         {
  243.             return;
  244.         }
  245.  
  246.         $this->structFile();
  247.         $this->structItems();
  248.         $this->structBlocs();
  249.         $this->arr2HtmlTab();
  250.     }
  251.  
  252.     /**
  253.      * this method returns file structure
  254.      *
  255.      * @author H2LSOFT
  256.      */
  257.     protected function structFile()
  258.     {
  259.         $this->struct_tab["<b>File:</b> {$this->f[$this->f_no]['name']}<br>\n";
  260.     }
  261.  
  262.     /**
  263.      * this method returns item structure
  264.      *
  265.      * @author H2LSOFT
  266.      */
  267.     protected function structItems()
  268.     {
  269.         $p_var array('_UrlBng',
  270.                 '_UrlPrev',
  271.                 '_UrlNext',
  272.                 '_UrlEnd',
  273.                 '_UrlPageNav',
  274.                 '_PageNumber',
  275.                 '_PageCount',
  276.                 '_First',
  277.                 '_Last',
  278.                 '_Count',
  279.                 '_NavColor',
  280.                 '_Chrono',
  281.                 '_Logo',
  282.                 '_Version',
  283.                 '_Field',
  284.                 '_QueryCount');
  285.  
  286.         $tab '<b>Variable(s) found:</b> '.count($this->f[$this->f_no]['items'])."<br>\n";
  287.  
  288.         $cur_item array()// initialisation
  289.         $tpln_var array()// initialisation
  290.         if(count($this->f[$this->f_no]['items']0)
  291.         {
  292.             $item_tmp array_unique($this->f[$this->f_no]['items']);
  293.  
  294.             foreach($item_tmp as $name)
  295.             {
  296.                 if(!in_array($name$p_var))
  297.                 {
  298.                     $cur_item[$name;
  299.                 }
  300.                 else
  301.                 {
  302.                     $tpln_var[$name;
  303.                 }
  304.             }
  305.         }
  306.  
  307.         $tab .= $this->arr2List('Constants variable(s)'$this->f[$this->f_no]['php_items']'{CONST::''}');
  308.         $tab .= $this->arr2List('Php variable(s)'$this->f[$this->f_no]['php_items']'{$''}');
  309.         $tab .= $this->arr2List('User variable(s)'$cur_item'{''}');
  310.         $tab .= $this->arr2List('Private variable(s)'$tpln_var'{''}');
  311.         $tab .= $this->arr2List('Tpln Include Command(s)'$this->f[$this->f_no]['cmd_items']'{#include('')}');
  312.  
  313.         $this->struct_tab[$tab;
  314.     }
  315.  
  316.     /**
  317.      * this method returns block structure
  318.      *
  319.      * @author H2LSOFT */
  320.     protected function structBlocs()
  321.     {
  322.         $this->struct_tab[$this->arr2List('Blocs'$this->f[$this->f_no]['shortcut_blocs']['all']);
  323.     }
  324.  
  325.     /**
  326.      * this method changes array to list
  327.      *
  328.      * @param string $text 
  329.      * @param string $arr 
  330.      * @param string $bng 
  331.      * @param string $end 
  332.      *
  333.      * @return string 
  334.      * @author H2LSOFT */
  335.     protected function arr2List($text ''$arr$bng ''$end '')
  336.     {
  337.         $txt null;
  338.  
  339.         if(!empty($text))
  340.             $txt .= "<b>$text:</b> ".count($arr).'<br>';
  341.  
  342.         if(count($arr0)
  343.         {
  344.             $txt .= '<ul>';
  345.  
  346.             foreach($arr as $name)
  347.             {
  348.                 $txt .= '<li>'.$bng.$name.$end."</li>\n";
  349.  
  350.                 if($text == 'Blocs')
  351.                 {
  352.                     if(count($this->f[$this->f_no]['shortcut_blocs'][$name]['items']0)
  353.                     {
  354.                         $txt .= '<ul>';
  355.  
  356.                         foreach($this->f[$this->f_no]['shortcut_blocs'][$name]['items'as $item)
  357.                             $txt .= "<li>\{$item}</li>";
  358.  
  359.                         $txt .= '</ul>';
  360.                     }
  361.                 }
  362.             }
  363.  
  364.             $txt .= '</ul>';
  365.         }
  366.  
  367.         return $txt;
  368.     }
  369.  
  370.     /**
  371.      * this method changes array to html table
  372.      *
  373.      * @author H2LSOFT */
  374.     protected function arr2HtmlTab()
  375.     {
  376.         for($i 0;$i count($this->struct_tab);$i++)
  377.         {
  378.             if($i == 0)
  379.                 echo '<table width="100%" border="1" cellspacing="0" cellpadding="3">';
  380.  
  381.             echo "<tr><td>{$this->struct_tab[$i]}</td></tr>";
  382.  
  383.             if($i == count($this->struct_tab)-1)
  384.                 echo '</table>';
  385.         }
  386.     }
  387.  
  388.     /**
  389.      * this method triggers TPLN error
  390.      *
  391.      * @global int $_err 
  392.      * @param string $err_no 
  393.      * @param string $file 
  394.      * @param string $bloc 
  395.      * @param string $item 
  396.      * @author H2LSOFT */
  397.     protected function error($err_no$file ''$bloc ''$item '')
  398.     {
  399.         global $_err;
  400.         $err_msg $_err["$err_no"];
  401.         $err_msg str_replace(
  402.  
  403.                 array('[:FILE:]''[:BLOC:]''[:ITEM:]'),
  404.                 array($file$bloc$item),
  405.                 $err_msg);
  406.  
  407.         $this->error_msg = "<B>TPLN error $err_no:</B> $err_msg";
  408.  
  409.         // assign use handler
  410.         if(in_array($err_noarray(0910111213)))
  411.             $this->error_user_level = E_USER_ERROR;
  412.         elseif(in_array($err_noarray813)))
  413.             $this->error_user_level = E_USER_WARNING;
  414.         else
  415.             $this->error_user_level = E_USER_NOTICE;
  416.  
  417.         $this->outPutMessage();
  418.     }
  419.  
  420.     /**
  421.      * this method sends mail admin alert
  422.      *
  423.      * @author H2LSOFT */
  424.     protected function mailAlert()
  425.     {
  426.         if($this->error_user_level != E_USER_ERROR)return;
  427.  
  428.         $err_alert TPLN_ERROR_ALERT;
  429.         $mail_admin TPLN_MAIL_ADMIN;
  430.  
  431.  
  432.         if(($err_alert == && !empty($mail_admin)) && (!isset($_GET['tpln_w']|| $_GET['tpln_w'!= 'adm'))
  433.         {
  434.  
  435.  
  436.  
  437.             $request_url_simple str_replace('?'.$_SERVER['QUERY_STRING']''$_SERVER['REQUEST_URI']);
  438.             $url 'http://'.$_SERVER['HTTP_HOST'].$request_url_simple;
  439.  
  440.             // have a query string ?
  441.             if(empty($_SERVER['QUERY_STRING']))
  442.                 $url .= '?tpln_w=adm';
  443.             else
  444.                 $url .= '?'.$_SERVER['QUERY_STRING'].'&tpln_w=adm';
  445.  
  446.             $subject '[TPLN] Alert Error';
  447.  
  448.             $err_msg $this->error_msg;
  449.             $err_msg str_replace('&lt;''<'$err_msg);
  450.             $err_msg str_replace('&gt;''>'$err_msg);
  451.  
  452.             $body date('[Y-m-d H:i] ')." TPLN has detected an error\n\n";
  453.             $body .= $err_msg.' in '.$_SERVER['SCRIPT_FILENAME']."\n\n\n";
  454.             $body .= "Url <a href=\"$url\">$url</a>\n";
  455.             $body .= "===========================================\n";
  456.             $body .= 'TPLN version '.TPLN_VERSION."\n";
  457.             $body .= 'IP: '.$this->GetIP()."\n";
  458.  
  459.             $body str_replace("\n""<br />"$body);
  460.  
  461.             $headers "MIME-Version: 1.0\n";
  462.             $headers .= "Content-type: text/html; charset=iso-8859-1\n";
  463.             $headers .= "From: ".TPLN_MAIL_EXPEDITOR."\n";
  464.             $headers .= 'X-Mailer: PHP/'.phpversion();
  465.  
  466.             if(@mail(TPLN_MAIL_ADMIN$subject$body$headers))
  467.             {
  468.                 if(TPLN_LANG == 'en')
  469.                     $msg "<br><br><hr>An email has been sent to the webmaster $mail_admin";
  470.                 elseif(TPLN_LANG == 'fr')
  471.                     $msg "<br><br><hr>Mail a alert&eacute; le webmaster $mail_admin";
  472.  
  473.                 $this->error_msg .= $msg;
  474.             }
  475.         }
  476.     }
  477.  
  478.     /**
  479.      *
  480.      * this method displays error message
  481.      *
  482.      * @param boolean $exit 
  483.      * @author H2LSOFT */
  484.     protected $error_user_level;
  485.     public function outPutMessage($exit true)
  486.     {
  487.         $this->mailAlert();
  488.  
  489.         if(!@in_array($this->error_msg$this->error_signaled))
  490.         {
  491.             $err_msg $this->error_msg;
  492.             //if($exit == 1 && TPLN_ERROR_URI == '')
  493.             //{
  494.                 if('TPLN_OUTPUT_CHARSET' != 'utf-8')
  495.                     $err_msg utf8_decode($this->error_msg);
  496.  
  497.                 // $err_msg = strip_tags($err_msg);
  498.                 trigger_error($err_msg$this->error_user_level);
  499.             //}
  500.  
  501.             $this->error_signaled[$this->error_msg;
  502.         }
  503.  
  504.         // logs of errors
  505.         if(TPLN_ERROR_LOGS)
  506.         {
  507.             // check if the file exists else we create it
  508.             if(!($fp @fopen(TPLN_ERROR_LOGS_FILE 'a+')))
  509.             {
  510.                 trigger_error('Impossible to open/create '.TPLN_ERROR_LOGS_FILEE_USER_NOTICE);
  511.             }
  512.             else
  513.             {
  514.                 // day hour ,msg
  515.                 $txt date("[Y-m-d H:i:s]    ").strip_tags($this->error_msg)."\n";
  516.                 fwrite($fp$txt);
  517.                 fclose($fp);
  518.             }
  519.         }
  520.  
  521.         // exit ?
  522.         if(TPLN_ERROR_URI != '')
  523.         {
  524.             $this->redirect(TPLN_ERROR_URI);
  525.         }
  526.  
  527.     }
  528.  
  529.     /**
  530.      * This method allows to redirect to a new web page
  531.      *
  532.      * @param string $uri 
  533.      * @param int $timer default 0
  534.      * @since 2.9
  535.      * @author H2LSOFT */
  536.     public function redirect($uri$timer=0)
  537.     {
  538.         if($timer 0)
  539.         {
  540.             die('<meta http-equiv="refresh" content="'.$timer.';'.$uri.'" />');
  541.         }
  542.  
  543.         if(!headers_sent())
  544.         {
  545.             header('Location: '.$uri);
  546.             exit();
  547.         }
  548.         else
  549.         {
  550.             die('<script>document.location.href="'.$uri.'"</script>');
  551.         }
  552.     }
  553.  
  554.     /**
  555.      * this method initializes template variables
  556.      *
  557.      * @author H2LSOFT */
  558.     protected function initTemplateVars()
  559.     {
  560.         // initialisation of variables types for EALL **************************
  561.         $this->f[$this->f_no]['name'null;
  562.         $this->f[$this->f_no]['cache_name'null;
  563.         $this->f[$this->f_no]['buffer'null;
  564.         $this->f[$this->f_no]['items'array();
  565.         $this->f[$this->f_no]['constant_items'array();
  566.         $this->f[$this->f_no]['php_items'array();
  567.         $this->f[$this->f_no]['cmd_items'array();
  568.  
  569.         $this->f[$this->f_no]['create_cached_file'0;
  570.         $this->f[$this->f_no]['time_started'0;
  571.         $this->f[$this->f_no]['cache_expire'0;
  572.         $this->f[$this->f_no]['execution_time'0;
  573.         $this->f[$this->f_no]['chrono_started'0;
  574.  
  575.         $this->f[$this->f_no]['shortcut_blocs'array();
  576.         $this->f[$this->f_no]['shortcut_blocs']['all'array();
  577.         $this->f[$this->f_no]['shortcut_blocs']['used'array();
  578.  
  579.         $this->f[$this->f_no]['shortcut_blocs']['name'null;
  580.         $this->f[$this->f_no]['shortcut_blocs']['name']['items'array();
  581.  
  582.         $this->f[$this->f_no]['def_blocs'array();
  583.  
  584.         $this->chrono_type[$this->f_nonull;
  585.     }
  586.  
  587.     /**
  588.      * this method allows to open template file which can to support any extensions of file (.htm, .html, .tpl, .php ... ).
  589.      *
  590.      * if none name of file has been defined, it will open the file which have the same name
  591.      *
  592.      * as the script with extension per defect.
  593.      *
  594.      * @param string $file 
  595.      * @param CACHED $cached 
  596.      * @param int $cached_time 
  597.      *
  598.      * @return boolean 
  599.      * @author H2LSOFT */
  600.     public function open($file ''$cached ''$cached_time '')
  601.     {
  602.         $this->f_no++// incremente
  603.         $this->initTemplateVars()// array's initialisation
  604.  
  605.         // add the name of file
  606.         if(empty($file))
  607.         {
  608.             $file basename($_SERVER['PHP_SELF']);
  609.             // delete the extension
  610.             preg_match("/\.([^\.]*$)/"$file$elts);
  611.  
  612.             if(count($elts1)
  613.                 $file str_replace($elts[count($elts)-1]TPLN_DEFAULT_EXT$file);
  614.         }
  615.  
  616.         // check the existence of extension and the directory per defect
  617.         if(TPLN_DEFAULT_IND)
  618.         {
  619.             if(!preg_match("/\./"basename($file)))
  620.             {
  621.                 $file .= '.'.TPLN_DEFAULT_EXT;
  622.             }// puts the extension per defect if it's not exists
  623.             $file TPLN_DEFAULT_PATH.'/'.$file// puts the directory per defect
  624.         }
  625.  
  626.         $this->f[$this->f_no]['name'$file;
  627.  
  628.         $time explode(' 'microtime());
  629.         $this->f[$this->f_no]['time_started'time();
  630.         $this->f[$this->f_no]['chrono_started'$time[1$time[0];
  631.  
  632.         // define the chrono
  633.         if(!defined('TPLN_CHRONO_STARTED'))
  634.         {
  635.             $chrono $time[1$time[0];
  636.             define('TPLN_CHRONO_STARTED'$chrono);
  637.         }
  638.  
  639.         // if there is caching file
  640.         if(!empty($cached))
  641.         {
  642.             // the ? is replaced by -- in the caching file
  643.             if(strpos($file'?'))
  644.                 $this->f[$this->f_no]['name'substr($this->f[$this->f_no]['name']0strpos($file'?'));
  645.  
  646.             $this->f[$this->f_no]['cache_name'str_replace('?''---'$file);
  647.             $this->cacheDirExists();
  648.  
  649.             if(empty($cached_time))
  650.             {
  651.                 $cached_time TPLN_CACHE_TIME;
  652.             }
  653.             $this->f[$this->f_no]['cache_expire'$this->f[$this->f_no]['time_started'$cached_time// caching expiry
  654.  
  655.             // check if the file is still caching
  656.  
  657.             // file exists && its date of creation <= time of caching
  658.             if(file_exists(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['cache_name']&& $this->inCachePeriod())
  659.             {
  660.                 $this->getCachedFile();
  661.                 return true;
  662.             }
  663.             else
  664.             {
  665.                 $this->f[$this->f_no]['create_cached_file'1;
  666.                 $this->f[$this->f_no]['buffer'$this->getFile($this->f[$this->f_no]['name']);
  667.             }
  668.         }
  669.         else
  670.             $this->f[$this->f_no]['buffer'$this->getFile($this->f[$this->f_no]['name']);
  671.  
  672.         // remplaces the constants
  673.         $this->parseConstants();
  674.  
  675.         $this->parsePhpCommands();
  676.  
  677.         // remplaces the variables with $
  678.         if(TPLN_PARSE_GLOBALS)$this->ParseGlobals();
  679.         // remplaces the files to include
  680.         $this->captureIncludeCmd()// captures the commandes include
  681.         // parsing and evaluation if necessary
  682.         if(count($this->f[$this->f_no]['cmd_items']0)
  683.         {
  684.             $this->parseAllIncludeCmd();
  685.             $this->f[$this->f_no]['cmd_items'array()// delete
  686.         }
  687.         // replaces the $ if contained in includind files
  688.         if(TPLN_PARSE_GLOBALS)$this->parseGlobals();
  689.         $this->f[$this->f_no]['shortcut_blocs']['all'$this->captureAllBlocs();
  690.         $this->endBlocVerify();
  691.         $this->dualBlocVerify();
  692.  
  693.         // captures of the items after checking of blocs
  694.         $this->f[$this->f_no]['items'$this->captureItems();
  695.         $this->captureItemsInEachBloc();
  696.  
  697.         // debugger
  698.         $this->structOpen();
  699.  
  700.         if($this->f[$this->f_no]['create_cached_file'== 1)return false;
  701.     }
  702.  
  703.     /**
  704.      * this method replaces all php constants in template
  705.      *
  706.      * @author H2LSOFT */
  707.     public function parseConstants()
  708.     {
  709.         $this->f[$this->f_no]['constant_items'$this->captureItems('''CONSTANT');
  710.         if(count($this->f[$this->f_no]['constant_items']== 0)return;
  711.  
  712.         $defined_constants get_defined_constants();
  713.  
  714.         foreach($this->f[$this->f_no]['constant_items'as $item)
  715.         {
  716.             $this->f[$this->f_no]['buffer'$this->replaceItem('CONST::'.$item$defined_constants[$item]$this->f[$this->f_no]['buffer']);
  717.         }
  718.     }
  719.  
  720.     /**
  721.      * this method allows to delete the blocks.
  722.      *
  723.      * @since 2.2
  724.      * @see EraseBloc(), EraseItem().
  725.      * @author H2LSOFT */
  726.     public function cleanBlocs()
  727.     {
  728.         for($i 0$i count($this->f[$this->f_no]['shortcut_blocs']['all'])$i++)
  729.         {
  730.             $this->f[$this->f_no]['buffer'str_replace(
  731.                     array("<bloc::{$this->f[$this->f_no]['shortcut_blocs']['all'][$i]}>",
  732.                     "</bloc::{$this->f[$this->f_no]['shortcut_blocs']['all'][$i]}>"
  733.                     ''$this->f[$this->f_no]['buffer'])// bloc before/after
  734.         }
  735.     }
  736.  
  737.     /**
  738.      * this method allows to create a virtual template.
  739.      *
  740.      * @param string $countain 
  741.      *
  742.      * @return boolean 
  743.      * @author H2LSOFT */
  744.     public function createVirtualTemplate($countain)
  745.     {
  746.         $this->vf_no++// increments
  747.         $this->f_no++// increments
  748.         //$this->f_no = count($this->def_tpl) + 1; // increments
  749.  
  750.         // initialisation of variables types for EALL **************************
  751.         $this->f[$this->f_no]['name''Virtual'.$this->vf_no;
  752.         $this->f[$this->f_no]['buffer'$countain;
  753.         $this->f[$this->f_no]['items'array();
  754.  
  755.         $this->f[$this->f_no]['constant_items'array();
  756.         $this->f[$this->f_no]['php_items'array();
  757.         $this->f[$this->f_no]['cmd_items'array();
  758.  
  759.         $this->f[$this->f_no]['create_cached_file'0;
  760.         $this->f[$this->f_no]['time_started'0;
  761.         $this->f[$this->f_no]['cache_expire'0;
  762.         $this->f[$this->f_no]['execution_time'0;
  763.         $this->f[$this->f_no]['chrono_started'0;
  764.  
  765.         $this->f[$this->f_no]['shortcut_blocs'array();
  766.         $this->f[$this->f_no]['shortcut_blocs']['all'array();
  767.         $this->f[$this->f_no]['shortcut_blocs']['used'array();
  768.  
  769.         $this->f[$this->f_no]['shortcut_blocs']['name'null;
  770.         $this->f[$this->f_no]['shortcut_blocs']['name']['items'array();
  771.  
  772.         $this->f[$this->f_no]['def_blocs'array();
  773.  
  774.         $this->chrono_type[$this->f_nonull;
  775.  
  776.         $time explode(' 'microtime());
  777.         $this->f[$this->f_no]['time_started'time();
  778.         $this->f[$this->f_no]['chrono_started'$time[1$time[0];
  779.  
  780.         // defines the chrono
  781.         if(!defined('TPLN_CHRONO_STARTED'))
  782.         {
  783.             $chrono $time[1$time[0];
  784.             define('TPLN_CHRONO_STARTED'$chrono);
  785.         }
  786.  
  787.         $this->parseConstants();
  788.  
  789.         // replaces the variables with $
  790.         if(TPLN_PARSE_GLOBALS)$this->ParseGlobals();
  791.  
  792.         // replaces the files to include
  793.         $this->captureIncludeCmd()// captures the include commands
  794.  
  795.         // parsing and evaluation if necessary
  796.         if(count($this->f[$this->f_no]['cmd_items']0)
  797.         {
  798.             $this->parseAllIncludeCmd();
  799.             $this->f[$this->f_no]['cmd_items'array()// delete
  800.         }
  801.         // replaces the $ if there are contained in including files
  802.         if(TPLN_PARSE_GLOBALS$this->ParseGlobals();
  803.  
  804.         $this->f[$this->f_no]['shortcut_blocs']['all'$this->captureAllBlocs();
  805.         $this->endBlocVerify();
  806.         $this->dualBlocVerify();
  807.  
  808.         // Captures the items after cheking the blocs
  809.         $this->f[$this->f_no]['items'$this->captureItems();
  810.         $this->captureItemsInEachBloc();
  811.  
  812.         // debugger
  813.         $this->structOpen();
  814.  
  815.         if($this->f[$this->f_no]['create_cached_file'== 1)
  816.             return false;
  817.     }
  818.  
  819.     /**
  820.      * this method is a macro which allows to open and to write a template.
  821.      *
  822.      * @param string $file 
  823.      * @author H2LSOFT */
  824.     public function directIoWrite($file '')
  825.     {
  826.         $c_id $this->f_no// saves the actual number
  827.         $this->open($file);
  828.         $this->write();
  829.         $this->f_no = $c_id// puts the number
  830.     }
  831.  
  832.     /**
  833.      * this method is a macro wich allows to open and to return a template.
  834.      *
  835.      * @param string $file 
  836.      *
  837.      * @return string 
  838.      * @author H2LSOFT */
  839.     public function directIoOutput($file '')
  840.     {
  841.         $c_id $this->f_no// saves the actual number
  842.         $this->open($file);
  843.         $output $this->outPut();
  844.         $this->f_no = $c_id// puts the number
  845.  
  846.         return $output;
  847.     }
  848.  
  849.     /**
  850.      * this method is a macro which allows to open and to save a template.
  851.      *
  852.      * @param string $file 
  853.      * @param string $path 
  854.      * @author H2LSOFT */
  855.     public function directIOSave($file ''$path)
  856.     {
  857.         $c_id $this->f_no// saves the actual number
  858.         $this->open($file);
  859.         $this->saveTemplate($path);
  860.         $this->f_no = $c_id// puts the number
  861.     }
  862.  
  863.     /**
  864.      * this method allows to open and to name various templates.
  865.      *
  866.      * @param array $arr 
  867.      *
  868.      * @author H2LSOFT */
  869.     public function defineTemplate($arr)
  870.     {
  871.         if(!is_array($arr))
  872.         {
  873.             $this->error(12);
  874.             return;
  875.         }
  876.  
  877.         foreach($arr as $key => $val)
  878.         {
  879.             $this->open($val);
  880.             $this->def_tpl[count($this->f)-1$key;
  881.         }
  882.     }
  883.  
  884.     /**
  885.      * this method allows to select a template which has been opened by the Open()
  886.      *
  887.      * or DefineTemplate() methods is by a name or a number.
  888.      *
  889.      * @param string $key 
  890.      *
  891.      * @deprecated
  892.      * @since 1.4
  893.      * @author H2LSOFT */
  894.     public function setTemplate($key)
  895.     {
  896.         $this->changeTemplate($key);
  897.     }
  898.  
  899.     /**
  900.      * this method allows you to select a template opened by Open()
  901.      *
  902.      * or DefineTemplate() methods either by name or by number.
  903.      *
  904.      * @param string $key 
  905.      * @since 2.9
  906.      * @see getTemplateID
  907.      * @author H2LSOFT */
  908.     public function setTemplateID($key)
  909.     {
  910.         $this->changeTemplate($key);
  911.     }
  912.  
  913.     /**
  914.      * This method returns curent template index
  915.      *
  916.      * @return int template index
  917.      */
  918.     public function getTemplateID()
  919.     {
  920.         return $this->f_no;
  921.  
  922.     }
  923.  
  924.     /**
  925.      * this method allows to select a template opened by Open()
  926.      *
  927.      * or DefineTemplate() methods either by name or by number.
  928.      *
  929.      * @param string $key 
  930.      *
  931.      * @author H2LSOFT */
  932.     public function changeTemplate($key)
  933.     {
  934.         if(is_string($key))
  935.         {
  936.             // taks the id
  937.             if(!in_array($key$this->def_tpltrue))
  938.             {
  939.                 $this->error(11$key);
  940.                 return;
  941.             }
  942.  
  943.             $key array_search($key$this->def_tpltrue);
  944.         }
  945.  
  946.         if(is_int($key))
  947.         {
  948.             if($key || $key >= count($this->f))
  949.             {
  950.                 $this->error(10$key);
  951.             }
  952.         }
  953.  
  954.         $this->f_no = $key;
  955.     }
  956.  
  957.     /**
  958.      * this method allows to parse a variable Php by a variable contained in the template.
  959.      * @since 2.1, 2.4
  960.      * @see Parse(), FastParse().
  961.      * @author H2LSOFT */
  962.     public function parseGlobals()
  963.     {
  964.         $this->f[$this->f_no]['php_items'$this->captureItems('''PHP');
  965.  
  966.         if(count($this->f[$this->f_no]['php_items']== 0)
  967.         {
  968.             return;
  969.         }
  970.  
  971.         @extract($GLOBALSEXTR_SKIP || EXTR_REFS);
  972.         foreach($this->f[$this->f_no]['php_items'as $item)
  973.         {
  974.             $replace '$'.$item;
  975.             //if(!eregi("\(", $replace)) // protection security of methods and functions !
  976.             if(strpos($replace"("=== false// protection security of methods and functions !
  977.  
  978.             {
  979.                 @eval("\$tmp = $replace;");
  980.                 $item '$'.$item;
  981.                 $item str_replace('$''\$'$item);
  982.                 $item str_replace('[''\['$item);
  983.                 $item str_replace(']''\]'$item);
  984.                 $this->f[$this->f_no]['buffer'$this->replaceItem($item$tmp$this->f[$this->f_no]['buffer']);
  985.             }
  986.         }
  987.     }
  988.  
  989.     /**
  990.      * this method allows to substitute a variable defined inside the template file.
  991.      *
  992.      * TPLN use a style javascript pseudo object language to access to the variable by the separator ".".
  993.      *
  994.      * @param string $path 
  995.      * @param string $replace 
  996.      * @param string $functions 
  997.      * @see ParseBloc()
  998.      * @author H2LSOFT */
  999.     public function parse($path$replace$functions '')
  1000.     {
  1001.         // formatting function of data
  1002.         $replace $this->applySpecialFunction($replace$functions);
  1003.  
  1004.         if($this->isBlocDesired($path)) // is it a bloc ?
  1005.  
  1006.         {
  1007.             $item $this->getItem($path)// taks the item
  1008.             $fathers_arr $this->getFathers($path'ARRAY')// les p�res ds un array
  1009.             $bloc $this->getFather($path)// on prend le p�re
  1010.  
  1011.             if(!$this->blocExists($bloc))
  1012.                 $this->error(2$this->f[$this->f_no]['name']$bloc);
  1013.  
  1014.             $this->itemVerify($item$bloc)// verification
  1015.  
  1016.             if(!$this->isDefined($path)) // the path is saved ?
  1017.                 $this->defineBloc($path)// define the blocs one by one
  1018.  
  1019.             $this->directParseInBloc($fathers_arr$item$replace);
  1020.         }
  1021.         else
  1022.         {
  1023.             $this->itemVerify($path)// verification
  1024.             $this->directParseInFile($path$replace)// direct parsing in the file
  1025.         }
  1026.     }
  1027.  
  1028.     /**
  1029.      * this method
  1030.      *
  1031.      * @param int $item 
  1032.      * @param int $replace 
  1033.      * @author H2LSOFT */
  1034.     protected function directParseInFile($item$replace)
  1035.     {
  1036.         $this->f[$this->f_no]['buffer'$this->replaceItem($item$replace$this->f[$this->f_no]['buffer']);
  1037.     }
  1038.  
  1039.     /**
  1040.      * this method
  1041.      *
  1042.      * @param array $fathers_arr 
  1043.      * @param int $item 
  1044.      * @param int $replace 
  1045.      * @author H2LSOFT */
  1046.     protected function directParseInBloc($fathers_arr$item$replace)
  1047.     {
  1048.         $b_ref $this->f[$this->f_no]['def_blocs'];
  1049.         // reachs the block
  1050.         for($i 0;$i count($fathers_arr);$i++)
  1051.         {
  1052.             $b_ref $b_ref[$fathers_arr[$i]];
  1053.  
  1054.             if($i count($fathers_arr)-1)
  1055.                 $b_ref $b_ref['children'];
  1056.         }
  1057.  
  1058.         // check if there was a loop>0
  1059.         $loop_nb count($b_ref['parsed']);
  1060.         $b_ref['parsed'][$loop_nb-1$this->replaceItem($item$replace$b_ref['parsed'][$loop_nb-1]);
  1061.     }
  1062.  
  1063.     /**
  1064.      * this method is like Parse() method but it avoids to rewrite definied variables.
  1065.      *
  1066.      * @param string $path 
  1067.      * @param string $functions 
  1068.      * @author H2LSOFT */
  1069.     public function fastParse($path$functions '')
  1070.     {
  1071.         // if it's a block then replace
  1072.         if($this->isBlocDesired($path))
  1073.             $item $this->getItem($path)// taks the last item
  1074.         else
  1075.             $item $path;
  1076.         $this->parse($path$GLOBALS[$item]$functions);
  1077.     }
  1078.  
  1079.     /**
  1080.      * this method allows to substitute the items by the pairs keys of an array in a whole block.
  1081.      *
  1082.      * The 3rd parameters allows to replace entire block if no data foud in array.
  1083.      *
  1084.      * @param string $path 
  1085.      * @param array $arr 
  1086.      * @param string $msg 
  1087.      * @param boolean $looped 
  1088.      *
  1089.      * @since 2.3
  1090.      * @author H2LSOFT */
  1091.     public function loadArrayInBloc($path$arr$msg ''$looped false)
  1092.     {
  1093.         if(count($arr== 0)
  1094.         {
  1095.             if(!$looped)
  1096.             {
  1097.                 $this->parseBloc($path$msg);
  1098.             }
  1099.             else
  1100.             {
  1101.                 $this->eraseBloc($path$msg);
  1102.                 $this->loop($path);
  1103.             }
  1104.         }
  1105.         else
  1106.         {
  1107.             foreach($arr as $current_arr)
  1108.             {
  1109.                 $sub_blocs array();
  1110.                 $keys @array_keys($current_arr);
  1111.                 foreach($keys as $key)
  1112.                 {
  1113.                     if(!is_array($current_arr[$key]))
  1114.                     {
  1115.                         $zpath $path;
  1116.                         if($looped)
  1117.                         {
  1118.                             $ttmp explode('.'$zpath);
  1119.                             $zpath $ttmp[count($ttmp)-1];
  1120.                         }
  1121.  
  1122.                         if($this->itemExists($key$zpath))
  1123.                         {
  1124.                             //echo "parse: $path.$key".'<br />';
  1125.                             $this->parse("$path.$key"$current_arr[$key]);
  1126.                         }
  1127.                     }
  1128.                     else
  1129.                     {
  1130.                         $sub_bloc $key;
  1131.                         $this->loadArrayInBloc($path.'.'.$sub_bloc$current_arr[$key]$msgtrue);
  1132.                     }
  1133.                 }
  1134.                 //echo "loop: $path".'<hr />';
  1135.                 $this->loop($path);
  1136.             }
  1137.         }
  1138.     }
  1139.  
  1140.     /**
  1141.      * this method is applied to a block to report is looping.
  1142.      *
  1143.      * @param string $path 
  1144.      * @author H2LSOFT */
  1145.     public function loop($path)
  1146.     {
  1147.         // check the existence of the path
  1148.         if(!$this->isDefined($path'NOITEM'))
  1149.         {
  1150.             $this->error(4.1$this->f[$this->f_no]['name']$path);
  1151.             return;
  1152.         }
  1153.  
  1154.         $fathers_arr $this->getFathers($path'ARRAY'0);
  1155.  
  1156.         // touch the block
  1157.         $b_ref $this->f[$this->f_no]['def_blocs'];
  1158.  
  1159.         for($i 0;$i count($fathers_arr);$i++)
  1160.         {
  1161.             $b_ref $b_ref[$fathers_arr[$i]];
  1162.  
  1163.             if($i count($fathers_arr)-1)
  1164.             {
  1165.                 $b_ref $b_ref['children'];
  1166.             }
  1167.         }
  1168.  
  1169.         // all the following génération is replaced
  1170.         if(count($b_ref['children']0)
  1171.         {
  1172.             // $level = count($fathers_arr)-1;
  1173.             $child_blocs $this->getNextGenerationBlocs($fathers_arr);
  1174.             // encapsulate the blocks
  1175.             $this->encapsuleBlocs($fathers_arr$child_blocs);
  1176.         }
  1177.  
  1178.         // add one session parse
  1179.         // increment the value of loop
  1180.         $b_ref['parsed'][$b_ref['structure'];
  1181.         $b_ref['is_looped'1;
  1182.     }
  1183.  
  1184.     /**
  1185.      * this method
  1186.      *
  1187.      * @param array $bloc_arr 
  1188.      * @return array 
  1189.      * @author H2LSOFT */
  1190.     protected function getNextGenerationBlocs($bloc_arr)
  1191.     {
  1192.         // touch the block
  1193.         $b_ref $this->f[$this->f_no]['def_blocs'];
  1194.  
  1195.         for($i 0;$i count($bloc_arr);$i++)
  1196.         {
  1197.             $b_ref $b_ref[$bloc_arr[$i]];
  1198.  
  1199.             if($i count($bloc_arr)-1)
  1200.             {
  1201.                 $b_ref $b_ref['children'];
  1202.             }
  1203.         }
  1204.  
  1205.         $b_names array_keys($b_ref['children']);
  1206.  
  1207.         return $b_names;
  1208.     }
  1209.  
  1210.     /**
  1211.      * this method
  1212.      *
  1213.      * @param array $bloc_arr 
  1214.      * @param array $child_blocs 
  1215.      * @author H2LSOFT */
  1216.     protected function encapsuleBlocs($bloc_arr$child_blocs)
  1217.     {
  1218.         // encapsulate each child CAD
  1219.         // contracting the block if it has chidren
  1220.         // parsing at father of the son parsed
  1221.         // puts zero in the son block
  1222.         foreach($child_blocs as $children)
  1223.         {
  1224.             // touch the block
  1225.             $b_ref $this->f[$this->f_no]['def_blocs'];
  1226.  
  1227.             for($i 0;$i count($bloc_arr);$i++)
  1228.             {
  1229.                 $b_ref $b_ref[$bloc_arr[$i]];
  1230.  
  1231.                 if($i == count($bloc_arr)-1)
  1232.                     $father_parsed $b_ref['parsed'][count($b_ref['parsed'])-1]// c'est le dernier
  1233.  
  1234.                 $b_ref $b_ref['children'];
  1235.             }
  1236.  
  1237.             $children_all_parsed $b_ref[$children]['parsed'];
  1238.             $children_structure $b_ref[$children]['structure'];
  1239.             $children_parsed '';
  1240.             // block
  1241.             if(count($children_all_parsed== 1)
  1242.                 $children_parsed $children_all_parsed['0'];
  1243.  
  1244.             if(count($children_all_parsed1)
  1245.             {
  1246.                 for($l 0$l count($children_all_parsed)-1$l++)
  1247.                     $children_parsed $children_parsed.$children_all_parsed[$l];
  1248.             }
  1249.             // parsing at the father
  1250.             $father_parsed $this->replaceBloc($children$children_parsed$father_parsed);
  1251.             // puts zero in the child block
  1252.             $children_all_parsed array($children_structure);
  1253.             unset($children_parsed);
  1254.         }
  1255.     }
  1256.  
  1257.     /**
  1258.      * this method allows to delete a variable.
  1259.      *
  1260.      * @param string $item 
  1261.      *
  1262.      * @since 2.9
  1263.      * @author H2LSOFT */
  1264.     public function eraseItem($item)
  1265.     {
  1266.         if(is_array($item))
  1267.         {
  1268.             foreach($item as $tmp)
  1269.                 $this->parse($tmp'');
  1270.         }
  1271.         else
  1272.             $this->parse($item'');
  1273.     }
  1274.  
  1275.     /**
  1276.      * this method allows you to delete a block.
  1277.      *
  1278.      * But if the bolck is one, the substitution will be done in the template.
  1279.      *
  1280.      * @param string $path 
  1281.      * @param string $msg 
  1282.      *
  1283.      * @since 2.9
  1284.      * @author H2LSOFT */
  1285.     public function eraseBloc($path$msg='')
  1286.     {
  1287.         if(is_array($path))
  1288.         {
  1289.             foreach($path as $tmp)
  1290.                 $this->parseBloc($tmp$msg);
  1291.         }
  1292.         else
  1293.             $this->parseBloc($path$msg);
  1294.     }
  1295.  
  1296.     /**
  1297.      * this method allows you to return the contents of file.
  1298.      *
  1299.      * If the block name optional parameter is specified the method will return
  1300.      *
  1301.      * the contents of the block defined in the file.
  1302.      *
  1303.      * @param string $filename 
  1304.      * @param string $blocname 
  1305.      *
  1306.      * @return string 
  1307.      * @author H2LSOFT */
  1308.     public function getFile($filename$blocname '')
  1309.     {
  1310.         if(!$fp @fopen($filename'r')) // opening the file on reding
  1311.         {
  1312.             $this->error(0$filename);
  1313.         }
  1314.  
  1315.         $filebuffer @fread($fpfilesize($filename));
  1316.         @fclose($fp);
  1317.         clearstatcache()// delete the Data buffer
  1318.  
  1319.         if(!empty($blocname)) // capture the block
  1320.             $filebuffer $this->captureBloc($blocname$filebuffer);
  1321.  
  1322.         return $filebuffer;
  1323.     }
  1324.  
  1325.     /**
  1326.      * this method allows to substitute a whole bloc and markers also.
  1327.      *
  1328.      * @param string $path 
  1329.      * @param string $replace 
  1330.      * @see parse()
  1331.      * @author H2LSOFT */
  1332.     public function parseBloc($path$replace)
  1333.     {
  1334.         $this->pathVerify($path)// check the existence of blocks of the path
  1335.  
  1336.         // definition of the path
  1337.         if(!$this->isdefined($path'NOITEM')) $this->defineBloc($path.'.none');
  1338.  
  1339.         // imbricated block?
  1340.         if(!$this->isBlocDesired($path))
  1341.         {
  1342.             $this->f[$this->f_no]['buffer'$this->replaceBloc($path$replace$this->f[$this->f_no]['buffer']);
  1343.             $bloc_arr[$path;
  1344.         }
  1345.         else
  1346.         {
  1347.             // go to the bloc for éliminating !
  1348.             $bloc_arr $this->getFathers($path'ARRAY'0);
  1349.         }
  1350.  
  1351.         // delete the blok
  1352.         $b_ref $this->f[$this->f_no]['def_blocs'];
  1353.  
  1354.         // only one block ?
  1355.         if(count($bloc_arr== 1)
  1356.         {
  1357.             $b_ref $b_ref[$bloc_arr[0]];
  1358.         }
  1359.         else
  1360.         {
  1361.             // delete the current block in the last father
  1362.             for($i 0;$i count($bloc_arr);$i++)
  1363.             {
  1364.                 $b_ref $b_ref[$bloc_arr[$i]];
  1365.  
  1366.                 if($i == count($bloc_arr)-2)
  1367.                     $last_father_parsed $b_ref['parsed'][count($b_ref['parsed'])-1];
  1368.  
  1369.                 if($i count($bloc_arr)-1)
  1370.                     $b_ref $b_ref['children'];
  1371.             }
  1372.  
  1373.             $last_father_parsed $this->replaceBloc($bloc_arr[count($bloc_arr)-1]$replace$last_father_parsed);
  1374.         }
  1375.  
  1376.         $b_ref['parsed'array()// delete the session of the last block !
  1377.     }
  1378.  
  1379.     /**
  1380.      * this method allows to reload variables of a block contained in the template.
  1381.      *
  1382.      * @param string $path 
  1383.      * @since 1.5
  1384.      * @author H2LSOFT */
  1385.     public function reloadBlocVars($path)
  1386.     {
  1387.         $this->pathVerify($path);
  1388.  
  1389.         $last_bloc $this->getItem($path);
  1390.         $this->f[$this->f_no]['shortcut_blocs'][$last_bloc]['items'$this->captureItems($last_bloc);
  1391.     }
  1392.  
  1393.     /**
  1394.      * this method allows to substitute a variable from the template file by the contents of a file.
  1395.      *
  1396.      * @param string $item 
  1397.      * @param string $file 
  1398.      *
  1399.      * @see GetBlocInFile()
  1400.      * @author H2LSOFT */
  1401.     public function includeFile($item$file)
  1402.     {
  1403.         // checking for one block
  1404.         $this->parse($item"{#include(\"$file\");}")// replace by the include command
  1405.         $this->f[$this->f_no]['cmd_items'][$file// add to the list of f_cmd
  1406.     }
  1407.  
  1408.     /**
  1409.      * this method allows to return a whole block from the template file.
  1410.      *
  1411.      * @param string $path 
  1412.      *
  1413.      * @return string 
  1414.      *
  1415.      * @since IncludeFile()
  1416.      * @author H2LSOFT */
  1417.     public function getBlocInFile($path)
  1418.     {
  1419.         $this->pathVerify($path);
  1420.         $all_bloc explode('.'$path);
  1421.         $bloc_name $all_bloc[count($all_bloc)-1];
  1422.         $bloc $this->captureBloc($bloc_name$this->f[$this->f_no]['buffer']);
  1423.  
  1424.         return $bloc;
  1425.     }
  1426.  
  1427.     /**
  1428.      * this method allows to print file the template parsed.
  1429.      * @see Parse(), Output()
  1430.      * @author H2LSOFT */
  1431.     public function write()
  1432.     {
  1433.         $this->out();
  1434.         echo $this->f[$this->f_no]['buffer'];
  1435.         $this->createCache(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['name']);
  1436.         if(TPLN_AUTO_UNSET_TEMPLATE$this->initTemplateVars();
  1437.     }
  1438.  
  1439.     /**
  1440.      * this method allows to return the contents of the template file parsed.
  1441.      *
  1442.      * @return string 
  1443.      * @author H2LSOFT */
  1444.     public function output()
  1445.     {
  1446.         $this->out();
  1447.         $this->createCache(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['name']);
  1448.         $buffer $this->f[$this->f_no]['buffer'];
  1449.         if(TPLN_AUTO_UNSET_TEMPLATE$this->initTemplateVars();
  1450.  
  1451.         return $buffer;
  1452.     }
  1453.  
  1454.     /**
  1455.      * this method allows to save the contents of the template file parsed.
  1456.      *
  1457.      * @param string $path 
  1458.      * @see write()
  1459.      * @author H2LSOFT */
  1460.     public function saveTemplate($path)
  1461.     {
  1462.         // add function for creating folders
  1463.         $act_dir '';
  1464.         $all_dir explode('/'$path);
  1465.  
  1466.         if(count($all_dir1)
  1467.         {
  1468.             for($i 0;$i count($all_dir)-1;$i++)
  1469.             {
  1470.                 if($i 0)$act_dir .= '/';
  1471.                 $act_dir .= $all_dir[$i];
  1472.  
  1473.                 if(!is_dir($act_dir))
  1474.                 {
  1475.                     if(!@mkdir($act_dir0755))
  1476.                     {
  1477.                         $this->error(7.1$act_dir);
  1478.                         return;
  1479.                     }
  1480.  
  1481.                     clearstatcache();
  1482.                 }
  1483.             }
  1484.         }
  1485.  
  1486.         $output $this->Output();
  1487.         $fp @fopen($path'w')// open file
  1488.         @fwrite($fp$output);
  1489.         @fclose($fp);
  1490.         clearstatcache()// erase the file
  1491.     }
  1492.  
  1493.     /**
  1494.      * this method applays special function in item
  1495.      *
  1496.      * @param string $replace 
  1497.      * @param string $functions 
  1498.      *
  1499.      * @return string 
  1500.      * @since 2.9
  1501.      * @author H2LSOFT */
  1502.     protected function applySpecialFunction($replace ''$functions '')
  1503.     {
  1504.         if(empty($functions))return $replace;
  1505.  
  1506.         // there is a special function ?
  1507.         $functions explode('|'$functions);
  1508.  
  1509.         foreach($functions as $function_name)
  1510.         {
  1511.             if($function_name != 'B' && $function_name != 'I' && $function_name != 'U' && $function_name != 'S' && !empty($function_name))
  1512.             {
  1513.                 $replace $function_name($replace);
  1514.             }
  1515.         }
  1516.         // Bold, Italic, Underline
  1517.         if(in_array('B'$functions))$replace "<strong>$replace</strong>";
  1518.         if(in_array('I'$functions))$replace "<i>$replace</i>";
  1519.         if(in_array('U'$functions))$replace "<u>$replace</u>";
  1520.         if(in_array('S'$functions))$replace "<s>$replace</s>";
  1521.  
  1522.         return $replace;
  1523.     }
  1524.  
  1525. // replace the son in the father
  1526.     /**
  1527.      * this method
  1528.      *
  1529.      * @param array $bloc 
  1530.      * @author H2LSOFT */
  1531.     protected function parseEncapsuledBlocs($bloc)
  1532.     {
  1533.         // reach the last block
  1534.         // preserve conserve the father (adress) and his son (nom, structure)
  1535.         // delete the last member of the block
  1536.         while(count($bloc1)
  1537.         {
  1538.             $b_ref $this->f[$this->f_no]['def_blocs'];
  1539.  
  1540.             for($i 0;$i count($bloc);$i++)
  1541.             {
  1542.                 $b_ref $b_ref[$bloc[$i]];
  1543.  
  1544.                 if($i == count($bloc2// capture of the last father
  1545.                     $father_parsed $b_ref['parsed'][count($b_ref['parsed'])-1];
  1546.  
  1547.                 if($i == count($bloc1// capture of the last son
  1548.  
  1549.                 {
  1550.                     $children_name $bloc[$i];
  1551.                     $children_all_parsed $b_ref['parsed'];
  1552.                     $children_parsed null;
  1553.  
  1554.                     if(count($children_all_parsed1)
  1555.                     {
  1556.                         for($j 0;$j count($children_all_parsed)-1;$j++)
  1557.                             $children_parsed .= $children_all_parsed[$j];
  1558.                     }
  1559.                     else
  1560.                     {
  1561.                         if(count($children_all_parsed== 1)
  1562.                             $children_parsed $children_all_parsed[0];
  1563.                     }
  1564.                 }
  1565.  
  1566.                 $b_ref $b_ref['children'];
  1567.             }
  1568.  
  1569.             // replace the son in the father
  1570.             $father_parsed $this->replaceBloc($children_name$children_parsed$father_parsed);
  1571.  
  1572.             // delete the last block
  1573.             unset($children_parsed);
  1574.             $bloc array_slice($bloc0count($bloc)-1);
  1575.         }
  1576.     }
  1577.  
  1578.     /**
  1579.      * this method
  1580.      *
  1581.      * @param int $level 
  1582.      * @param array $bloc_arr 
  1583.      *
  1584.      * @return boolean 
  1585.      * @author H2LSOFT */
  1586.     protected function parseSubBlocs($level$bloc_arr)
  1587.     {
  1588.         $b_ref $this->f[$this->f_no]['def_blocs'];
  1589.  
  1590.         foreach($bloc_arr as $cur_bloc)
  1591.         {
  1592.             $b_ref $b_ref[$cur_bloc]['children'];
  1593.         }
  1594.  
  1595.         if(!is_array($b_ref))return;
  1596.  
  1597.         $b_names array_keys($b_ref)// contains all names of the blocks
  1598.  
  1599.         foreach($b_names as $bloc)
  1600.         {
  1601.             if(count($b_ref[$bloc]['children']0)
  1602.             {
  1603.                 $bloc_arr[$bloc;
  1604.                 $this->parseSubBlocs($level 1$bloc_arr);
  1605.             }
  1606.             else
  1607.             {
  1608.                 $bloc_arr array_slice($bloc_arr0$level 1);
  1609.                 $bloc_arr[$bloc;
  1610.                 $this->parseEncapsuledBlocs($bloc_arr);
  1611.             }
  1612.         }
  1613.     }
  1614.  
  1615.     /**
  1616.      * this method
  1617.      *
  1618.      * @author H2LSOFT */
  1619.     protected function parseBigFathers()
  1620.     {
  1621.         // takes the parsed father and replace it in the buffer
  1622.         $b_ref $this->f[$this->f_no]['def_blocs'];
  1623.         // takes the names or parent BIG
  1624.         $b_names array_keys($b_ref);
  1625.         $b_parsed ''// initialisation
  1626.  
  1627.         foreach($b_names as $bloc)
  1628.         {
  1629.             if(count($b_ref[$bloc]['parsed']== && array_key_exists('0'$b_ref[$bloc]['parsed']))
  1630.                 $b_parsed $b_ref[$bloc]['parsed'][0];
  1631.  
  1632.             // if a block is in loop
  1633.             if(count($b_ref[$bloc]['parsed']1)
  1634.             {
  1635.                 // don't takes the first
  1636.                 for($i 0;$i count($b_ref[$bloc]['parsed'])-1;$i++)
  1637.                     $b_parsed .= $b_ref[$bloc]['parsed'][$i];
  1638.             }
  1639.  
  1640.             $this->f[$this->f_no]['buffer'$this->replaceBloc($bloc$b_parsed$this->f[$this->f_no]['buffer']);
  1641.             // unset($b_parsed);
  1642.             $b_parsed '';
  1643.         }
  1644.     }
  1645.  
  1646.     /**
  1647.      * this method
  1648.      *
  1649.      * @return string 
  1650.      * @author H2LSOFT */
  1651.     protected function getBigBlocs()
  1652.     {
  1653.         // touch the block
  1654.         $b_ref $this->f[$this->f_no]['def_blocs'];
  1655.         $b_names array_keys($b_ref);
  1656.         return $b_names;
  1657.     }
  1658.  
  1659.     /**
  1660.      * this method
  1661.      *
  1662.      * @author H2LSOFT */
  1663.     protected function out()
  1664.     {
  1665.         if(count($this->f[$this->f_no]['def_blocs']0)
  1666.         {
  1667.             $b_ref $this->f[$this->f_no]['def_blocs'];
  1668.             // obtains the names of big blocks
  1669.             $big_blocs $this->getBigBlocs();
  1670.  
  1671.             foreach($big_blocs as $bloc)
  1672.             {
  1673.                 if(count($b_ref[$bloc]['children']0)
  1674.                     $this->parseSubBlocs(0(array)$bloc);
  1675.             }
  1676.  
  1677.             $this->parseBigFathers()// compress the big blocks and parse in the buffer
  1678.         }
  1679.  
  1680.         $this->parseAllIncludeCmd();
  1681.         $this->parseChrono();
  1682.         $this->parseLogo();
  1683.         $this->parseVersion();
  1684.         $this->parseQueryCount();
  1685.  
  1686.         if(TPLN_AUTO_CLEAN_BLOCS$this->cleanBLocs();
  1687.         // compression ?
  1688.         if($this->HTMLCompress)
  1689.         {
  1690.             $this->f[$this->f_no]['buffer'preg_replace("/(\r\n|\n)/"''$this->f[$this->f_no]['buffer']);
  1691.         }
  1692.     }
  1693.  
  1694.     /**
  1695.      * this method captures items
  1696.      *
  1697.      * @param string $subject 
  1698.      * @param string $type 
  1699.      *
  1700.      * @return string 
  1701.      * @author H2LSOFT */
  1702.     protected function captureItems($subject ''$type '')
  1703.     {
  1704.         if(empty($subject))
  1705.         {
  1706.             $subject $this->f[$this->f_no]['buffer']// in the file
  1707.             $blocs $this->f[$this->f_no]['shortcut_blocs']['all'];
  1708.         }
  1709.         else
  1710.         {
  1711.             $subject $this->captureBloc($subject$this->f[$this->f_no]['buffer']);
  1712.             // capture the blocks of subjet
  1713.             $blocs $this->captureAllBlocs($subject);
  1714.             // delete them
  1715.             foreach($blocs as $bloc)
  1716.                 $subject $this->replaceBloc($bloc''$subject);
  1717.         }
  1718.         // exclusion of spaces etc
  1719.         if($type == 'PHP')
  1720.         {
  1721.             $motif "/\{\\$([^ ;\*\$\\\,\\n\\t]+)?\}/msU";
  1722.         }
  1723.         elseif($type == 'CONSTANT')
  1724.         {
  1725.             $motif "/\{CONST::([^ ;\.\*\$\\\,\\n\\t]+)?\}/msU";
  1726.         }
  1727.         else
  1728.         {
  1729.             $motif "/\{([^ ;\.\*\$\\\,\\n\\t]+)?\}/msU";
  1730.         }
  1731.  
  1732.         $match preg_match_all($motif$subject$tab);
  1733.  
  1734.         // duplicate the array
  1735.         $one array();
  1736.  
  1737.         if(count($tab[1]0)
  1738.             $one array_unique($tab[1]);
  1739.  
  1740.         return $one;
  1741.     }
  1742.  
  1743.     /**
  1744.      * this method captures block
  1745.      *
  1746.      * @param string $name 
  1747.      * @param string $subject 
  1748.      *
  1749.      * @return string 
  1750.      * @author H2LSOFT */
  1751.     protected function captureBloc($name$subject)
  1752.     {
  1753.         if(empty($name))
  1754.         {
  1755.             $this->error(5$this->f[$this->f_no]['name']);
  1756.             return;
  1757.         }
  1758.  
  1759.         $motif "<bloc::$name>(.*)?<\\/bloc::$name>";
  1760.         $match @preg_match("/$motif/msU"$subject$bloc);
  1761.         // error
  1762.         if(!$match)
  1763.         {
  1764.             $this->error(2$this->f[$this->f_no]['name']$name);
  1765.             return;
  1766.         }
  1767.  
  1768.         $bloc @$bloc[1];
  1769.         $bloc @rtrim($bloc);
  1770.  
  1771.         return $bloc;
  1772.     }
  1773.  
  1774.     /**
  1775.      * this method captures all blocks
  1776.      *
  1777.      * @param string $subject 
  1778.      * @return string 
  1779.      * @author H2LSOFT */
  1780.     protected function captureAllBlocs($subject '')
  1781.     {
  1782.         if(empty($subject))
  1783.         {
  1784.             $subject $this->f[$this->f_no]['buffer'];
  1785.         }
  1786.  
  1787.         $motif "<bloc::([^ ;\.\*\$\\\,\\n\\t]+)?>";
  1788.         $match preg_match_all("/$motif/U"$subject$blocs);
  1789.  
  1790.         return $blocs[1];
  1791.     }
  1792.  
  1793.     /**
  1794.      * this method captures items in each block
  1795.      *
  1796.      * @return boolean 
  1797.      * @author H2LSOFT */
  1798.     protected function captureItemsInEachBloc()
  1799.     {
  1800.         if(count($this->f[$this->f_no]['shortcut_blocs']['all']== 0)
  1801.             return;
  1802.  
  1803.         foreach($this->f[$this->f_no]['shortcut_blocs']['all'as $bloc)
  1804.             $this->f[$this->f_no]['shortcut_blocs'][$bloc]['items'$this->captureItems($bloc);
  1805.     }
  1806.  
  1807.     /**
  1808.      * this method gets all blocks
  1809.      *
  1810.      * @param string $subject 
  1811.      *
  1812.      * @return array 
  1813.      * @author H2LSOFT */
  1814.     protected function getAllBlocs($subject)
  1815.     {
  1816.         $motif "<bloc::([^ ;\.\*\$\\\,\\n\\t]+)?>";
  1817.         preg_match_all("/$motif/U"$subject$blocs);
  1818.         return $blocs[1];
  1819.     }
  1820.  
  1821.     /**
  1822.      * this method captures include commands in the template
  1823.      *
  1824.      * @return boolean 
  1825.      * @author H2LSOFT */
  1826.     protected function captureIncludeCmd()
  1827.     {
  1828.         $motif "\{#include\(([^ ;\*,\\n\\t]+)?\);\}";
  1829.         $match preg_match_all("/$motif/U"$this->f[$this->f_no]['buffer']$tab);
  1830.  
  1831.         if(count($tab[1]== 0)
  1832.             return;
  1833.  
  1834.         $one array_unique($tab[1]);
  1835.         $this->f[$this->f_no]['cmd_items'$one;
  1836.     }
  1837.  
  1838.     /**
  1839.      * this method allows to know if a variable exists in the template file.
  1840.      *
  1841.      * @param string $item_name 
  1842.      * @param string $bloc 
  1843.      *
  1844.      * @return boolean 
  1845.      * @see BlocExists()
  1846.      * @author H2LSOFT */
  1847.     public function itemExists($item_name$bloc '')
  1848.     {
  1849.         if(empty($bloc))
  1850.         {
  1851.             if(@in_array($item_name$this->f[$this->f_no]['items']))
  1852.                 return true;
  1853.             else
  1854.                 return false;
  1855.         }
  1856.         else
  1857.         {
  1858.             if(@in_array($item_name$this->f[$this->f_no]['shortcut_blocs'][$bloc]['items']))
  1859.                 return true;
  1860.             else
  1861.                 return false;
  1862.         }
  1863.     }
  1864.  
  1865.     /**
  1866.      * this method verifies item
  1867.      *
  1868.      * @param string $item 
  1869.      * @param string $bloc 
  1870.      *
  1871.      * @return boolean 
  1872.      *
  1873.      * @author H2LSOFT */
  1874.     protected function itemVerify($item$bloc '')
  1875.     {
  1876.         if(empty($bloc))
  1877.         {
  1878.             if(!$this->itemExists($item))
  1879.             {
  1880.                 $this->error(1$this->f[$this->f_no]['name']''$item);
  1881.                 return;
  1882.             }
  1883.         }
  1884.         else
  1885.         {
  1886.             if(!$this->itemExists($item$bloc))
  1887.             {
  1888.                 $this->error(1.1$this->f[$this->f_no]['name']$bloc$item);
  1889.                 return;
  1890.             }
  1891.         }
  1892.     }
  1893.  
  1894.     /**
  1895.      * this method verifies path
  1896.      *
  1897.      * @param string $path 
  1898.      * @return boolean 
  1899.      * @author H2LSOFT */
  1900.     public function pathVerify($path)
  1901.     {
  1902.         $tab @explode('.'$path);
  1903.         // reach the block and add the items to this block
  1904.         for($i 0$i count($tab)$i++)
  1905.         {
  1906.             if(!$this->blocExists($tab[$i]))
  1907.             {
  1908.                 $this->error(2$this->f[$this->f_no]['name']$tab[$i]);
  1909.                 return;
  1910.             }
  1911.         }
  1912.     }
  1913.  
  1914.     /**
  1915.      * method allows to know if a block exists in the template file.
  1916.      *
  1917.      * @param string $bloc_name 
  1918.      *
  1919.      * @return boolean 
  1920.      * @author H2LSOFT */
  1921.     public function blocExists($bloc_name)
  1922.     {
  1923.         if(@in_array($bloc_name$this->f[$this->f_no]['shortcut_blocs']['all']))
  1924.             return true;
  1925.         else
  1926.             return false;
  1927.     }
  1928.  
  1929.     /**
  1930.      * this method verifies if end block is not in double
  1931.      *
  1932.      * @return <type> 
  1933.      * @author H2LSOFT */
  1934.     protected function endBlocVerify()
  1935.     {
  1936.         foreach($this->f[$this->f_no]['shortcut_blocs']['all'as $bloc_name)
  1937.         {
  1938.             $motif "/<\\/bloc::$bloc_name>/U";
  1939.             if(!preg_match($motif$this->f[$this->f_no]['buffer']))
  1940.             {
  1941.                 $this->error(8$this->f[$this->f_no]['name']$bloc_name);
  1942.                 return;
  1943.             }
  1944.         }
  1945.     }
  1946.  
  1947.     /**
  1948.      * this method verifies if block is not in double
  1949.      *
  1950.      * @author H2LSOFT */
  1951.     protected function dualBlocVerify()
  1952.     {
  1953.         if(count($this->f[$this->f_no]['shortcut_blocs']['all']== 0)
  1954.             return;
  1955.  
  1956.         $blocs array();
  1957.         foreach($this->f[$this->f_no]['shortcut_blocs']['all'as $bloc)
  1958.         {
  1959.             if(!in_array($bloc$blocs))
  1960.                 $blocs[$bloc;
  1961.             elseif(!in_array($bloc$this->blocs_double_exceptions))
  1962.                 $this->error(2.1$this->f[$this->f_no]['name']$bloc);
  1963.         }
  1964.     }
  1965.  
  1966.     /**
  1967.      * This method allows to rise an exception for blocks defined twice or more times in the template.
  1968.      *
  1969.      * @param string $str 
  1970.      * @since 2.7
  1971.      * @author H2LSOFT */
  1972.     public function addBlocException($str)
  1973.     {
  1974.         if(is_array($str))
  1975.         {
  1976.             foreach($str as $bloc)
  1977.                 $this->addBlocException($bloc);
  1978.         }
  1979.         else
  1980.         {
  1981.             if(!in_array($str$this->blocs_double_exceptions))
  1982.                 $this->blocs_double_exceptions[$str;
  1983.         }
  1984.     }
  1985.  
  1986.     /**
  1987.      * this method replaces item
  1988.      *
  1989.      * @param string $name 
  1990.      * @param string $replace 
  1991.      * @param string $subject 
  1992.      *
  1993.      * @return boolean 
  1994.      * @author H2LSOFT */
  1995.     protected function replaceItem($name$replace$subject)
  1996.     {
  1997.         if(empty($name))
  1998.         {
  1999.             $this->error(6$this->f[$this->f_no]['name']);
  2000.             return;
  2001.         }
  2002.  
  2003.         $str preg_replace("/\{$name\}/U"$replace$subject);
  2004.         return $str;
  2005.     }
  2006.  
  2007.     /**
  2008.      * this method replaces block
  2009.      *
  2010.      * @param string $name 
  2011.      * @param string $replace 
  2012.      * @param string $subject 
  2013.      *
  2014.      * @return boolean 
  2015.      * @author H2LSOFT */
  2016.     protected function replaceBloc($name$replace$subject)
  2017.     {
  2018.         if(empty($name))
  2019.         {
  2020.             $this->error(5$this->f[$this->f_no]['name']);
  2021.             return;
  2022.         }
  2023.         // it's not an array
  2024.         if(!is_array($name&& !is_array($replace))
  2025.         {
  2026.             $motif "<bloc::$name>(.*)?<\\/bloc::$name>";
  2027.             $str @preg_replace("/$motif/msU"$replace$subject);
  2028.         }
  2029.         else
  2030.         {
  2031.             $str @preg_replace($name$replace$subject);
  2032.         }
  2033.         return $str;
  2034.     }
  2035.  
  2036.     /**
  2037.      * this method replaces include command
  2038.      *
  2039.      * @param string $file 
  2040.      * @author H2LSOFT */
  2041.     protected function parseIncludeCmd($file)
  2042.     {
  2043.         // parsing the file's name
  2044.         $file str_replace(chr(34)' '$file);
  2045.         $file str_replace(chr(39)' '$file);
  2046.         $file trim($file);
  2047.  
  2048.         $filebuffer $this->getFile($file);
  2049.  
  2050.         if($this->isPhpFile($file))
  2051.         {
  2052.             $filebuffer $this->evalHtml($filebuffer);
  2053.         }
  2054.  
  2055.         $file str_replace('/''\/'$file);
  2056.         $motif "/\{\#include\(\"$file\"\)\;\}|\{\#include\(\'$file\'\)\;\}/";
  2057.         $this->f[$this->f_no]['buffer'@preg_replace($motif$filebuffer$this->f[$this->f_no]['buffer']);
  2058.     }
  2059.  
  2060.     /**
  2061.      * this method replaces all PHP commands
  2062.      *
  2063.      * @author H2LSOFT */
  2064.     protected function parsePhpCommands()
  2065.     {
  2066.         // parse the if
  2067.         $motif "#{\#(.*|^include)}#";
  2068.         preg_match_all($motif$this->f[$this->f_no]['buffer']$matches);
  2069.  
  2070.         if(count($matches== && $matches[10)
  2071.         {
  2072.             // replace by the globals variables
  2073.             foreach($matches[1as $m)
  2074.             {
  2075.                 $m2 $m;
  2076.                 preg_match_all('#\$([[:alnum:]|\_]*)#'$m$ms);
  2077.  
  2078.                 if(count($ms== 2)
  2079.                 {
  2080.                     foreach($ms[0as $tm)
  2081.                     {
  2082.                         if(!in_array($tmarray('$_GET''$_POST''$_COOKIE''$_SERVER''$_SESSION''$_REQUEST')))
  2083.                             $m2 str_replace($tm'$GLOBALS["'.str_replace('$','',$tm).'"]'$m);
  2084.                     }
  2085.                 }
  2086.                 $this->f[$this->f_no]['buffer'str_replace("{#$m}""{#$m2}"$this->f[$this->f_no]['buffer']);
  2087.             }
  2088.  
  2089.             $this->f[$this->f_no]['buffer'str_replace("{#else}""{#else:}"$this->f[$this->f_no]['buffer']);
  2090.             $this->f[$this->f_no]['buffer'str_replace('{#endif}''{#endif;}'$this->f[$this->f_no]['buffer']);
  2091.             $this->f[$this->f_no]['buffer'preg_replace("#{\#(.*)\)}#""{#$1):}"$this->f[$this->f_no]['buffer']);
  2092.             $this->f[$this->f_no]['buffer'preg_replace($motif"<?php $1 ?>" ,$this->f[$this->f_no]['buffer']);
  2093.             $this->f[$this->f_no]['buffer'$this->evalHtml($this->f[$this->f_no]['buffer']);
  2094.         }
  2095.     }
  2096.  
  2097.     /**
  2098.      * this method replaces all include commands
  2099.      *
  2100.      * @return boolean 
  2101.      * @author H2LSOFT */
  2102.     protected function parseAllIncludeCmd()
  2103.     {
  2104.         if(count($this->f[$this->f_no]['cmd_items']== 0)
  2105.             return;
  2106.  
  2107.         foreach($this->f[$this->f_no]['cmd_items'as $filename)
  2108.             $this->parseIncludeCmd($filename);
  2109.     }
  2110.  
  2111.     /**
  2112.      * this method evals template file
  2113.      *
  2114.      * @param string $string 
  2115.      *
  2116.      * @return string 
  2117.      * @author H2LSOFT */
  2118.     protected function evalHtml($string)
  2119.     {
  2120.         // $string = implode('', $string);
  2121.         ob_start();
  2122.         eval('?>'.$string);
  2123.         $string ob_get_contents();
  2124.         ob_end_clean();
  2125.         return $string;
  2126.     }
  2127.  
  2128.     /**
  2129.      * this method returns if template is a PHP file
  2130.      *
  2131.      * @param string $filename 
  2132.      *
  2133.      * @return boolean 
  2134.      * @author H2LSOFT */
  2135.     protected function isPhpFile($filename)
  2136.     {
  2137.         $php_file_extension 'php|phtml|php4|php3'// extensions of the php file
  2138.  
  2139.         if(preg_match("/\.($php_file_extension)$/i"basename($filename)))
  2140.             return true;
  2141.  
  2142.         return false;
  2143.     }
  2144.  
  2145.     /**
  2146.      * this method returns if it is a block
  2147.      *
  2148.      * @param string $path 
  2149.      *
  2150.      * @return boolean 
  2151.      * @author H2LSOFT */
  2152.     protected function isBlocDesired($path)
  2153.     {
  2154.         if(preg_match("/[.]/"$path))
  2155.             return true;
  2156.         else
  2157.             return false;
  2158.     }
  2159.  
  2160.     /**
  2161.      * this method verifies if all the block are defined
  2162.      *
  2163.      * @param string $path 
  2164.      * @param string $type 
  2165.      *
  2166.      * @return boolean 
  2167.      * @author H2LSOFT */
  2168.     protected function isDefined($path$type '')
  2169.     {
  2170.         if(empty($type))
  2171.             $fathers_path $this->getFathers($path)// r�cup�re les p�res
  2172.  
  2173.         if($type == 'NOITEM')
  2174.             $fathers_path $path// recover the fathers
  2175.  
  2176.         if(@in_array($fathers_path$this->f[$this->f_no]['shortcut_blocs']['used']true))
  2177.             return true;
  2178.         else
  2179.             return false;
  2180.     }
  2181.  
  2182. // recover the text of the bloc
  2183. // recover the item of path
  2184.     /**
  2185.      * this method returns the last item
  2186.      *
  2187.      * @param string $path 
  2188.      *
  2189.      * @return string 
  2190.      * @author H2LSOFT */
  2191.     protected function getItem($path)
  2192.     {
  2193.         // if(!preg_match("/[.]/",$path)) {return;}
  2194.         $path_arr explode('.'$path);
  2195.         return $path_arr[count($path_arr)-1];
  2196.     }
  2197.  
  2198. // recover the father, the next to last block
  2199.     /**
  2200.      * this method returns the last father
  2201.      *
  2202.      * @param string $path 
  2203.      * @return string 
  2204.      * @author H2LSOFT */
  2205.     protected function getFather($path)
  2206.     {
  2207.         // if(!preg_match("/[.]/",$path)) {return;}
  2208.         $path_arr explode('.'$path);
  2209.         return $path_arr[count($path_arr)-2];
  2210.     }
  2211.  
  2212. // recover the fathers
  2213.     /**
  2214.      * this method returns all fathers in array
  2215.      *
  2216.      * @param string $path 
  2217.      * @param string $type 
  2218.      * @param int $with_item 
  2219.      *
  2220.      * @return string 
  2221.      * @author H2LSOFT */
  2222.     protected function getFathers($path$type ''$with_item 1)
  2223.     {
  2224.         // if(!preg_match("/[.]/",$path)) {return;}
  2225.         $path_arr explode('.'$path);
  2226.  
  2227.         if($with_item == 1)
  2228.             $fathers_arr array_slice($path_arr0count($path_arr)-1)// all the names except the last
  2229.         else
  2230.             $fathers_arr $path_arr;
  2231.  
  2232.         if($type == 'ARRAY')
  2233.             return $fathers_arr;
  2234.         else
  2235.         {
  2236.             $fathers_path join('.'$fathers_arr);
  2237.             return $fathers_path;
  2238.         }
  2239.     }
  2240.  
  2241.     /**
  2242.      * this method
  2243.      *
  2244.      * @param string $path 
  2245.      * @author H2LSOFT */
  2246.     protected function defineBloc($path)
  2247.     {
  2248.         $fathers_path $this->getFathers($path)// no item
  2249.         $fathers_arr $this->getFathers($path'ARRAY')// array
  2250.  
  2251.         foreach($fathers_arr as $bloc)
  2252.         {
  2253.             $cur_arr[$bloc;
  2254.  
  2255.             if(count($cur_arr== 1)
  2256.                 $cur_path $cur_arr[0];
  2257.             else
  2258.                 $cur_path join('.'$cur_arr);
  2259.  
  2260. // definition of all the fathers
  2261.             if(!$this->isDefined($cur_path'NOITEM'))
  2262.             {
  2263.                 $this->savePath($cur_path);
  2264.                 $a_bloc $this->initialiazeBloc($bloc);
  2265.                 // storage
  2266.                 $b_ref $this->f[$this->f_no]['def_blocs'];
  2267.  
  2268.                 $i 0;
  2269.                 foreach($cur_arr as $cur_bloc)
  2270.                 {
  2271.                     $b_ref $b_ref[$cur_bloc];
  2272.                     if($i (count($cur_arr)-1))
  2273.                         $b_ref $b_ref['children'];
  2274.                     $i++;
  2275.                 }
  2276.  
  2277.                 $b_ref $a_bloc;
  2278.             }
  2279.         }
  2280.     }
  2281.  
  2282.     /**
  2283.      * this method inisializes path in TPLN memory manager
  2284.      *
  2285.      * @param <type> $bloc 
  2286.      *
  2287.      * @return array 
  2288.      * @author H2LSOFT */
  2289.     protected function initialiazeBloc($bloc)
  2290.     {
  2291.         $cur['structure'$this->captureBloc($bloc$this->f[$this->f_no]['buffer'])// structure
  2292.         $cur['parsed'][$cur['structure']// parsed
  2293.         $cur['is_looped'0;
  2294.         $cur['children'array();
  2295.  
  2296.         return $cur;
  2297.     }
  2298.  
  2299.     /**
  2300.      * this method registers path in TPLN memory manager
  2301.      *
  2302.      * @param string $fathers_path 
  2303.      * @author H2LSOFT */
  2304.     protected function savePath($fathers_path)
  2305.     {
  2306.         $this->f[$this->f_no]['shortcut_blocs']['used'][$fathers_path// save in defined blocks
  2307.     }
  2308.  
  2309. // code from bitlux
  2310.     /**
  2311.      * This method allows to protect data against XSS attack,
  2312.      *
  2313.      * this method is used before insetring records in a database.
  2314.      *
  2315.      * @param string $string 
  2316.      * @return string 
  2317.      * @since 2.5, 2.2.5
  2318.      * @author H2LSOFT */
  2319.     public function xssProtect($string)
  2320.     {
  2321.         if(is_array($string))
  2322.         {
  2323.             foreach($string as $key => $val)
  2324.                 $string[$key$this->XSSProtect($val);
  2325.  
  2326.             return $string;
  2327.         }
  2328.  
  2329.         if (get_magic_quotes_gpc())$string stripslashes($string);
  2330.  
  2331.         $string str_replace(array("&amp;""&lt;""&gt;")array("&amp;amp;""&amp;lt;""&amp;gt;",)$string);
  2332.         // fix &entitiy\n;
  2333.         $string preg_replace('#(&\#*\w+)[\s\r\n]+;#U'"$1;"$string);
  2334.         $string @html_entity_decode($stringENT_COMPAT"UTF-8");
  2335.         // remove any attribute starting with "on" or xmlns
  2336.         $string preg_replace('#(<[^>]+[\s\r\n\"\'])(on|xmlns)[^>]*>#iU'"$1>"$string);
  2337.         // remove javascript: and vbscript: protocol
  2338.         $string preg_replace('#([a-z]*)[\s\r\n]*=[\s\n\r]*([\`\'\"]*)[\\s\n\r]*j[\s\n\r]*a[\s\n\r]*v[\s\n\r]*a[\s\n\r]*s[\s\n\r]*c[\s\n\r]*r[\s\n\r]*i[\s\n\r]*p[\s\n\r]*t[\s\n\r]*:#iU''$1=$2nojavascript...'$string);
  2339.         $string preg_replace('#([a-z]*)[\s\r\n]*=([\'\"]*)[\s\n\r]*v[\s\n\r]*b[\s\n\r]*s[\s\n\r]*c[\s\n\r]*r[\s\n\r]*i[\s\n\r]*p[\s\n\r]*t[\s\n\r]*:#iU''$1=$2novbscript...'$string);
  2340.         // <span style="width: expression(alert('Ping!'));"></span>
  2341.         // only works in ie...
  2342.         $string preg_replace('#(<[^>]+)style[\s\r\n]*=[\s\r\n]*([\`\'\"]*).*expression[\s\r\n]*\([^>]*>#iU'"$1>"$string);
  2343.         $string preg_replace('#(<[^>]+)style[\s\r\n]*=[\s\r\n]*([\`\'\"]*).*s[\s\n\r]*c[\s\n\r]*r[\s\n\r]*i[\s\n\r]*p[\s\n\r]*t[\s\n\r]*:*[^>]*>#iU'"$1>"$string);
  2344.         // remove namespaced elements (we do not need them...)
  2345.         $string preg_replace('#</*\w+:\w[^>]*>#i'""$string);
  2346.         // remove really unwanted tags
  2347.         do
  2348.         {
  2349.             $oldstring $string;
  2350.             $string preg_replace('#</*(style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i'""$string);
  2351.         }
  2352.         while ($oldstring != $string);
  2353.  
  2354.         return $string;
  2355.     }
  2356.  
  2357.     /**
  2358.      * this method replaces { _Version} by TPLN current version
  2359.      *
  2360.      * @author H2LSOFT */
  2361.     protected function parseVersion()
  2362.     {
  2363.         if($this->itemExists('_Version')) // place the logo
  2364.             $this->parse('_Version'TPLN_VERSION);
  2365.     }
  2366.  
  2367.     /**
  2368.      * this method replaces { _QueryCount} by the numbre of queries executed.
  2369.      *
  2370.      * @author H2LSOFT */
  2371.     protected function parseQueryCount()
  2372.     {
  2373.         if($this->itemExists('_QueryCount')) // place the logo
  2374.             $this->parse('_QueryCount'$this->query_count);
  2375.     }
  2376.  
  2377.     /**
  2378.      * this method replaces { _Logo} by TPLN Logo
  2379.      *
  2380.      * @author H2LSOFT */
  2381.     protected function parseLogo()
  2382.     {
  2383.         if($this->itemExists('_Logo')) // place the logo
  2384.  
  2385.         {
  2386.             $this->parse('_Logo''<a href="http://tpln.sourceforge.net" title="Powered by TPLN template !"><img src="http://tpln.sourceforge.net/logo.gif" alt="made with TPLN Template!" border="0" target="_blank"  /></a>');
  2387.         }
  2388.     }
  2389.  
  2390.     /**
  2391.      * this method allows to know template total time execution.
  2392.      *
  2393.      * The variable { _Chrono} must be imperatively replaced inside your template file.
  2394.      *
  2395.      * @param string $type 
  2396.      * @see write(), OutPut().
  2397.      * @author H2LSOFT */
  2398.     public function setChrono($type 'this')
  2399.     {
  2400.         $this->chrono_type[$this->f_no$type;
  2401.     }
  2402.  
  2403.     /**
  2404.      * this method replaces { _Chrono} by the time clock of the template
  2405.      *
  2406.      * @author H2LSOFT */
  2407.     protected function parseChrono()
  2408.     {
  2409.         if($this->itemExists('_Chrono')) // place the chrono
  2410.  
  2411.         {
  2412.             $this->getExecutionTime();
  2413.             $this->parse('_Chrono'$this->f[$this->f_no]['execution_time']);
  2414.         }
  2415.     }
  2416.  
  2417. // gestion du chrono
  2418.     /**
  2419.      * this method
  2420.      *
  2421.      * @author H2LSOFT */
  2422.     protected function getExecutionTime()
  2423.     {
  2424.         $time explode(' 'microtime());
  2425.         $fin $time[1$time[0];
  2426.         // we want the perf of this cette session or all
  2427.         if($this->chrono_type[$this->f_no== 'ALL')
  2428.             $this->f[$this->f_no]['execution_time'intval(10000 ((double)$fin - (double)TPLN_CHRONO_STARTED)) 10000;
  2429.         else
  2430.             $this->f[$this->f_no]['execution_time'intval(10000 ((double)$fin - (double)$this->f[$this->f_no]['chrono_started'])) 10000;
  2431.     }
  2432.  
  2433. // retourne la valeur de la premi�re ligne
  2434.     /**
  2435.      * this method verifies if template is expired
  2436.      *
  2437.      * @return boolean 
  2438.      * @author H2LSOFT */
  2439.     protected function inCachePeriod()
  2440.     {
  2441.         $expire $this->getTime(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['cache_name']);
  2442.  
  2443.         if($expire >= $this->f[$this->f_no]['time_started'])
  2444.         {
  2445.             return true;
  2446.         }
  2447.         else
  2448.         {
  2449.             @unlink(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['cache_name'])// remove the file
  2450.             return false;
  2451.         }
  2452.     }
  2453.  
  2454. // prend le temps au dessus du fichier
  2455.     /**
  2456.      * this method gets current time
  2457.      *
  2458.      * @return int 
  2459.      * @author H2LSOFT */
  2460.     protected function getTime()
  2461.     {
  2462.         $fp @fopen(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['cache_name']'r')// open the file
  2463.         $expire trim(@fgets($fp12));
  2464.         // $data = fread($fp, filesize($file));
  2465.         @fclose($fp);
  2466.  
  2467.         clearstatcache();
  2468.  
  2469.         return $expire;
  2470.     }
  2471.  
  2472.     /**
  2473.      * this method creates file cache
  2474.      *
  2475.      * @return boolean 
  2476.      * @author H2LSOFT */
  2477.     protected function createCache()
  2478.     {
  2479.         if(!$this->f[$this->f_no]['create_cached_file'])
  2480.         {
  2481.             return;
  2482.         }
  2483.         else
  2484.         {
  2485.             // add a function for creating folders
  2486.             $all_dir explode('/'$this->f[$this->f_no]['cache_name']);
  2487.             if(count($all_dir0)
  2488.             {
  2489.                 $count count($all_dir)-1// we want the last
  2490.                 $act_dir TPLN_CACHE_DIR;
  2491.                 for($i 0;$i $count;$i++)
  2492.                 {
  2493.                     $act_dir .= '/'.$all_dir[$i];
  2494.                     if(!is_dir($act_dir))
  2495.                     {
  2496.                         if(!@mkdir($act_dir0755))
  2497.                         {
  2498.                             $this->error(7);
  2499.                             return;
  2500.                         }
  2501.  
  2502.                         clearstatcache();
  2503.                     }
  2504.                 }
  2505.             }
  2506.  
  2507.             $cache_file_content $this->f[$this->f_no]['cache_expire']."\r".$this->f[$this->f_no]['buffer'];
  2508.             $fp @fopen(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['cache_name']'w')// open the file
  2509.             @fwrite($fp$cache_file_content);
  2510.             @fclose($fp);
  2511.             clearstatcache()// erase the data buffer
  2512.         }
  2513.     }
  2514.  
  2515.     /**
  2516.      * this method returns cached file
  2517.      *
  2518.      * @author H2LSOFT */
  2519.     protected function getCachedFile()
  2520.     {
  2521.         $this->f[$this->f_no]['create_cached_file'0;
  2522.  
  2523.         $fp @fopen(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['cache_name']'r');
  2524.         $tmp_expire @fgets($fp12)// for the pointer's position after the time
  2525.         $this->f[$this->f_no]['buffer'@fread($fpfilesize(TPLN_CACHE_DIR.'/'.$this->f[$this->f_no]['cache_name']));
  2526.         @fclose($fp);
  2527.         clearstatcache()// erase the data buffer
  2528.     }
  2529.  
  2530.     /**
  2531.      * this method verifies if cach directory exists
  2532.      *
  2533.      * @return boolean 
  2534.      * @author H2LSOFT */
  2535.     protected function cacheDirExists()
  2536.     {
  2537.         // the directory exists ?
  2538.         if(!is_dir(TPLN_CACHE_DIR))
  2539.         {
  2540.             if(!@mkdir(TPLN_CACHE_DIR0755))
  2541.             {
  2542.                 // $this->_AddTraceMsg();
  2543.                 $this->error(7);
  2544.                 return;
  2545.             }
  2546.             clearstatcache();
  2547.         }
  2548.     }
  2549.  
  2550.     /**
  2551.      * this method extracts string
  2552.      *
  2553.      * @param  string $str 
  2554.      * @param  string $start 
  2555.      * @param  string $end 
  2556.      * @param bool  $inc_markup 
  2557.      *
  2558.      * @return string 
  2559.      * @author H2LSOFT */
  2560.     public function extractStr($str$start$end$inc_markup 0)
  2561.     {
  2562.         $pos_start strpos($str$start);
  2563.  
  2564.         if($inc_markup)
  2565.             $pos_end strpos($str$end($pos_start));
  2566.         else
  2567.             $pos_end strpos($str$end($pos_start strlen($start)));
  2568.  
  2569.         if(($pos_start !== false&& ($pos_end !== false))
  2570.         {
  2571.             if($inc_markup)
  2572.             {
  2573.                 $pos1 $pos_start;
  2574.                 $pos2 ($pos_end strlen($end)) $pos1;
  2575.             }
  2576.             else
  2577.             {
  2578.                 $pos1 $pos_start strlen($start);
  2579.                 $pos2 $pos_end $pos1;
  2580.             }
  2581.  
  2582.             return substr($str$pos1$pos2);
  2583.         }
  2584.     }
  2585.  
  2586.     /**
  2587.      * PHP str replace with count parameter
  2588.      *
  2589.      * @param string $search 
  2590.      * @param string $replace 
  2591.      * @param string $subject 
  2592.      * @param int $times 
  2593.      *
  2594.      * @return string 
  2595.      * @author H2LSOFT */
  2596.     public function str_replace_count($search$replace$subject$times)
  2597.     {
  2598.         $subject_original $subject;
  2599.  
  2600.         $len strlen($search);
  2601.         $pos 0;
  2602.         for ($i 1;$i <= $times;$i++)
  2603.         {
  2604.             $pos strpos($subject$search$pos);
  2605.  
  2606.             if($pos === falsebreak;
  2607.  
  2608.             $subject substr($subject_original0$pos);
  2609.             $subject .= $replace;
  2610.             $subject .= substr($subject_original$pos $len);
  2611.             $subject_original $subject;
  2612.  
  2613.         }
  2614.  
  2615.         return($subject);
  2616.     }
  2617.  
  2618.     /**
  2619.      * This method allows to convert a php array to a javascript array, it is useful for Ajax.
  2620.      *
  2621.      * @param array $arr 
  2622.      *
  2623.      * @return string 
  2624.      * @author H2LSOFT */
  2625.     public function array2json($arr)
  2626.     {
  2627.         if(function_exists('json_encode')) return json_encode($arr)//Lastest versions of PHP already has this functionality.
  2628.         $parts array();
  2629.         $is_list false;
  2630.  
  2631.         //Find out if the given array is a numerical array
  2632.         $keys array_keys($arr);
  2633.         $max_length count($arr)-1;
  2634.         if(($keys[0== 0and ($keys[$max_length== $max_length))
  2635.         {
  2636.             //See if the first key is 0 and last key is length - 1
  2637.             $is_list true;
  2638.             for($i=0$i<count($keys)$i++)
  2639.             {
  2640.                 //See if each key correspondes to its position
  2641.                 if($i != $keys[$i])
  2642.                 {
  2643.                     //A key fails at position check.
  2644.                     $is_list false//It is an associative array.
  2645.                     break;
  2646.                 }
  2647.             }
  2648.         }
  2649.  
  2650.         foreach($arr as $key=>$value)
  2651.         {
  2652.             if(is_array($value))
  2653.             {
  2654.                 //Custom handling for arrays
  2655.                 if($is_list$parts[array2json($value)/* :RECURSION: */
  2656.                 else $parts['"' $key '":' array2json($value)/* :RECURSION: */
  2657.             }
  2658.             else
  2659.             {
  2660.                 $str '';
  2661.                 if(!$is_list$str '"' $key '":';
  2662.  
  2663.                 //Custom handling for multiple data types
  2664.                 if(is_numeric($value)) $str .= $value//Numbers
  2665.                 elseif($value === false$str .= 'false'//The booleans
  2666.                 elseif($value === true$str .= 'true';
  2667.                 else $str .= '"' addslashes($value'"'//All other things
  2668.                 // :TODO: Is there any more datatype we should be in the lookout for? (Object?)
  2669.  
  2670.                 $parts[$str;
  2671.             }
  2672.         }
  2673.  
  2674.         $json implode(',',$parts);
  2675.         if($is_listreturn '[' $json ']';//Return numerical JSON
  2676.         return '{' $json '}';//Return associative JSON
  2677.     }
  2678.  
  2679.     /**
  2680.      * This method allows to recover the contents of the text of the block,
  2681.      *
  2682.      * useful to recover the text after an exit of template
  2683.      *
  2684.      * @param string $bloc_name 
  2685.      * @param string $out 
  2686.      *
  2687.      * @return string 
  2688.      * @since 2.9
  2689.      * @author H2LSOFT */
  2690.     public function getAjaxBloc($bloc_name$out='')
  2691.     {
  2692.         if(empty($out))    $out $this->output();
  2693.  
  2694.         $pattern_s "<!-- ajax::$bloc_name -->";
  2695.         $pattern_e "<!-- /ajax::$bloc_name -->";
  2696.  
  2697.         $pos_start strpos($out$pattern_s);
  2698.         if($pos_start === false)return '';
  2699.         $pos_start += strlen($pattern_s);
  2700.  
  2701.         $pos_end strpos($out$pattern_e$pos_start);
  2702.         if($pos_end === false)return '';
  2703.  
  2704.         $bloc_content substr($out$pos_start$pos_end-$pos_start);
  2705.         return $bloc_content;
  2706.     }
  2707.  
  2708.     /**
  2709.      * This method allows to convert http, www, ftp, mailto into clickable element
  2710.      *
  2711.      * @param string $ret 
  2712.      * @return string 
  2713.      * @author H2LSOFT */
  2714.     public function clickable($ret)
  2715.     {
  2716.         /*$str = eregi_replace("([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)",
  2717.                                "<a href=\"mailto:\\1\">\\1</a>", $str);
  2718.     $str = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
  2719.                                     "<a href=\"\\1://\\2\\3\" target=\"_blank\">\\1://\\2\\3</a>", $str);
  2720.     * @author H2LSOFT */
  2721.  
  2722.         // matches an "xxxx://yyyy" URL at the start of a line, or after a space.
  2723.         // xxxx can only be alpha characters.
  2724.         // yyyy is anything up to the first space, newline, comma, double quote or <
  2725.         $ret preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is""\\1<a href=\"\\2\" target=\"_blank\">\\2</a>"$ret);
  2726.  
  2727.         // matches an email@domain type address at the start of a line, or after a space.
  2728.         // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
  2729.         $ret preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i""\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>"$ret);
  2730.  
  2731.         // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
  2732.         // Must contain at least 2 dots. xxxx contains either alphanum, or "-"
  2733.         // zzzz is optional.. will contain everything up to the first space, newline,
  2734.         // comma, double quote or <.
  2735.         //$ret = preg_replace("#(^|[\n ]|)((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
  2736.  
  2737.  
  2738.         // Remove our padding..
  2739.         // $ret = substr($ret, 1);
  2740.  
  2741.  
  2742.  
  2743.         return $ret;
  2744.     }
  2745. }
  2746.  
  2747.  
  2748. ?>

Documentation generated on Sat, 06 Mar 2010 21:34:08 +0100 by phpDocumentor 1.4.3