Posts Tagged ‘支持’

WEB页面多语言支持解决方案

星期二, 06月 3rd, 2008

首先建立语言档,在项目中加入.resx文件
例如:
message.zh-cn.resx ‘简体中文
message.zh-tw.resx ‘繁体中文
message.en ‘英文
…………..
=========================================
然后利用Name –Value 键值对 填入您要在页面上显示de语言
如:
name value
message.zh-cn.resx中:
res_loginbname 登陆名 :
message.zh-tw.resx中:
res_loginbname 登陸名 :
message.zh-cn.resx中:
res_loginbname Login Name :

=========================================
然后在Golbal.asax中加入多语言设定支持相关代码(浏览器需要支持Cookie)

‘=========================================
‘ Application_BeginRequest Event

‘ The Application_BeginRequest method is an ASP.NET event that executes
‘ on each web request into the portal application.

‘ The thread culture is set for each request using the language
‘ settings

‘=========================================
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Try
If Not Request.Cookies(”resource”) Is Nothing Or Request.Cookies(”resource”).Value = “” Then
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.Cookies(”resource”).Value)
Else
Thread.CurrentThread.CurrentCulture = New CultureInfo(ConfigurationSettings.AppSettings(”DefaultCulture”))
End If
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
Catch ex As Exception
Thread.CurrentThread.CurrentCulture = New CultureInfo(ConfigurationSettings.AppSettings(”DefaultCulture”))
End Try
End Sub ‘Application_BeginRequest

在Web.Config中加入如下相关代码,用于设定编码和默认语种,在Global.asax中有调用:

=========================================
<globalization requestEncoding=”utf-8″ responseEncoding=”utf-8″ />
<appSettings>
<add key=”DefaultCulture” value=”zh-cn” />
<!– zh-cn:簡體中文 zh-tw:繁體中文 en:英文 –>
</appSettings>

=========================================
页面相关代码中使用多语言支持:

Imports System.Resources

Public Class 类名
Inherits System.Web.UI.Page
Protected LocRM As ResourceManager = New ResourceManager(”项目文件名.message”, GetType(类名).Assembly)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblLogin.Text = LocRM.GetString(”res_login”)
End Sub
End Class


=========================================

到这里多语言支持de工作就作完了,接下来自己去慢慢Key
message.zh-cn.resx ‘简体中文
message.zh-tw.resx ‘繁体中文
message.en ‘英文

这几个语言档吧

让你的IIS服务器支持JSP

星期一, 06月 2nd, 2008

一.软件简介
本文主要讲述如何用IIS Tomcat3.1支持JSP及servlet环境.正常情况下IIS不支持servlet及JSP环境.我通过使用一个IIS到Tomcat重定向de插件(plugin)使用IIS能够将所有deservlet及JSP请求发送到Tomcat执行以实现servlet及JSP环境.
二.文档定义
"tomcat_home"–假定为您安装tomcatde目录.
三.软件环境
Microsoft Windows NT 4.0 SP6a
IIS 4.0
Tomcat 3.1
四.获得所需软件
Microsoft Windows NT Server 4.0,请您自行准备.
Microsoft Windows NT Option Pack(安装IIS),请您自行准备.
IIS serverdeTomcat插件
Tomcat 3.1
五.安装
(1)请参考前面de文章,安装Tomcat 3.1 for win.
(2)确认第一步安装成功后,安装配置IISdeTomcat插件
注册表中,增加一个新de键值:
"HKEY_LOCAL_MACINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0"
增加一个名为"extension_uri"de字符串,值为"/jakarta/isapi_redirect.dll"
增加一个名为"log_filei"de字符串,值为"日志文件de文件全名l"(例如c:\tomcat\IISisapi.log)
增加一个名为"log_level"de字符串,值为"您想记录deerror级别"(可以是以下值中de一个:debug,inform,error,emerg)
增加一个名为"worker_file"de字符串,值为"tomcat_home\conf\workers.properties"(将这里detomcat_home替换成您安装tomcatde路径全名,例如c:\tomcat)
增加一个名为"worker_mount_file"de字符串,值为"tomcat_home\conf\uriworkermap.properties"(将这里detomcat_home替换成您安装tomcatde路径全名,例如c:\tomcat)
进入IIS管理控制台,选中"WEB站点"->按右键->选中属性->isapi筛选器中将"isapi_redirect.dll"加入到筛选器列表中.
重新启动IIS,确认在isapi筛选器中我新加de筛选器有一个向上de绿色箭头.

