1 / 16

UCHome 模板解析

UCHome 模板解析. Zuoyuan 2012/3/23. 问题提出. 为什么要了解模板? 模板解析的过程是什么样的? 模板的基本语法 怎样修改模板?. <!--// 说明 : 显示公共头部模板 --> <!--{template common/header}--> <!--// 说明 : 开始显示留言 --> <div id="ct" class=" wp cl ">

Download Presentation

UCHome 模板解析

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UCHome模板解析 Zuoyuan 2012/3/23

  2. 问题提出 • 为什么要了解模板? • 模板解析的过程是什么样的? • 模板的基本语法 • 怎样修改模板?

  3. <!--//说明: 显示公共头部模板--> • <!--{template common/header}--> • <!--//说明: 开始显示留言--> • <div id="ct" class="wpcl"> • <h1 class="mt">心情墙 - <!--{if $_G[uid]}--><a href="mood.php?mod=publish">发表心情</a><!--{/if}--></h1> • <div class="bm"> • <!--{if $list}--> • <!--//说明: loop 循环一个数组 相当于foreach(){}--> • <!--{loop $list $mood}--> • <a href="home.php?mod=space&uid=$mood[uid]" target="_blank"><!--{avatar($value[authorid],small)}--></a><br> • <a href="home.php?mod=space&uid=$mood[uid]" title="$mood[username]" target="_blank" class="xi2">$mood[username]</a> 发表于: $mood[dateline] • <br> • 心情: $mood[message] • <hr> • <!--{/loop}--> • <!--//说明: 显示准备好的分页链接--> • $multi • <!--{else}--> • <p class="emp">暂时没有记录...</p> • <!--{/if}--> • </div> • </div> • <!--//说明: 显示公共尾部模板--> • <!--{template common/footer}-->

  4. 模板 • Uchome和很多php框架都使用了模板 • 模板使得框架和数据分开 • 模板引擎 • Smarty • Template Lite • Uchome自定义的 模板

  5. 模板解析过程 • 涉及的文件:php引擎文件,htm或其他格式(如tpl)的模板文件,php缓存文件 • 编译过程:php引擎打开模板,进行替换,生成php缓存文件

  6. 技术细节 • 独立的标记 <!--{if $_G[uid]}--> • 查找替换——正则表达式

  7. 正则表达式 • 功能:字符串查找匹配 • 类似的技术:通配符 windows下的* ? • 一个例子 在模板中查找<!--{template 各种可用字符}--> 正则表达式是 \<\<\!\-\-\{template\s+ ([a-z0-9_\/]+)\}\-\-\>

  8. 正则表达式基本语法 / 定界符^ 字符串头$ 字符串尾[a-z]所有小写字母[A-Z]所有大写字母[0-9] 所有数字? 零或一个紧接前的字符* 零或多个紧接前的字符+ 一或多个紧接前的字符{4}4个紧接前的字符{4,8}4-8个紧接前的字符. 任意字符(red|green|blue) Red 或 green 或 blue(红 或 绿 或 蓝)s空格( ) [ ] . * ? + ^ | $

  9. 正则表达式语法举例 • 匹配数字和字母 [0-9|a-z]+ • 匹配http开头的url ^http \<http • 分组(下面这个是干嘛的?) (\d{1,3}\.){3}\d{1,3}

  10. 在哪里可以使用正则表达式 • Findstr • World • Open office • Excel • 编程语言php,js,java等

  11. 正则表达式参考 • http://deerchao.net/tutorials/regex/regex.htm • 正则表达式入门经典Andrew watt(TP301.2/6)

  12. UChome模板的语法 <!--{template common/header}--> 用common/header.htm替换这里 <!--{template common/footer}--> 用common/footer.htm替换

  13. UChome模板的语法 • 流程控制 {if}{else if}{/if} {loop}{/loop} • 变量 $value {$_SN[‘title’]}

  14. 源代码 //模板 $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("/\<\!\-\-\{eval\s+(.+?)\s*\}\-\-\>/ies", "evaltags('\\1')", $template);

  15. 本周任务 • 在服务器上搭好框架,进行修改,添加插件,配置模板等(按脚本行事) • 查看源代码、网上查找资料,将uchome修改成我们修要的界面 • 本周php培训

  16. 事务管理 • 增加一次会议(周三或周日晚上22:00) • 确定一起工作的时间,4小时,本时间内,禁止人人,QQ,游戏等与任务无关的事,时间待定

More Related