uchome 模板引擎
模板不能动态包含
像这样<!--{template template/default/course/$space[school]}-->
因为执行解析模板时,先解析
$template = preg_replace("/\<\!\-\-\{template\s+([a-z0-9_\/]+)\}\-\-\>/ie", "readtemplate('\\1')", $template);
表达式中不允许存在$符号
function parse_template($tpl) {
global $_SGLOBAL, $_SC, $_SCONFIG;
//包含模板
$_SGLOBAL['sub_tpls'] = array($tpl);
$tplfile = S_ROOT.'./'.$tpl.'.htm';
$objfile = S_ROOT.'./data/tpl_cache/'.str_replace('/','_',$tpl).'.php';
//read
if(!file_exists($tplfile)) {
$tplfile = str_replace('/'.$_SCONFIG['template'].'/', '/default/', $tplfile);
}
$template = sreadfile($tplfile);
if(empty($template)) {
exit("Template file : $tplfile Not found or have no access!");
}
//模板
$template = preg_replace("/\<\!\-\-\{template\s+([a-z0-9_\/]+)\}\-\-\>/ie", "readtemplate('\\1')", $template);
//处理子页面中的代码
$template = preg_replace("/\<\!\-\-\{template\s+([a-z0-9_\/]+)\}\-\-\>/ie", "readtemplate('\\1')", $template);
//解析模块调用
$template = preg_replace("/\<\!\-\-\{block\/(.+?)\}\-\-\>/ie", "blocktags('\\1')", $template);
//解析广告
$template = preg_replace("/\<\!\-\-\{ad\/(.+?)\}\-\-\>/ie", "adtags('\\1')", $template);
//时间处理
$template = preg_replace("/\<\!\-\-\{date\((.+?)\)\}\-\-\>/ie", "datetags('\\1')", $template);
//头像处理
$template = preg_replace("/\<\!\-\-\{avatar\((.+?)\)\}\-\-\>/ie", "avatartags('\\1')", $template);
//PHP代码
$template = preg_replace("/\<\!\-\-\{\s+(.+?)\s*\}\-\-\>/ies", "tags('\\1')", $template);
//开始处理
//变量
$var_regexp = "((\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)(\[[a-zA-Z0-9_\-\.\"\'\[\]\$\x7f-\xff]+\])*)";
$template = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}", $template);
$template = preg_replace("/([\n\r]+)\t+/s", "http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.1/", $template);
$template = preg_replace("/(\\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\.([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/s", "http://www.cnblogs.com/qiantuwuliang/admin/file://1['//2']", $template);
$template = preg_replace("/\{(\\\$[a-zA-Z0-9_\[\]\'\"\$\.\x7f-\xff]+)\}/s", "<?=\\1?>", $template);
$template = preg_replace("/$var_regexp/es", "addquote('<?=\\1?>')", $template);
$template = preg_replace("/\<\?\=\<\?\=$var_regexp\?\>\?\>/es", "addquote('<?=\\1?>')", $template);
//逻辑
$template = preg_replace("/\{elseif\s+(.+?)\}/ies", "stripvtags('<?php } elseif(http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.1/) { ?>','')", $template);
$template = preg_replace("/\{else\}/is", "<?php } else { ?>", $template);
//循环
for($i = 0; $i < 6; $i++) {
$template = preg_replace("/\{loop\s+(\S+)\s+(\S+)\}(.+?)\{\/loop\}/ies", "stripvtags('<?php if(is_array(http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.1/)) { foreach(http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.1/ as http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.2/) { ?>','\\3<?php } } ?>')", $template);
$template = preg_replace("/\{loop\s+(\S+)\s+(\S+)\s+(\S+)\}(.+?)\{\/loop\}/ies", "stripvtags('<?php if(is_array(http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.1/)) { foreach(http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.1/ as http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.2/ => http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.3/) { ?>','\\4<?php } } ?>')", $template);
$template = preg_replace("/\{if\s+(.+?)\}(.+?)\{\/if\}/ies", "stripvtags('<?php if(http://www.cnblogs.com/qiantuwuliang/admin/file://0.0.0.1/) { ?>','\\2<?php } ?>')", $template);
}
//常量
$template = preg_replace("/\{([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}/s", "<?=\\1?>", $template);
//替换
if(!empty($_SGLOBAL['block_search'])) {
$template = str_replace($_SGLOBAL['block_search'], $_SGLOBAL['block_replace'], $template);
}
//换行
$template = preg_replace("/ \?\>[\n\r]*\<\? /s", " ", $template);
//附加处理
$template = "<?php if(!defined('IN_UCHOME')) exit('Access Denied');?><?php subtplcheck('".implode('|', $_SGLOBAL['sub_tpls'])."', '$_SGLOBAL[timestamp]', '$tpl');?>$template<?php ob_out();?>";
//write
if(!swritefile($objfile, $template)) {
exit("File: $objfile can not be write!");
}
}
function readtemplate($name) {
global $_SGLOBAL, $_SCONFIG;
$tpl = strexists($name,'/')?$name:"template/$_SCONFIG[template]/$name";
$tplfile = S_ROOT.'./'.$tpl.'.htm';
$_SGLOBAL['sub_tpls'][] = $tpl;
if(!file_exists($tplfile)) {
$tplfile = str_replace('/'.$_SCONFIG['template'].'/', '/default/', $tplfile);
}
$content = sreadfile($tplfile);
return $content;
}
转载于:https://www.cnblogs.com/qiantuwuliang/archive/2010/02/23/1672095.html
uchome 模板引擎相关推荐
- SpringBoot (三) :SpringBoot使用Freemarker模板引擎渲染web视图
什么是Freemarker FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源代码等)的通用工具. 它不是面向最终用户的,而 ...
- SpringBoot-web开发(三): 模板引擎Thymeleaf
[SpringBoot-web系列]前文: SpringBoot-web开发(一): 静态资源的导入(源码分析) SpringBoot-web开发(二): 页面和图标定制(源码分析) 目录 1. 引入 ...
- php codeigniter 语言,php – codeigniter模板引擎,包括语言解析器
不幸的是,CI内置的模板解析器类没有此功能.你可以在 sparks directory中环顾四周,有多个火花集成了许多模板引擎,如smarty或twig,可以通过调整来创建这样的东西. 此外,您可以尝 ...
- php smarty模板引擎 性能,smarty性能低?直接使用php模板引擎吧
skymvc框架使用的php模板引擎 1.[代码][PHP]代码 class smarty{ public $template_dir = '';//模版文件夹 public $cache_dir = ...
- java freemarker 模版_Java模板引擎-FreeMarker
简介: FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写.FreeMarker我们的第一印象是用来替代JSP的,但是与JSP不同的是FreeMarker模板可 ...
- 模板引擎:VelocityFreeMarker(转)
Velocity,名称字面翻译为:速度.速率.迅速,用在Web开发里,用过的人可能不多,大都基本知道和在使用Struts,到底Velocity和Struts(Taglib和Tiles)是如何联系?在技 ...
- 【JavsScript】推荐五款流行的JavaScript模板引擎
摘要:Javascript模板引擎作为数据与界面分离工作中最重要一环,受到开发者广泛关注.本文通过开发实例解析五款流行模板引擎:Mustache.Underscore Templates.Embedd ...
- php 简单模板引擎,PHP 实现简单的模板引擎
模板引擎作为视图层和模型曾分离的一种解决方案. 首先我们新建一个Template.class.php 的文件 '.m', //设置模板文件'templateDir' => 'template/' ...
- php模板引擎如何实现,php模板引擎技术简单实现
用了smarty,tp过后,也想了解了解其模板技术是怎么实现,于是写一个简单的模板类,大致就是读取模板文件->替换模板文件的内容->保存或者静态化 tpl.class.php主要解析 as ...
最新文章
- mysql中主从复制需要的酶_mysql主从复制
- -Wl,-rpath=
- Spring RestTemplate中几种常见的请求方式
- VS Code 报错Vetur can‘t find ‘tsconfig.json‘ or ‘jsconfig.json‘的解决方法
- unity着色器和屏幕特效开发秘笈_Oculus研发分享:开发移动VR内容时应避免的PC渲染技术...
- C#中using关键字的作用及其用法(转)
- 关于spring框架
- 无标度网络 matlab,无标度网络及MATLAB建模
- 三进制计算机在线计算,计算器在线
- IBM Websphere MQ 基础3:Listener监听器
- 利用C语言实现大数加减法
- 二手苹果手机哪个性价比高?
- 点击input文本框,文字消失 JS
- 电子信息工程就业方向、就业要求及薪资标准
- 41-构造函数/析构函数
- 释放让iBooks占用的冗余空间
- kernel停在Starting kernel 分析
- php curl请求 和 打印日志
- meituan-YOLOV6-训练自己的数据集-新鲜出炉的YOLOV6
- Strange Characters On Budgetary Control Result Page [ID 1439888.1]
热门文章
- android中获取图片、获取图片像素、处理像素等基础知识
- mysql explain用法
- Codeforces Round #323 (Div. 2) C. GCD Table
- struts2 action之间参数的传递
- css清除浮动的处理方法
- Oracle11gR2 64bit+Oracle11gR2Client32bit+pl/sql 9
- 企业网站推广方案详解
- 人生致命的8个经典问题[转]
- php自动处理,thinkphp中的三种自动处理
- 新浪php面试题目,新浪php的面试题 收集