Home > Backend Development > PHP Tutorial > wecis 2.0 RC version

wecis 2.0 RC version

WBOY
Release: 2016-07-25 09:08:48
Original
926 people have browsed it

Please notify me when debugging bugs, thank you!
New version features:
1. Add {-script lang='php'-} template and you can also write PHP code
2. Modify 1.0 detailed errors: If there is no hard work code, optimize the core code to improve the running and compilation speed.
3. Add template formatting function {-$string|subistr(12):'...'-}, time formatting {-$time|time('ymd')-}

  1. /**
  2. * [Wecis] (C)2012-2099 Haowei Inc.
  3. * This is NOT a freeware, use is subject to license terms
  4. * version: 2.0 RC
  5. **/
  6. class wecis{
  7. private $assign=array();
  8. public $tpl_cache_dir = 'cache/';
  9. public $tpl_cache_open = TRUE;
  10. public $tpl_cache_time = 5 ;
  11. public $tpl_tpl_dir = 'template/';
  12. public $tpl_rw_left = '{-';
  13. public $tpl_rw_right = '-}';
  14. public function wecis(){
  15. return '[{name:'wecis 2.0 rc'}]';
  16. }
  17. public function assign($tplvar,$value){
  18. if(empty($tplvar) || empty($value)){
  19. $this->error('wecis-> assign() Parameters are missing');
  20. }
  21. return $this->assign[$tplvar]=$value;
  22. }
  23. public function display($tplfile){
  24. if(empty($tplfile)){ $this->error('wecis-> display() Parameters are missing'); }
  25. if($this->tpl_cache_open){
  26. if(file_exists($this->tpl_cache_dir.$this->cahce_format($tplfile))){
  27. if($this->cahce_timeout($tplfile)) {
  28. $this->cache_delete($tplfile);
  29. include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
  30. }else{
  31. include $this->tpl_cache_dir.$this->cahce_format($tplfile);
  32. }
  33. }else{
  34. include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
  35. }
  36. }else{
  37. include $this->cache($tplfile) ? $this->tpl_cache_dir.$this->cahce_format($tplfile) : '';
  38. }
  39. }
  40. public function cache($tplfile){
  41. $data = file_get_contents($this->tpl_tpl_dir.$tplfile);
  42. $data = preg_replace('/'.$this->tpl_rw_left.'script lang='php''.$this->tpl_rw_right.'/',' $data = preg_replace('/'.$this->tpl_rw_left.'/script'.$this->tpl_rw_right.'/','?>',$data);
  43. $data = preg_replace('/'.$this->tpl_rw_left.'loop ($(.*)?) as ($(.*)?)'.$this->tpl_rw_right.'/','',$data);
  44. $data = preg_replace('/'.$this->tpl_rw_left.'/loop'.$this->tpl_rw_right.'/','',$data);
  45. $data = preg_replace('/'.$this->tpl_rw_left.'($(.*)?)[((.*)?)]'.$this->tpl_rw_right.'/','',$data);
  46. $data = preg_replace('/'.$this->tpl_rw_left.'if((.*)?)'.$this->tpl_rw_right.'/','',$data);
  47. $data = preg_replace('/'.$this->tpl_rw_left.'else'.$this->tpl_rw_right.'/','',$data);
  48. $data = preg_replace('/'.$this->tpl_rw_left.'/if'.$this->tpl_rw_right.'/','',$data);
  49. $data = preg_replace('/'.$this->tpl_rw_left.'($(.*)?)|subistr(((.*)?)):((.*)?)'.$this->tpl_rw_right.'/','',$data);
  50. $data = preg_replace('/'.$this->tpl_rw_left.'($(.*)?)|time:(((.*)?))'.$this->tpl_rw_right.'/',"",$data);
  51. $data = preg_replace('/'.$this->tpl_rw_left.'($(.*)?)'.$this->tpl_rw_right.'/','',$data);
  52. $arr='';
  53. foreach($this->assign as $k=>$v) {
  54. if(!is_array($v)) {
  55. $data = !is_numeric($v) ? str_replace('$'.$k,'''.$v.''',$data) : str_replace('$'.$k,$v,$data);
  56. }else{
  57. $arr.='';
  58. }
  59. }
  60. return file_put_contents($this->tpl_cache_dir.$this->cahce_format($tplfile),$arr.$data) ? 1 : 0;
  61. }
  62. public function cahce_timeout($tplfile){
  63. $time = time();
  64. $filetime = fileatime($this->tpl_cache_dir.$this->cahce_format($tplfile));
  65. return $time-$filetime > ($this->tpl_cache_time*60) ? 1 : 0;
  66. }
  67. public function cahce_format($tplfile){
  68. return md5($this->version()).str_replace('/','.',$tplfile).'.php';
  69. }
  70. public function cache_delete($tplfile){
  71. return unlink($this->tpl_cache_dir.$this->cahce_format($tplfile)) ? 1 : 0;
  72. }
  73. private function error($str){
  74. return exit($str);
  75. }
  76. public function version(){
  77. return 'wecis 2.0 RC';
  78. }
  79. }
复制代码


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template