php无限级回复怎么处理,ThinkPHP无限级分类原理实现留言与回复功能实例

gclist("id,username,inputtime,pid,url,content,path,concat(path,'-',id) as bpath");

$this->assign('Gklist',$garr['list']);

$this->assign('page',$garr['page']);

$this->display();

}

// +----------------------------------------------------------------------

// | 添加留言

// +----------------------------------------------------------------------

public function add(){

$this->adddata('Guestbook');

}

// +----------------------------------------------------------------------

// | 网址跳转。如在表单url添加网址的话,点击会跳转到相关网站

// +----------------------------------------------------------------------

public function tourl(){

$this->gettourl('Guestbook');

}

}

?>

// +----------------------------------------------------------------------

// | WBlog

// +----------------------------------------------------------------------

// | Copyright (c) 2008 http://www.w3note.com All rights reserved.

// | Author: 网菠萝果

// +----------------------------------------------------------------------

// $Id$

/**

+------------------------------------------------------------------------------

@function 留言板模型 类GuestbookModel.class.php

+------------------------------------------------------------------------------

*/

class GuestbookModel extends RelationModel{

// +----------------------------------------------------------------------

// | $_validate表单自动验证

// +----------------------------------------------------------------------

protected $_validate = array(

array('email','require','请填写您的邮箱!'),

array('email','email','邮箱格式错误!'),

);

// +----------------------------------------------------------------------

// | $_auto表单自动填充

// +----------------------------------------------------------------------

protected $_auto=array(

array('status','1'),

array('inputtime','time',1,'function'),

array('content','content','callback'),

array('url','geturl',

array ('inputtime',

array('path','path',3,

array('username','getusername',

);

// +----------------------------------------------------------------------

// | getusername()过滤用户名

// +----------------------------------------------------------------------

public function getusername(){

if (isset ($_POST['username'])) {

if(trim($_POST['username'])=='网菠萝果'){

return $data= ' ̄□ ̄';

}elseif(strlen($_POST['username']) >10){

return $data= msubstr($_POST['username'],5);

}else{

return $data= $_POST['username'];

}

}

}

// +----------------------------------------------------------------------

// | path()返回子类的path,父类的path的值为0

// +----------------------------------------------------------------------

public function path(){

$pid=isset($_POST['pid'])?(int)$_POST['pid']:0;

$id=$_POST['id'];

if($pid==0){

return 0;

}

$fat=$this->where(array('id' => $pid))->find();

$data=$fat['path'].'-'.$fat['id'];

return $data;

}

// +----------------------------------------------------------------------

// | content()过滤留言内容

// +----------------------------------------------------------------------

public function content() {

if (isset ($_POST['content']) && !empty ($_POST['content'])) {

$data =deleteHtmlTags($_POST['content']);

$data =safeHtml($data);

if (strlen($data) > 1000) {

$data = msubstr($data,500);

}

return $data;

}

}

// +----------------------------------------------------------------------

// | content()过滤URL

// +----------------------------------------------------------------------

public function geturl(){

if (isset ($_POST['url'])) {

$data = deleteHtmlTags($_POST['url']);

$data = safeHtml($data);

return $data=$data?$data:"";

}

}

// +----------------------------------------------------------------------

// |gclist($field,$where='',$pagesize=30)留言列表

// +----------------------------------------------------------------------

// |$field,字段

// +----------------------------------------------------------------------

// |$where查询条件,默认为空

// +----------------------------------------------------------------------

// |$pagesize分页记录,默认为30

// +----------------------------------------------------------------------

// |使用方法,看上面的控制器调用

// +----------------------------------------------------------------------

public function gclist($field,$pagesize=30) {

import("ORG.Util.Page");

$count = $this->field('id')->where($where)->count();

$P = new Page($count,$pagesize);

$list=$this->field($field)->where($where)->order('bpath,id')->limit($P->firstRow . ',' . $P->listRows)->select();

foreach ($list as $k => $v) {

$list[$k]['count'] = count(explode('-',$v['bpath']));

$list[$k]['tousername']=$this->where(array('id'=> $v['pid']))->getField('username');

$str = '';

if ($v['pid'] <> 0) {

for ($i = 0; $i < $list[$k]['count'] * 2; $i++) {

$str .= '';

}

$str .= ' ';

}

$list[$k]['space'] = $str;

}

$P->setConfig('header','篇');

$P->setConfig('prev',"«");

$P->setConfig('next','»');

$P->setConfig('first','|«');

$P->setConfig('last','»|');

$page = $P->show();

$arr=array('page'=>$page,'list'=>$list);

return $arr;

}

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值