|  | 
 
 楼主|
发表于 2005 年 4 月 26 日 19:33:48
|
显示全部楼层 
闲着没事,分析了下代码...//| 今天分析phpwind的分类怎样在前台显示出来: 大家把phpwind的数据库查看一下,我是用
 phpmyadmin把phpwind数据库中的表pw_forums导出
 看看结构
 --
 -- 表的结构 `pw_forums`
 --
 
 CREATE TABLE `pw_forums` (
 `fid` smallint(6) unsigned NOT NULL auto_increment,
 `fup` smallint(6) unsigned NOT NULL default '0',
 `ifsub` tinyint(1) NOT NULL default '0',
 `childid` tinyint(1) NOT NULL default '0',
 `type` enum('category','forum','sub') NOT NULL default 'forum',
 `logo` char(100) NOT NULL default '',
 `name` char(100) NOT NULL default '',
 `descrip` char(255) NOT NULL default '',
 `vieworder` tinyint(3) NOT NULL default '0',
 `forumadmin` char(255) NOT NULL default '',
 `style` char(12) NOT NULL default '',
 `tpost` mediumint(8) unsigned NOT NULL default '0',
 `topic` mediumint(8) unsigned NOT NULL default '0',
 `article` mediumint(8) unsigned NOT NULL default '0',
 `subtopic` smallint(6) unsigned NOT NULL default '0',
 `lastpost` char(135) NOT NULL default '',
 `allowhtm` tinyint(1) NOT NULL default '0',
 `allowhide` tinyint(1) NOT NULL default '1',
 `allowsell` tinyint(1) NOT NULL default '1',
 `allowencode` tinyint(1) NOT NULL default '1',
 `password` char(32) NOT NULL default '',
 `viewsub` tinyint(1) NOT NULL default '0',
 `allowvisit` char(120) NOT NULL default '',
 `allowpost` char(120) NOT NULL default '',
 `allowrp` char(120) NOT NULL default '',
 `allowdownload` char(120) NOT NULL default '',
 `allowupload` char(120) NOT NULL default '',
 `f_type` char(10) NOT NULL default 'forum',
 `t_type` char(255) NOT NULL default '',
 `f_score` char(50) NOT NULL default '',
 `f_check` tinyint(1) unsigned NOT NULL default '0',
 PRIMARY KEY (`fid`),
 KEY `fup` (`fup`),
 KEY `type` (`ifsub`,`vieworder`,`fup`)
 ) TYPE=MyISAM AUTO_INCREMENT=17 ;
 其中涉及到几个主要文件(包括模板文件)如下:
 根目录下的"index.php","./template/wind/index.htm"
 打开index.php文件看看里面的代码,看上去没头没尾的,
 还是先从"./template/wind/index.htm"开始,不过也是一样看不出
 什么门道,很多都是采用(print <<<EOT "html的内容" EOT;)
 这种方式输出的php语句中大多采用if语句,里面有很多变量$xx,
 
 现在要考虑的就是 ,phpwind论坛采用什么方式把模板文件读出来的。
 个人猜测在index.php中采用包含模板文件,因为index.htm里面也包含
 php语句,在index.php中采用require_once("./template/wind/index.htm"),
 然后在index.php中写变量的判断关系,这样很符合逻辑了,
 
 依照这样的思路,我又回到了index.php文件里,找require_once("./template/wind/index.htm")
 来证实我的猜想,在index.php里面没有找到调用index.htm文件,不过在最后一行找到
 了require_once(PrintEot('index');这就好办了,原来phpwind采用PrintEot函数调用,
 这也是函数的好处。
 
 我 又产生疑问PrintEot在哪个文件里定义的。就在index.php里面找了,找index.php是否调用其他文件了
 ,require_once('./global.php'),呵呵~~,global文件定义了很多函数,应该在里面了。
 打开global.php文件查找function PrintEot,找到了,如下定义:
 function PrintEot($template,$EXT="htm"){
 global $tplpath;
 if(!$template) $template=N;
 
 file_exists("./template/$tplpath/$template.$EXT") ? $path="./template/$tplpath/$template.$EXT" : $path="./template/wind/$template.$EXT";
 
 return $path;
 }
 现在就分析一下PrintEot函数,require_once(PrintEot('index'))
 其中index是传递的参数,$template接受,现在就是$template=index了
 global $tplpath;是申明$tplpath为全局变量,再其他地方可以赋值如:
 $tplpath=wind,看看if()判断语句,如果$template不存在的话,就赋值为N
 N是什么啊?我去测试一下,
 自己写了如下调式语句;
 <?php
 $template='wind';
 if(!$template) $template=N;
 echo $template;
 ?>
 结果还是输出N,我还以为N是变量为false呢,
 到(./tempalte/wind/)目录下找找,找N.htm,现在就符合逻辑了。
 就是说我们传递的参数如index如果不存在的话,就调用./tempalte/wind/N.htm
 N.htm这个文件里什么都没有,这样写有什么好处呢?
 测试一下
 <?php
 function PrintEot($template,$EXT="htm") {
 if(!$template) $template=N;
 $path="./template/$template.$EXT";
 return $path;
 }
 require_once(PrintEot('index');
 ?>
 新建./template/index.htm和./template/N.htm两个文件。
 在index.htm里面输入内容
 <?php
 echo "测试一下这种模板调用思路";
 ?>
 N.htm文件为空。
 还是不行啊,我把require_once(PrintEot('0'));
 才调用N.htm,还是没体会到这里有什么好处,
 暂且放过了。
 继续分析PrintEot函数
 file_exists() ? :
 象这种形式就是判断了。如果“./template/$tplpath/$template.$EXT”
 这个路径下的文件存在的话,就执行后面的$path="./template/$tplpath/$template.$EXT"
 语句,如果不存在的话,就执行第二个语句$path="./template/wind/$template.$EXT";
 phpwind使用$tplpath可能是为了以后方面加载模板方便的。
 这样每个模板的路径就可以在后台改变$tplpath的值就可以,换模板了。
 以上总结一下吧,算是phpwind模板调用的一个流程。
 下次继续,先分析一下模板中的变量是怎么判断,怎么传递的。
 感觉分析过程加上大胆的猜测,大胆的调式,还是有收获的。
 | 
 |