php开发大型web应用,[转]PHP大型Web应用入门(二)

'.$this->default_db_handle.'->num_queries; ?>',$template);/*

if (!@$fp = fopen($objfile, 'w')) {

die ("Directory '" . $this->tpl_root . '/' . $this->tpl_cache_root . "' not found or have no access!");

}

flock ($fp, 3);

fwrite ($fp, $template);

fclose ($fp);

*/return$template;

}

functionparse($file)

{

global$page_time,$page_time_start;$tplfile=$this->tpl_dir.$file.'.'.$this->tpl_file_ext;$objfile=$this->tpl_cache_root_dir.'/'.$this->tpl_name.'_'.$file.'.tpl.'.$this->tpl_cache_file_ext;

if (!file_exists($tplfile)) {$tplfile=$this->tpl_root_dir.'/'.$this->default_tpl_name.'/'.$file.'.'.$this->tpl_file_ext;$objfile=$this->tpl_cache_root_dir.'/'.$this->default_tpl_name.'_'.$file.'.tpl.'.$this->tpl_cache_file_ext;

}

if ((@filemtime($tplfile) > @filemtime($objfile)) || (!@file_exists($objfile))) {//$this->parse_template ($tplfile, $objfile);if (!@$fp=fopen($objfile,'w')) {

die ("Directory '".$this->tpl_root.'/'.$this->tpl_cache_root."' not found or have no access!");

}flock($fp,3);fwrite($fp,$this->parse_template($tplfile,$objfile));fclose($fp);

}

list ($usec,$sec) =explode(" ",microtime());$page_time_end=$usec+$sec;$page_time=sprintf("%0.6f",$page_time_end-$page_time_start);

return$objfile;

}

functionset_tpl_db_handle($dh)

{$this->defalt_db_handle='$'.$dh;

}

functionset_tpl_name($name)

{$tpl_dir=$this->tpl_root_dir.'/'.$name.'/';

if ($name!=''&&is_dir($tpl_dir)) {$this->tpl_name=$name;$this->tpl_dir=str_replace('//','/',$tpl_dir);

}

else {$this->tpl_name=$this->default_tpl_name;$this->tpl_dir=str_replace('//','/',$this->tpl_root_dir.'/'.$this->tpl_name.'/');

}

}

functionset_language($langMeta)

{$langFile=$this->tpl_dir.$langMeta.'.lang';clearstatcache();

if (@is_readable($langFile)) {

return$langFile;

}

elseif (@is_readable($this->tpl_dir.$this->default_lang.'.'.$this->tpl_lang_file_ext)) {$langFile=$this->tpl_dir.$this->default_lang.'.'.$this->tpl_lang_file_ext;$langMeta=$this->default_lang;

return$langFile;

}

elseif (@is_readable($this->tpl_root_dir.'/'.$this->default_tpl_name.'/'.$langMeta.'.lang')) {$langFile=$this->tpl_root_dir.'/'.$this->default_tpl_name.'/'.$langMeta.'.lang';

return$langFile;

}

elseif (@is_readable($this->tpl_root_dir.'/'.$this->default_tpl_name.'/'.$this->default_lang.'.'.$this->tpl_lang_file_ext)) {$langFile=$this->tpl_root_dir.'/'.$this->default_tpl_name.'/'.$this->default_lang.'.'.$this->tpl_lang_file_ext;$langMeta=$this->default_lang;

return$langFile;

}

else

die ('Accept Langfile:'.$langFile.' did not exist or has no access!');

}

functiondsp()

{

global$mSession;

if ($mSession['do_gzip']) {$gzip_contents=ob_get_contents();ob_end_clean();$gzip_size=strlen($gzip_contents);$gzip_crc=crc32($gzip_contents);$gzip_contents=gzcompress($gzip_contents,9);$gzip_contents=substr($gzip_contents,0,strlen($gzip_contents) -4);

echo"x1fx8bx08x00x00x00x00x00";

echo$gzip_contents;

echopack('V',$gzip_crc);

echopack('V',$gzip_size);

}

elseob_end_flush();

}

functionget_static_html($file)

{// Just for Test...$static_file='../../data/static/'.$file.'.'.$this->tpl_static_file_ext;

if (@$fp=fopen($static_file,'wb')) {fwrite($fp,ob_get_contents());fclose($fp);

}ob_end_clean();

return;

}

}

functionaddquote($var)

{

returnstr_replace("\\"", """,preg_replace("/[([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)]/s","['\1']",$var));

}

functionstripvtags($expr,$statement)

{$expr=str_replace("\\"", """,preg_replace("/=(\$[a-zA-Z_x7f-xff][a-zA-Z0-9_[]\"'x7f-xff]*)?>/s","\1",$expr));$statement=str_replace("\\"", """,$statement);

return$expr.$statement;

}?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值