download this file: class.tmpl.php view text/plain: class.tmpl.php file encoding: UTF-8 [goback]
<?php
##
## this file name is 'class.tmpl.php'
##
## tmpl object
##
## [author]
## - Chilbong Kim<san2(at)linuxchannel.net>
##
## [changes]
## - 2005.03.10 : fixed extra
## - 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,$contents);
}
## for block file
##
function pregplace($from, $to, $contents)
{
return preg_replace($from,$to,$contents);
}
## alias of pregplace()
##
function preplace($form, $to, $contents)
{
return preg_replace($from,$to,$contents);
}
function parse($contents, $TMPL=array(), $_TMPL=array())
{
global $_SERVER, $TMPL, $_TMPL, $BLOCK, $_BLOCK;
//$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 || (defined('__DEBUG__')&&__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 tmpl::get_diofile($file);
if($fp = @fopen($file,'r'))
{
$contents = fread($fp,filesize($file));
fclose($fp);
}
else if($this->debug || (defined('__DEBUG__')&&__DEBUG__))
{ echo 'file('.$file.') not found in get_file()'."<BR>\n"; }
return $contents;
}
## alias of get_file()
##
function getfile($file)
{
return tmpl::get_file($file);
}
} // end of class
?>