(1)加上jspdeweb引用目录(Context)
在Tomcat里加上一个web引用目录,具体步骤请看本区文章
加入一个web引用目录到IIS ISAPI 重定向插件
打开"tomcat_home\conf\worker.properties"文件,加入如下配置行:
/"web引用目录"/*=ajp12(例如/jsp/*=ajp12).

php 之 没有mysql支持时的替代方案

星期一, 06月 2nd, 2008

一般个人免费主页空间都不会提供mysql支持,就是提供也很苛刻,所以寻找也个良好de替代方案很重要哦!
PHPde文件处理功能很强大,所以可以用文件de存取来代替来!
(要知道没有数据库de时候,什么都是用文件组织de哦!呵呵!),其中个数据项用特殊符号分割,我采用de是“||”,方便通过explode()函数读取单个记录!
其实这里数据库de思想还是可以用到de!象数据库de索引!
所以必须先做个索引文件!(这样说也并不正确)
就以留言本来说吧:
主要文件是:
index.database
其结构如下:
留言人姓名||留言人性别||留言时间||留言内容存放位置||feiyn(这项是方便读取时de被‘n’干恼de!
每条存储一行可以方便de通过PHPdefgets()函数读取,或者file()函数读取每行到数组
为了防止多人同是对数据de写入冲突,故还需要加锁(也用文件实现)
以下是写入相关代码
<?php
//必须传入以下参量:
//留言人姓名 $name
//留言人性别 $sex
//留言时间 $time
//留言内容存放位置 $savePosite
$indexFile="index.database";
$indexFileLock=$indexFile."Lock";
$message=$name."||".$sex."||".$time."||".$savePosite."||feiy||";//这就是要写入de记录
while(file_exists($indexFileLock)) $temp ; //检测是否已加锁
fclose(fopen($indexFileLock,"w")); //如没有则进入并加锁避免同是访问冲突
$fp=fopen($indexFile,"a");
fputs($message,strlen($message));
fclose($fp);
unlink($indexFileLock);//解锁
?>
读取相关代码
<?php
$indexFile="index.database";
$indexFileLock=$indexFile."Lock";
while(file_exists($indexFileLock)) $temp ; //检测是否已加锁
fclose(fopen($indexFileLock,"w")); //如没有则进入并加锁避免同是访问冲突
$ary=file($indexFile);
unlink($indexfileLock);//解锁
for($i=0;$i<sizeof($ary);$i ){
$tempAry=explode("||",$ary[$i]);
echo("name:".$tempAry[0]);
echo("sex:".$tempAry[1]);
echo("sex:".$tempAry[2]);
echo("savePosite:",$tempAry[3]);//可以从该地址读取留言内容
}
?>
通过以上可以方便de解决常用de网页运用,比如聊天室,BBS论坛,书签之类
如果那位大虾有更好de解决方法,请赐教!谢谢!
我de主页:feiyschool.51.net
QQ:23072155
email:feiyhy@sina.com
【本文版权归作者feiy与奥索网共同拥有,如需转载,请注明作者及出处】

一个没有MYSQL数据库支持的简易留言本的编写

星期一, 06月 2nd, 2008

由于国内MySQL资源比较紧张,国外de不是太慢,就是不对我国用户开放.因此,在没有MYSQLde日子里,我想做一些方便他人和完善自己站点de事情,那简直比登天还难,为了摆脱这种痛苦,niky哭思冥想,闭门造车,终于,皇天不负有心人,一个不需要MYSQL数据库支持de简易留言本就这样出台了,我暂且叫它gbook.php吧,源程序如下:
<?
if ($message)
{
$message = ereg_replace( "rnrn", "n<P>", $message);
//去除无效de控制符号
$date = date( "l, F j Y, h:i a"); //获取指定de日期时间格式
$ip=getenv("REMOTE_ADDR");
$message = "<table border="0" cellspacing="0" width="640" cellpadding="0">
<tr>
<td width="25%"><B>$name </B></td>
<td width="25%">$email</td>
<td width="25%">写于–$date</td>
<td width="25%">来自>>$ip</td>
</tr>
<tr>
<td width="100%" colspan="4">$subject</td>
</tr>
<tr>
<td width="100%" colspan="4">$massage</td>
</tr>
</table><hr>
";
$fp = fopen (basename($PHP_SELF) . ".comment", "a");
fwrite ($fp, $message);
fclose ($fp);
}
@readfile(basename(($PHP_SELF . ".comment")));
//读出记录文件内容
?>
<form method="POST" >
<p>姓名:<input type="text" name="name" size="20"> E-mail:<input type="text" name="email" size="24"><hr>
主题:<input type="text" name="subject" size="55">
<p>
您想说de话:<br><TEXTAREA name="message" rows=10 cols=60 wrap=virtual>
</TEXTAREA><BR><br>
<INPUT name="submit" type="submit" value="发表!"> <input type="reset" value="重写?" name="B2">
</p>
</form>
──────────────────────────────────────
上面de程序,其原理是:在PHP端首先判断message变量是否存在,如果不存在,则读文件.读文件使用了readfile函数.至于文件名de提取,这里使用了一个巧妙de方式(使用$PHP_SELF变量提取文件所在de绝对位置,然后用basename()函数提取文件名,再加上指定de文件尾comment.)来完成de.为了能更好de学习PHP&MySQL,特拿来和大家共享,也希望曾经和niky一样痛苦过de网路人能有一个属于自己de留言本,而不是"xxx留言本由xxx.com提供."而大煞风景.还等什么,赶快行动吧!
版权所有,请勿随便转载!
Copyright ©2000 niky All rights reserved.
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】

让你的PHP同时支持GIF、png、JPEG

星期一, 06月 2nd, 2008

让您dePHP同时支持GIF、png、JPEG
在RedHat6.2按phpdemanual编译安装,发现只能处理GIF图像,不能处理JPEG图像.后来知道PHP处理图像,使用了GD库,而GD库开始时是支持GIFde,但由于GIF使用了有版权争议deLZW算法,会引起法律问题,于是从GD-1.6开始,GD库不再支持GIF,改为支持更好de,无版权争议dePNG.而我现在希望同时支持GIF,PNG和JPEG.
1、 Jpeg6bde安装
RedHat6.2中已经有了RPM包,我也就不需要去费劲编译了.
放入安装盘
mount /mnt/cdrom
cd /mnt/cdrom/RedHat/RPMS
rpm -ivh libjpeg*
安装成功,用rpm -ql libjpeg-6b-10 查看,发现libjpeg.so.62.0.0被拷到/usr/lib目录下.记住此目录,等会儿配php时要用.
2、 GD-1.8.3de安装
获取GD源码de地址为:
http://www.boutell.com/gd/
您当然可以自己编译,但它不支持jpeg,要打补丁.
获取补丁源码de地址为:
http://www.webofsin.com/gd-1.8.3-gif.patch
接下来………………麻烦死了……劝您还是不要自己编译了!!
有现成de东西为何不用呢?已经有人打好补丁编译好了,做成RPM.
可以在:
http://rpms.arvin.dk/rh7-backports/gd/
http://rpms.arvin.dk/gd-with_gif/
得到.世上竟然有这么好de人?;-<
真令人感动!!!
下载了几个gd-with_gif*.rpm后直接 rpm -ivh gd-with_gif* 安装.
用 rpm -ql gd-with_gif-1.8.3-7 查看
发现 libgd.so.1.8.3 放到了 /usr/gd-with_gif/lib 下
记住此目录,配php时也要用.
3、 PHPde安装和配置
鉴于曾听说php4.0不支持jpeg(不知记错没),我建议还是用phpde最新版.
下面de,大家应该熟悉得不能再熟悉了吧?
于是我把phpdemanual抄下来:
———————————
1. gunzip apache_1.3.x.tar.gz
2. tar xvf apache_1.3.x.tar
3. gunzip php-x.x.x.tar.gz
4. tar xvf php-x.x.x.tar
5. cd apache_1.3.x
6. ./configure –prefix=/www
7. cd ../php-x.x.x
8. 这里是关键!!!
./configure –with-mysql –with-apache=../apache_1.3.x –enable-track-vars –with-jpeg-dir=/usr/lib –with-gd=/usr/gd-with_gif/lib
当然您也可以加上您自己de选项,此不赘述.
9. make
10. make install
11. cd ../apache_1.3.x
12. for PHP 4: ./configure –activate-module=src/modules/php4/libphp4.a
13. make
14. make install
Instead of this step you may prefer to simply copy the httpd binary
overtop of your existing binary. Make sure you shut down your
server first though.
15. cd ../php-x.x.x
16. for PHP 4: cp php.ini-dist /usr/local/lib/php.ini
You can edit your .ini file to set PHP options. If
you prefer this file in another location, use
–with-config-file-path=/path in step 8.
17. Edit your httpd.conf or srm.conf file and add:
For PHP 4: AddType application/x-httpd-php .php
You can choose any extension you wish here. .php is simply the one
we suggest. You can even include .html .

18. Use your normal procedure for starting the Apache server. (You must
stop and restart the server, not just cause the server to reload by
use a HUP or USR1 signal.)
—————————————
终于成功了,您可以启动apache用phpinfo()试一试,发现gd那里:
———————-
gd
GD Support enabled
GD Version 1.6.2 or higher
GIF Support enabled
PNG Support enabled
JPG Support enabled
WBMP Support enabled
———————-
^_^哈哈哈哈哈哈哈哈哈^_^
您现在可以用到所有dephp图形函数了:
ImageCreateFromGIF() — Create a new image from file or URL
ImageCreateFromJPEG() — Create a new image from file or URL
ImageCreateFromPNG() — Create a new image from file or URL
……
绝对没问题!!!!

支持oicq头像的留言簿(一)

星期一, 06月 2nd, 2008

特点:
支持oicq头像,自动分页,显示留言人ip,email合法性验证,方便安全de留言管理,
没有复杂函数,初学者也很容易看懂.
程序示例:http://medguider.51.net/notebook/
完整程序下载(包括图片)http://medguider.51.net/download/notebook.zip
程序清单:
config.php 配置文件 mysql.txt 数据库文件 index.php 显示留言主程序 addnote.php 添加留言 delnote.php 删除留言
mysql.txt
create table notebook (name char(6),email varchar(35),time char(30),face char(2),ip varchar(16),title varchar(255),nnote text);
//留言簿 name 姓名 email time 时间 face 头像 ip title 标题 nnote 内容
config.php
<?php
//这里改为自己de数据库用户名与密码
$db = mysql_connect("localhost", "root");
mysql_select_db("test",$db);
//这里改为自己de管理用户名和密码
$username="demo";
$password="demo";
?>
index.php
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>留言簿</TITLE>
<style type="text/css">
<!–
.blue9 { font-size: 9pt; color: #0099FF; text-decoration: none}
.black9 { font-size: 9pt; text-decoration: none}
.purple10 { font-size: 10pt; color: #9900FF; text-decoration: none}
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
a:visited { color: #FFFFFF}
a:link { color: #FFFFFF}
–>
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?php
include ("config.php");
$result = mysql_query("SELECT * FROM notebook ",$db);
$row=mysql_num_rows($result);//查看查询结果有多少行
$max=$row; //帖子总数
//设每页显示10篇,可自行设定,$p总页数,$page第几页,$low 从第几行开始读,$x 读取几行
if (!$page){ $page=1;}//$page默认值为1
$p=ceil($max/10);//页数为$max/10de最大整数
$low=10*($page-1);
if($page==$p&&($max)<>0){$x=($max);} else {$x=10;}//如果是最后一页,且不是10de整倍数,读取$max除以10de余数,否则取10
if($max==0){$x=0;}//如果没有帖子,$x取0
$result = mysql_query("select * from notebook ORDER BY time DESC limit $low,$x",$db);//按照帖子de时间降序查询
?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="61">
<tr>
<td height="62" width="34%"><a href="http://www.medguider.com"><img src="image/logo.gif" width="243" height="60" alt="医学导航网" border="0"></a></td>
<td height="62" width="66%">
<div align="center"><img src="image/note.gif" width="410" height="60"><img src="image/y1.gif" width="60" height="60"></div>
</td>
</tr>
</table>
<table width="95%" border="1" cellspacing="0" cellpadding="0" height="253" bordercolordark="#FFFFFF" bordercolorlight="#003399" align="center">
<tr>
<td height="250">
<div align="center"></div>
<table width="95%" border="0" cellspacing="0" cellpadding="0" height="32" bgcolor="#3366FF">
<tr>
<td width="26%" class="white12" height="23"><a href="../index.php" class="white12">首页</a>
> 留言簿</td>
<td width="48%" class="white12" height="23">
<?php
echo "帖子总数: ",$max," 第";
for ($n=1;$n<=$p;$n ){
echo "<a href=index.php?page=$n>$n</a> ";
}
echo "页";
?>
</td>
<td width="15%" height="23"><a href="addnote.php"><img src="image/newthread.gif" width="91" height="21" border="0"></a></td>
<td width="11%" height="23"><a href="delnote.php"><span class="white12">留言管理</span></a></td>
</tr>
</table>
<?php
for ($i=0;$i<=($x-1);$i ) {
$name=mysql_result($result,$i,’name’);
$email=mysql_result($result,$i,’email’);
$face=mysql_result($result,$i,’face’);
$face=’image/face/icon’.$face; //用户头像
$time=mysql_result($result,$i,’time’);
$ip=mysql_result($result,$i,’ip’);
$title=mysql_result($result,$i,’title’);
$nnote=mysql_result($result,$i,’nnote’);
echo "<table width=’100%’ border=’0′ cellspacing=’0′ cellpadding=’0′ height=107′ bordercolor=’#FFFFFF’> <tr bgcolor=’#eeeeee’>";
echo "<td width=’10%’ height=’33′ bgcolor=’#eeeeee’ class=’blue9′> <img src=’$face.gif’ width=’32′ height=’32′></td>";
echo "<td width=’16%’ height=’33′ bgcolor=’#eeeeee’ class=’blue9′>留言人:$name</td>";
echo "<td width=’41%’ height=’33′ bgcolor=’#eeeeee’ class=’blue9′>发表于:$time</td>";
echo "<td width=’12%’ height=’33′ bgcolor=’#eeeeee’ class=’blue9′><a href=’mailto:$email’><img src=’image/email.gif’ width=’16′ height=’16′ border=0></a></td>";
echo "<td width=’21%’ height=’33′ class=’blue9′><img src=’image/ip.gif’ width=’13′ height=’15′> $ip</td> </tr> <tr>";
echo "<td colspan=’5′ class=’purple10′ height=’33′>标题:$title</td> </tr>";
echo "<tr bgcolor=’#ffffff’><td colspan=’5′ class=’black9′ height=’37′>留言内容:$nnote</td></tr></table>";
}
mysql_close($db);
?>
</td>
</tr>
</table>
</BODY>
</HTML>

支持oicq头像的留言簿(二)

星期一, 06月 2nd, 2008

addnote.php
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>添加留言</TITLE>
<style type="text/css">
<!–
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
–>
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="61">
<tr>
<td height="62" width="34%"><a href="http://www.medguider.com"><img src="image/logo.gif" width="243" height="60" alt="医学导航网" border="0"></a></td>
<td height="62" width="66%">
<div align="center"><img src="image/note.gif" width="410" height="60"><img src="image/y1.gif" width="60" height="60"></div>
</td>
</tr>
</table>
<?php
include ("config.php");
if ($submit){
$time=date("Y年m月d日 H:i:s A");
$ip=$REMOTE_ADDR;//留言人ip地址
$name=trim($name);
$email=trim($email);
$title=strip_tags($top);
$nnote=nl2br(strip_tags($content));//先去掉html标记,再将换行符转成 <br>.
if (!$name||!$email||!$title||!$nnote){ //检查是否填写完整
echo "对不起,您必须填所有内容!<BR>"."<a href=’javascript:history.back()’>返回</a>";
exit; }elseif(!ereg(’^[-!#$%&'* ./0-9=?A-Z^_`a-z{|}~] ‘.’@’.’[-!#$%&'* \/0-9=?A-Z^_`a-z{|}~] .’.’[-!#$%&'* \./0-9=?A-Z^_`a-z{|}~] $’,$email) //email合法性验证
){
echo "email不合法!<BR>"."<a href=’javascript:history.back()’>返回</a>";
exit;
}
//写入数据库
$sql="INSERT INTO notebook (name,email,time,face,ip,title,nnote) VALUES (’$name’,'$email’,'$time’,'$face’,'$ip’,'$title’,'$nnote’)";
$result = mysql_query($sql,$db);
mysql_close($db);
echo "留言成功!";
}
?>
<table width="99%" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#3366FF">
<tr bgcolor="#3366FF">
<td width="81%" class="white12" height="26"><a href="../index.php" class="white12">首页</a>
> <a href="index.php" class="white12">留言簿</a>
> 添加留言</td>
<td width="19%" class="white12" height="26"><a href=’index.php’ class="white12">查看留言</a>
</td>
</tr>
<tr>
<td colspan="2">
<form name="form1" method="post" action="addnote.php">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="54%"> </td>
<td rowspan="2" width="46%">选择一个自己喜欢de头像:<br>
<img src="image/face/icon1.gif" width="32" height="32">
<input type="radio" name="face" value="1" checked>
<img src="image/face/icon2.gif" width="32" height="32">
<input type="radio" name="face" value="2">
<img src="image/face/icon3.gif" width="32" height="32">
<input type="radio" name="face" value="3">
<img src="image/face/icon4.gif" width="32" height="32">
<input type="radio" name="face" value="4">
<img src="image/face/icon5.gif" width="32" height="32">
<input type="radio" name="face" value="5">
<img src="image/face/icon6.gif" width="32" height="32">
<input type="radio" name="face" value="6">
<img src="image/face/icon7.gif" width="32" height="32">
<input type="radio" name="face" value="7">
<img src="image/face/icon8.gif" width="32" height="32">
<input type="radio" name="face" value="8">
<img src="image/face/icon9.gif" width="32" height="32">
<input type="radio" name="face" value="9">
<img src="image/face/icon10.gif" width="32" height="32">
<input type="radio" name="face" value="10">
<img src="image/face/icon11.gif" width="32" height="32">
<input type="radio" name="face" value="11">
<img src="image/face/icon12.gif" width="32" height="32">
<input type="radio" name="face" value="12">
<img src="image/face/icon13.gif" width="32" height="32">
<input type="radio" name="face" value="13">
<img src="image/face/icon14.gif" width="32" height="32">
<input type="radio" name="face" value="14">
<img src="image/face/icon15.gif" width="32" height="32">
<input type="radio" name="face" value="15">
<img src="image/face/icon16.gif" width="32" height="32">
<input type="radio" name="face" value="16">
<img src="image/face/icon17.gif" width="32" height="32">
<input type="radio" name="face" value="17">
<img src="image/face/icon18.gif" width="32" height="32">
<input type="radio" name="face" value="18">
<img src="image/face/icon19.gif" width="32" height="32">
<input type="radio" name="face" value="19">
<img src="image/face/icon20.gif" width="32" height="32">
<input type="radio" name="face" value="20">
<img src="image/face/icon21.gif" width="32" height="32">
<input type="radio" name="face" value="21">
<img src="image/face/icon22.gif" width="32" height="32">
<input type="radio" name="face" value="22">
<img src="image/face/icon23.gif" width="32" height="32">
<input type="radio" name="face" value="23">
<img src="image/face/icon24.gif" width="32" height="32">
<input type="radio" name="face" value="24">
<img src="image/face/icon25.gif" width="32" height="32">
<input type="radio" name="face" value="25">
<img src="image/face/icon26.gif" width="32" height="32">
<input type="radio" name="face" value="26">
<img src="image/face/icon27.gif" width="32" height="32">
<input type="radio" name="face" value="27">
<img src="image/face/icon28.gif" width="32" height="32">
<input type="radio" name="face" value="28">
<img src="image/face/icon29.gif" width="32" height="32">
<input type="radio" name="face" value="29">
<img src="image/face/icon30.gif" width="32" height="32">
<input type="radio" name="face" value="30">
<img src="image/face/icon31.gif" width="32" height="32">
<input type="radio" name="face" value="31">
<img src="image/face/icon32.gif" width="32" height="32">
<input type="radio" name="face" value="32">
<img src="image/face/icon33.gif" width="32" height="32">
<input type="radio" name="face" value="33">
<img src="image/face/icon34.gif" width="32" height="32">
<input type="radio" name="face" value="34">
<img src="image/face/icon35.gif" width="32" height="32">
<input type="radio" name="face" value="35">
<img src="image/face/icon36.gif" width="32" height="32">
<input type="radio" name="face" value="36">
<img src="image/face/icon37.gif" width="32" height="32">
<input type="radio" name="face" value="37">
<img src="image/face/icon38.gif" width="32" height="32">
<input type="radio" name="face" value="38">
<img src="image/face/icon39.gif" width="32" height="32">
<input type="radio" name="face" value="39">
<img src="image/face/icon40.gif" width="32" height="32">
<input type="radio" name="face" value="40">
<img src="image/face/icon41.gif" width="32" height="32">
<input type="radio" name="face" value="41">
<img src="image/face/icon42.gif" width="32" height="32">
<input type="radio" name="face" value="42">
<img src="image/face/icon43.gif" width="32" height="32">
<input type="radio" name="face" value="43">
<img src="image/face/icon44.gif" width="32" height="32">
<input type="radio" name="face" value="44">
<img src="image/face/icon45.gif" width="32" height="32">
<input type="radio" name="face" value="45">
<img src="image/face/icon46.gif" width="32" height="32">
<input type="radio" name="face" value="46">
<img src="image/face/icon47.gif" width="32" height="32">
<input type="radio" name="face" value="47">
<img src="image/face/icon48.gif" width="32" height="32">
<input type="radio" name="face" value="48">
<img src="image/face/icon49.gif" width="32" height="32">
<input type="radio" name="face" value="49">
<img src="image/face/icon50.gif" width="32" height="32">
<input type="radio" name="face" value="50">
<img src="image/face/icon51.gif" width="32" height="32">
<input type="radio" name="face" value="51">
<img src="image/face/icon52.gif" width="32" height="32">
<input type="radio" name="face" value="52">
<img src="image/face/icon53.gif" width="32" height="32">
<input type="radio" name="face" value="53">
<img src="image/face/icon54.gif" width="32" height="32">
<input type="radio" name="face" value="54">
<img src="image/face/icon55.gif" width="32" height="32">
<input type="radio" name="face" value="55">
<img src="image/face/icon56.gif" width="32" height="32">
<input type="radio" name="face" value="56">
<img src="image/face/icon57.gif" width="32" height="32">
<input type="radio" name="face" value="57">
<img src="image/face/icon58.gif" width="32" height="32">
<input type="radio" name="face" value="58">
<img src="image/face/icon59.gif" width="32" height="32">
<input type="radio" name="face" value="59">
<img src="image/face/icon60.gif" width="32" height="32">
<input type="radio" name="face" value="60">
<img src="image/face/icon61.gif" width="32" height="32">
<input type="radio" name="face" value="61">
<img src="image/face/icon62.gif" width="32" height="32">
<input type="radio" name="face" value="62">
<img src="image/face/icon63.gif" width="32" height="32">
<input type="radio" name="face" value="63">
<img src="image/face/icon64.gif" width="32" height="32">
<input type="radio" name="face" value="64">
</td>
</tr>
<tr>
<td width="54%">名字
<input type="text" name="name">
<br>
Email
<input type="text" name="email">
<br>
标题
<input type="text" name="top" size="50">
<br>
内容<br>
<textarea name="content" cols="50" rows="20"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="submit" value="确定">
<input type="reset" name="cancel" value="重写">
</div>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<p><a href="main.php?user=<? echo $user?>" class="white12"><br>
</a></p>
</BODY>
</HTML>
delnote.php
<?php
include ("config.php");
if ($superadmin){ //如果已经进行管理员登陆,进行密码验证
if (!($user==$username)||!($psw==$password)){
echo "密码错误";
exit;
}
}else{ //管理员登陆
echo "<form name=’form1′ method=’post’ action=’$PHP_SELF’>";
echo "<div align=’center’> 请输入管理员密码<br>";
echo "管理员";
echo "<input type=’text’ name=’user’><br>";
echo "密码";
echo "<input type=’password’ name=’psw’><br>";
echo "<input type=’submit’ name=’superadmin’ value=’进入’><br>";
echo "<input type=’reset’ name=’cancel’ value=’重写’></div>";
echo "</form>";
exit;
}
if($del==1){ //判断是否要删除
mysql_query("delete from notebook where time=’$time’",$db); //以留言时间为删除标志
echo "删除成功!";
}
?>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>删除留言</TITLE>
<style type="text/css">
<!–
.blue9 { font-size: 9pt; color: #0099FF; text-decoration: none}
.black9 { font-size: 9pt; text-decoration: none}
.purple10 { font-size: 10pt; color: #9900FF; text-decoration: none}
.white12 { font-size: 12pt; color: #FFFFFF; text-decoration: none}
a:visited { color: #FFFFFF}
a:link { color: #FFFFFF}
–>
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<?php
$result = mysql_query("SELECT * FROM notebook ",$db);
$row=mysql_num_rows($result);//查看结果有多少行
$max=$row; //帖子总数
//设每页显示10篇,$p总页数,$page第几页,$low 从第几行开始读,$x 读取几行
if (!$page){$page=1;}
$p=ceil($max/10);
$low=10*($page-1);
if($page==$p&&($max)<>0){$x=($max);} else {$x=10;}//如果是最后一页,且不是10de整倍数,读取$max除以10de余数,否则取10
if($max==0){$x=0;}//如果没有帖子,$x取0
$result = mysql_query("select * from notebook ORDER BY time DESC limit $low,$x",$db);
?>
<table width="98%" border="0" cellspacing="0" cellpadding="0" height="61">
<tr>
<td height="62" width="34%"><a href="http://www.medguider.com"><img src="image/logo.gif" width="243" height="60" alt="医学导航网" border="0"></a></td>
<td height="62" width="66%">
<div align="center"><img src="image/note.gif" width="410" height="60"><img src="image/y1.gif" width="60" height="60"></div>
</td>
</tr>
</table>
<table width="95%" border="1" cellspacing="0" cellpadding="0" height="253" bordercolordark="#FFFFFF" bordercolorlight="#003399" align="center">
<tr>
<td height="250">
<table width="95%" border="0" cellspacing="0" cellpadding="0" height="32" bgcolor="#3366FF">
<tr>
<td width="28%" class="white12">首页
> <a href="index.php" class="white12">留言簿</a></td>
<td width="56%" class="white12">
<?php
echo "帖子总数: ",$max," 第";
for ($n=1;$n<=$p;$n ){
echo "<a href=index.php?page=$n>$n</a> ";
}
echo "页";
?>
</td>
<td width="16%"><a href="index.php" class="white12">查看留言</a></td>
</tr>
</table>
<?php
for ($i=0;$i<=($x-1);$i ) {
$email=mysql_result($result,$i,’email’);
$face=mysql_result($result,$i,’face’);
$face=’image/face/icon’.$face;
$name=mysql_result($result,$i,’name’);
$time=mysql_result($result,$i,’time’);
$ip=mysql_result($result,$i,’ip’);
$title=mysql_result($result,$i,’title’);
$nnote=mysql_result($result,$i,’nnote’);
echo "<table width=’100%’ border=’0′ cellspacing=’0′ cellpadding=’0′ height=107′ bordercolor=’#FFFFFF’> <tr bgcolor=’#eeeeee’>";
echo "<td width=’10%’ height=’33′ bgcolor=’#eeeeee’ class=’blue9′> <img src=’$face.gif’ width=’32′ height=’32′></td>";
echo "<td width=’16%’ height=’33′ bgcolor=’#eeeeee’ class=’blue9′>留言人:$name</td>";
echo "<td width=’41%’ height=’33′ bgcolor=’#eeeeee’ class=’blue9′>发表于:$time</td>";
echo "<td width=’12%’ height=’33′ bgcolor=’#eeeeee’ class=’blue9′><a href=’mailto:$email’><img src=’image/email.gif’ width=’16′ height=’16′ border=0></a></td>";
echo "<td width=’21%’ height=’33′ class=’blue9′><img src=’image/ip.gif’ width=’13′ height=’15′> $ip <a href=’$PHP_SELF?del=1&time=$time&superadmin=$superadmin&user=$user&psw=$psw’><img src=’image/del.gif’ width=’16′ height=’16′ border=0></a></td> </tr> <tr>";
echo "<td colspan=’5′ class=’purple10′ height=’33′>标题:$title</td> </tr>";
echo "<tr bgcolor=’#ffffff’><td colspan=’5′ class=’black9′ height=’37′>留言内容:$nnote</td></tr></table>";
}
mysql_close($db);
?>
</td>
</tr>
</table>
</BODY>
</HTML>

PHP4之COOKIE支持详解

星期一, 06月 2nd, 2008

PHP4之COOKIE支持详解
建立商业站点或者功能比较完善de个人站点,常常需要记录访问者de信息,在PHP中提供了两种方便de手段:session和cookie功能.为了永久de保持用户信息,则cookie是最便捷de手段.在这里我将为大家详细de讲解cookiede功能及使用方法.
一: 设置cookie
使用cookie前必须设置cookie.
函数原型:int setcookie(string name,string value,int expire,string path,string domain,int secure)
其中,除name外,所有de参数都是可选de,可以用空de字符串表示未设置.
属性value: 用来指定值.
属性path: 用来指定cookie被发送到服务器de哪一个目录路径下.
属性domain:能够在浏览器端对cookiede发送进行限定.
expire参数:用来指定cookiede有效时间,它是一个标准deUnix时间标记.
可以用time()或者mktime()函数取得,以秒为单位.
secure参数:表示这个cookie是否通过加密deHTTPS协议在网络上传输.
二: 设置cookie时de注意事项
在同一个页面中设置cookie,实际上是按从后往前de顺序进行de.如果要先删除一个cookie,再写入一个cookie,则必须先写写入语句,再写删除语句.否则会出现错误.
三: setcookie举例
简单de: setcookie("mycookie","value_of_mycookie");
带失效时间de: setcookie("withExpire","Expire_in_1_hour",time() 3600);
什么都有de:setcookie("FullCookie","Full_cookie_value",time 3600,"/forum","www.123.com",1);
四: cookiede一些特点
cookie是面向路径de.缺省path属性时,WEB服务器页会自动传递当前路径给浏览器.指定路径会强制服务器使用设置de路径.
在一个目录页面里设decookie在另一个目录de页面里是看不到de.
五: 接收和处理cookie
PHP对cookiede处理是全自动de,和处理FORM变量de原则一样.当然也可以使用PHP全局变量,$HTTP_COOKIE_VARS数组.
例: echo $mycookie;
echo $cookie Array[0];
echo count($cookie Array);
echo $HTTP_COOKIE_VARS["mycookie"];
六: 删除cookie
(1)调用只带有name参数desetcookie();
(2)使失效时间为time()或time-1;
七: 使用cookiede限制
(1) 必须在HTML文件de内容输出之前设置;
(2)不同de浏览器对cookiede处理不一致,使用时一定要考虑;
(3)客户端de限制,比如用户设置禁止cookie,则cookie不能建立;
八: 一个具体de例子,希望大家对cookie有更加深刻de认识
<?
//cookie.php
if(!isset($flag))
{
setcookie("mycookie","this my cookie!");
header("location:cookie.php?flag=1");
exit;
}
?>
<html>
<body>
<?
echo "cookie中有:".$mycookie;
?>
</body>
</html>
怎么样,通过上面de介绍,您是不是对PHP中deCOOKIE功能有了详细de了解.发挥您de聪明才智,让您de站点功能更强大吧.如有问题请与 fbigov@sina.com联系.让我一同进步.

配置PHP使之能同时支持GIF和JPEG

星期一, 06月 2nd, 2008

问题:安装蓝点Linux 2.0后,进行PHP编程,发现只能处理GIF图像,不能处理JPEG图像.后来知道PHP处理图像,使用了GD库,而GD库开始时是支持GIFde,但由于GIF使用了有版权争议deLZW算法,会引起法律问题,于是从GD-1.6开始,GD库不再支持GIF,改为支持更好de,无版权争议dePNG.而我现在希望同时支持GIF,PNG和JPEG.经过尝试,我成功地做到了这一点.下面介绍具体做法.我de配置为:蓝点Linux 2.0,Kernel-2.2.16,MySQL-3.23.10alpha,Apache-1.3.12,PHP4.0.1pl2,gd-1.8.3,Jpeg6b.

我将按照由底向上de顺序介绍,即Jpeg->GD->PHP->Apache.
0、 当前状态查看
安装蓝点Linux 2.0后,Kernel,MySQL,Apache未做任何改变,看看当前状态如何.
创建一PHP文件,名为info.php,放于Apahcede文档目录下(/etc/httpd/html),其内容如下:
<? phpinfo(); ?>
文件就只有1行.用浏览器打开该文件URL(我dehostname为zhangzh):
http://zhangzh/info.php
如果Apache/PHP正常运行de话,页面中将会列出PHP版本,Apache版本,以及其他各种有用de信息.我关心de是GD库部分,看看它是否支持GIF、JPEG,结果发现支持GIF而不支持JPEG.
1、 Jpeg6bde安装和配置
Jpegde主要文件有jpeglib.h, libjpeg.a, libjpeg.so等.首先检查系统中安装了没有,到/usr/include目录下看有无jpeglib.h,到/usr/lib目录下看有无libjpeg.a和libjpeg.so.我de系统中没有,因而要安装.
获取Jpeg源码de地址为:
ftp://ftp.uu.net/graphics/jpeg/
取得de文件为jpegsrc.v6b.tar.gz,放于/usr/src目录下.
进入/usr/src目录中,开始安装过程.
进入/usr/src:
cd /usr/src
解开压缩文件:
tar xzvf jpegsrc.v6b.tar.gz
命令完成后多了一个子目录jpeg-6b,Jpegde源码文件就在其中.
进入该子目录:
cd jpeg-6b
该目录中deinstall.doc文件详细介绍了如何安装Jpeg,照章行事即可.
配置生成Makefile文件:
./configure
命令完成后该目录下多了个Makefile文件.Makefile文件是许多软件编译、安装de配置和过程控制文件,十分重要,应该学会看懂它de内容.
开始编译:
make
命令完成后该目录下多了许多文件,其中重要de是libjpeg.a和libjpeg.so.
安装:
make install
命令完成后,jpeglib.h被拷到/usr/local/include目录下,libjpeg.a和libjpeg.so被拷到/usr/local/lib目录下.
2、 GD-1.8.3de安装和配置
GDde主要文件有gd.h, libgd.a等.
获取GD源码de地址为:
http://www.boutell.com/gd/
取得de文件为gd-1.8.3.tar.gz,放于/usr/src目录下.
已知道该版本deGD不支持GIF,但想来象我一样希望GD同时支持GIF和JPEGde人不少,于是有人做了个补丁,把对GIFde支持加回去了.看起来这是个英国人吧,他deEmail地址为adam@elysium.ltd.uk.
获取补丁源码de地址为:
http://www.webofsin.com/gd-1.8.3-gif.patch
取得de文件为gd-1.8.3-gif.patch,放于/usr/src目录下.
进入/usr/src:
cd /usr/src
解开压缩文件:
tar xzvf gd-1.8.3.tar.gz
命令完成后多了一个子目录gd-1.8.3,GDde源码文件就在其中.
给源码打补丁:
patch -p0 命令完成后gd-1.8.3子目录下多了个gd_gif.c文件,而文件gd.h和Makefile也被作了相应修改.
进入该子目录:
cd gd-1.8.3
缺省情况下,GD库编译时并不加入JPEG支持,得修改Makefile文件.
修改Makefile文件,使得:
CFLAGS=-O -DHAVE_XPM -DHAVE_JPEG -DHAVE_LIBTTF
LIBS=-lm -lgd -lpng -lz -ljpeg -lttf -lXpm -lX11
此后,编译并安装: 
make
make install
命令完成后,gd.h被拷到/usr/local/include目录下,libgd.a被拷到/usr/local/lib目录下.
3、 PHP-4.0.1pl2de安装和配置
PHPde主要文件有libphp4.a, libphp4.so等.
获取PHP源码de地址为:
http://php.net
取得de文件为php-4.0.1pl2.tar.gz,放于/usr/src目录下.
进入/usr/src目录并解压文件:
cd /usr/src
tar xzvf php-4.0.1pl2.tar.gz
命令完成后多了一个子目录php-4.0.1pl2,PHPde源码文件就在其中.
进入该子目录:
cd php-4.0.1pl2
该目录中deINSTALL文件详细介绍了如何安装PHP,照章行事即可.
配置生成Makefile文件:
./configure ’–with-apxs=/usr/sbin/apxs’ ’–with-mysql‘ 
‘–with-config-file-path=/etc/httpd’ ’–enable-safe-mode’ 
‘–with-system-regex’ ’–disable-debug’ 
‘–with-zlib’ ’–enable-magic-quotes’ ’–enable-track-vars’ 
‘–with-jpeg-dir=/usr/local’ ’–with-gd=/usr/local’
注意最后一行参数’–with-jpeg-dir=/usr/local’ ’–with-gd=/usr/local’,指明了Jpeg和GDde目录为/usr/local,这是根据步骤1、2中make installde结果而指定de.
(由于命令太长,建议写成shell文件再执行.文件my-php-conf内容如下:
#! /bin/sh
./configure ’–with-apxs=/usr/sbin/apxs’ ’–with-mysql‘ 
‘–with-config-file-path=/etc/httpd’ ’–enable-safe-mode’ 
‘–with-system-regex’ ’–disable-debug’ 
‘–with-zlib’ ’–enable-magic-quotes’ ’–enable-track-vars’ 
‘–with-jpeg-dir=/usr/local’ ’–with-gd=/usr/local’
用shell执行之:
sh my-php-conf
效果是一样de.)
命令完成后该目录下多了个Makefile文件.
编译并安装:
make
make install
命令完成后,libphp4.so被拷到/usr/lib/apache目录下.
4、 Apachede配置
Apache本身不必重新编译安装,但使用了新dePHP,须让Apache知道,得修改Apachede配置文件并重启Apache服务.
修改Apache配置文件/etc/httpd/conf/httpd.conf,使得文件中包含以下几行:
LoadModule php4_module modules/libphp4.so
AddModule mod_php4.c
AddType application/x-httpd-php .php3 .php
同时注意把旧dephp3de相应行注释掉,否则会出现冲突而使Apache重启失败.
重启Apache服务:
/etc/rc.d/init.d/httpd restart
5、 实例测试
再次按步骤0de说明检查当前状态,我已经看到,PHP改成了新de版本号,GD库也同时支持GIF和JPEG了.
但我还是想用实例来测试一下,这个例子de功能是读取一个gif文件,生成缩图,然后保存为另一个jpg文件.文件create-thumb.phpde内容如下:
<?
function CreateThumbnail($srcFile, $dstFile, $dstW, $dstH)
{
$data = GetImageSize($srcFile,&$info);
switch ($data[2]) {
case 1:
$im = @ImageCreateFromGIF($srcFile);
break;
case 2:
$im = @ImageCreateFromJPEG($srcFile);
break;
case 3:
$im = @ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
if ($srcW <= $dstW && $srcH <= $dstH)
ImageJPEG($im,$dstFile);
else
{
if(($srcW / $srcH) > ($dstW / $dstH))
$dstH = $dstW * $srcH / $srcW;
else
$dstW = $dstH * $srcW / $srcH;
$ni=ImageCreate($dstW,$dstH);
ImageCopyResized($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
ImageJPEG($ni,$dstFile);
}
}
CreateThumbnail("./test.gif", "./test-tn.jpg", 80, 80);
?>
把该文件放于Apahcede文档目录下(/etc/httpd/html),同时把测试用de图像文件test.gif也放于该目录下,然后用浏览器打开该php文件(我dehostname为zhangzh):
http://zhangzh/create-thumb.php
没出错信息.再看Apahcede文档目录(/etc/httpd/html),多了一个缩图文件test-tn.jpg.
大功告成,班师回朝.

一棵php的类树(支持无限分类)

星期一, 06月 2nd, 2008

最近问无限分类de类树问题比较多,所以一高兴自己写了一个,我刚写完de,大家用用看,看看怎么实现起来更快,更简单,把您de树也贴出来(要只查询一次数据库de)<br>
这是一棵分类列表de类树, 支持无限分类<br>
一个分类下面可以同时有”包含子类de分类”和”最终分类”;<br>
唯一de优点是*****只需要进行一次de数据库*****查询.<br>
样子不是很好看,不过可以自定义修改,可以自己定义css加里面<br>
缓存方面还没有作,可以自己补上
下面例子de目录结构是这样de.
¦–Catagory.php <br>
¦–images—-tree.jsp <br>
¦–images—-treeopen.gif <br>
¦–images—-treeclose.gif <br>
¦–images—-line.gif <br>
/****************tree.jsp********************/
function expand(id){
node = document.all(’node’ id);
if(node.style.display==”){
node.style.display = ‘none’;
document.images(’img’ id).src = imgopen;
}else{
node.style.display = ”;
document.images(’img’ id).src = imgclose;
}
}
/****************Catagory.php********************/
<?php
define(’CATAGORY_TREE_EXPEND_NONE’,0);
define(’CATAGORY_TREE_EXPEND_ALL’,1);
class Catagory{
//基础分类数据
var $treeData = array();
//分类de等级结构数组,以分类deid值作为数组de关键字
var $treePList = array();
//自分类对应上级类de关系
var $treeCList = array();
/*
* 这个是大分类de模板
*
* __id__ 分类de编号
* __name__ 分类de名称
* __image__ 分类前面显示de图像名称 $imgOpen or $imgClose
* __open__ 分类当前是否是展开de
* __inner__ 子分类显示de位置

* 样式可以根据自己de需要任意修改 ,但是不能删除现有de元素
*/
var $blockTpl = ‘
<table border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td colspan=”2″><a onclick=”expand(__id__); return false;” href=”#”>
<img src=”__image__” border=”0″ width=”15″ height=”15″ id=”img__id__”></a>
<a onclick=”expand(__id__); return false;” href=”#”>
__name__</a></td>
</tr>
<tr id=”node__id__” style=”display:__open__;”>
<td width=”20″></td><td>__inner__</td>
</tr>
</table>’;
/*
* 这个是小分类de模板
*
* see $blockTpl
*/
var $elementTpl = ‘<img src=”images/line.gif” width=”15″ height=”15″><a href=”?id=__id__”><font color=”white”>__name__</font></a><br/>’;
/*
* 这个是当前位置显示模板
*
* see $blockTpl
*/
var $currentTpl = ‘<a href=”?id=__id__”><font color=”white”>__name__</font></a>’;
var $js = “images/tree.js”;
var $imgOpen = ‘images/treeopen.gif’;
var $imgClose = ‘images/treeclose.gif’;
var $imgLine = ‘images/line.gif’;
var $cachFile = ”;
var $expand = 0;
var $result = array();
var $treeStr = ”;
var $currentStr = ”;
/*
* 用来初始化,传入分类数据
*
*param $data array()
*/
function Catagory(&$data){
$this->_init($data);
}
function _init($tmpData){
$plevel = $clevel = $treeData = array();

foreach($tmpData as $value){
$treeData[$value['id']] = $value;
$plevel[$value['pid']][$value['id']] = ‘END’;
$clevel[$value['id']] = $value['pid'];
}
$this->treeData = &$treeData;
$this->treePList = &$plevel;
$this->treeCList = &$clevel;
}
/*
* 解析分类列表
*
*param $cataId int 要解析de主分类de编号
*/
function parseNode($cataId=0){
$this->result = $this->treePList[$cataId];
if($this->result==null) die(”Catagory id error”);
$this->treeStr = $this->_doNode($this->result);
$this->treeStr .= $this->_jsParse();
}
function &_doNode(&$result){
$nstr = $estr = ”;
foreach($result as $key=>$value){
if(isset($this->treePList[$key])){
$result[$key] = $this->treePList[$key];
$inner = $this->_doNode($result[$key]);
$nstr .= $this->_parseNodeTpl($key, $inner);
}else{
$estr .= $this->_parseElementTpl($key);
}
}
return $nstr.$estr;
}
function &_parseNodeTpl($cataId, $inner){
$data = $this->treeData[$cataId];
$str = preg_replace(’ ¦__id__ ¦’, $data['id'], $this->blockTpl);
$str = preg_replace(’ ¦__name__ ¦’, $data['name'], $str);
$str = preg_replace(’ ¦__image__ ¦’, ($this->expand? $this->imgClose:$this->imgOpen), $str);
$str = preg_replace(’ ¦__open__ ¦’, ($this->expand?”:’none’), $str);
$str = preg_replace(’ ¦__inner__ ¦’, $inner, $str);
return $str;
}
function _parseElementTpl($cataId){
$data = $this->treeData[$cataId];
$str = preg_replace(’ ¦__id__ ¦’, $data['id'], $this->elementTpl);
$str = preg_replace(’ ¦__name__ ¦’, $data['name'], $str);
$str = preg_replace(’ ¦__image__ ¦’, $this->imgLine, $str);
return $str;
}

function _jsParse(){
$str = “<script language=\”javascript\”>
imgopen = \”$this->imgOpen\”;
imgclose = \”$this->imgClose\”;
</script><script src=\”$this->js\” language=\”javascript\”></script>”;
return $str;
}
/*
* 展开分类$cataId
*
*param $cataId int 要展开de分类de编号
*/
function parseCurrent($cataId){
$str = ”;
$str .= $this->_parseCurrentTpl($cataId);
while(isset($this->treeCList[$cataId]) && $this->treeCList[$cataId]!=0){
$cataId = $this->treeCList[$cataId];
$str = $this->_parseCurrentTpl($cataId).’->’.$str;
}
$this->currentStr = &$str;
}
function _parseCurrentTpl($cataId){
$data = $this->treeData[$cataId];
$str = preg_replace(’ ¦__id__ ¦’, $data['id'], $this->currentTpl);
$str = preg_replace(’ ¦__name__ ¦’, $data['name'], $str);
return $str;
}
/*
* 解析当前分类de路径
*
*param $cataId int 要解析de主分类de编号
*/
function expand($cataId){
if($this->expand>0) return ;
$str = ”;
if(isset($this->treePList[$cataId])) $str .= “expand($cataId);”;
while(isset($this->treeCList[$cataId]) && $this->treeCList[$cataId]!=0){
$str .= “expand(”.$this->treeCList[$cataId].”);”;
$cataId = $this->treeCList[$cataId];
}
$this->treeStr .= “<script language=\”javascript\”>$str</script>”;
}
/*
* 返回当前分类de路径
*/
function getCurrentStr(){

return $this->currentStr;
}
/*
* 返回分类de类树
*/
function getTreeStr(){
return $this->treeStr;
}
function setTpl($blockTpl, $elementTpl, $currentTpl, $js){
$this->blockTpl = $blockTpl;
$this->elementTpl = $elementTpl;
$this->currentTpl = $currentTpl;
$this->js = $js;
}
function setImage($open, $close, $line){
$this->imgOpen = $open;
$this->imgClose = $close;
$this->imgLine = $line;
}
function setExpend($expand){
$this->expand = $expand;
}
}
//分类de基础数据de样子如下:
$data = array(array(’id’=>1, ‘name’=>’name1′, ‘pid’=>0, ‘order’=>1),
array(’id’=>2, ‘name’=>’name2′, ‘pid’=>1, ‘order’=>1),
array(’id’=>3, ‘name’=>’name3′, ‘pid’=>0, ‘order’=>1),
array(’id’=>4, ‘name’=>’name4′, ‘pid’=>3, ‘order’=>1),
array(’id’=>5, ‘name’=>’name5′, ‘pid’=>6, ‘order’=>1),
array(’id’=>6, ‘name’=>’name6′, ‘pid’=>2, ‘order’=>1),
array(’id’=>7, ‘name’=>’name7′, ‘pid’=>6, ‘order’=>1),
array(’id’=>8, ‘name’=>’name8′, ‘pid’=>3, ‘order’=>1),
array(’id’=>9, ‘name’=>’name9′, ‘pid’=>6, ‘order’=>1),
array(’id’=>10, ‘name’=>’name10′, ‘pid’=>0, ‘order’=>1),
array(’id’=>11, ‘name’=>’name11′, ‘pid’=>10, ‘order’=>1),
array(’id’=>12, ‘name’=>’name12′, ‘pid’=>10, ‘order’=>1),
array(’id’=>13, ‘name’=>’name13′, ‘pid’=>10, ‘order’=>1),
array(’id’=>14, ‘name’=>’name14′, ‘pid’=>12, ‘order’=>1),
array(’id’=>15, ‘name’=>’name15′, ‘pid’=>12, ‘order’=>4),
);

echo “<body bgcolor=\”blue\”>”;
$tree = new Catagory($data);
echo “<hr>下面是当前分类de类树<hr>”;
//$tree->setExpend(1);
$tree->parseNode(0);
//$tree->parseNode(1);
//$tree->expand(9);
echo $tree->getTreeStr();
echo “<hr>下面是当前分类(分类de编号是9)de路径<hr>”;
$tree->parseCurrent(9);
echo $tree->getCurrentStr();