<?php
##
## this file name is 'class.tmpl.php'
##
## tmpl object
##
## [author]
##  - Chilbong Kim<san2(at)linuxchannel.net>
##
## [changes]
##  - 2003.06.09 : fixed parse() function
##  - 2003.03.08 : new build
##
## [references]
##
## [usage]
##
## [example]
##

class tmpl
{
  var 
$debug 0// boolean, debug mode

  
function tmpl($debug=0)
  {
    
define('__TMPLSTART__',microtime());
    
$this->debug $debug;
  }

  
## for block file
  ##
  
function replace($from$to$contents)
  {
    return 
str_replace($from,$to,$content);
  }

  
## for block file
  ##
  
function pregplace($from$to$contents)
  {
    return 
preg_replace($from,$to,$content);
  }

  function 
parse($contents$TMPL=array(), $_TMPL=array())
  {
    global 
$_SERVER$TMPL$_TMPL;

    
//$from = array("['",'["',"']",'"]','"');
    //$to = array('[','[',']',']','\"');

    
$from = array('["','"]','"'); // for javascript error
    
$to = array("['","']",'\"');

    
$contents str_replace($from,$to,$contents);

    @eval(
'$contents = "'.$contents.'";');

    return 
$contents;
  }

  function 
get_diofile($file)
  {
    if(
$fp = @dio_open($file,O_RDONLY)) {
        
$contents dio_read($fp,filesize($file));
        
dio_close($fp);
    }
    else if(
$this->debug)
    { echo 
'file('.$file.') not found in get_diofile()'."<BR>\n"; }

      return 
$contents;
  }

  
## common get file
  ##
  
function get_file($file)
  {
    if(
function_exists(dio_open)) return $this->get_diofile($file);

    if(
$fp = @fopen($file,'r')) {
        
$contents fread($fp,filesize($file));
        
fclose($fp);
    }
    else if(
$this->debug)
    { echo 
'file('.$file.') not found in get_file()'."<BR>\n"; }

    return 
$contents;
  }
// end of class

?>