小猪cms文本回复二次开发 参考
开发要求
批量导入文本
批量导出文本
批量修改匹配规则
批量删除
部分匹配规则改为包含匹配规则
原规则 淘宝网 回复 淘 淘宝 淘宝网
新规则 淘宝网 回复 淘宝网 淘宝网站 我爱淘宝网
涉及文件
控制器
\pigcms\lib\action\home\weixinaction.class.php
\pigcms\lib\action\user\textaction.class.php
\pigcms\lib\action\user\weixinaction.class.php
模板
\tpl\user\default\text_index.html
\tpl\user\default\text_pladd.html 新增
批量导出同时备份在 /beifen/text/文件夹下 按时间命名
二次开发仅参考
附上导出导入代码[本人是菜鸟qq839024615]//本人菜鸟 代码来自qq839024615
//批量添加
public function pladd(){
if(is_post){
$db=d('text');
$data['uid']=session('uid');
$data['token']=session('token');
$data['uname']=session('uname');
$str=$_post['text'];
$arr=explode(\n,$str);
if(count($arr)>=50){$this->error('对不起,最多支持50条');}
for($i=0;$i $arr=$this->text_explode($arr[$i]);
$precisions=$arr['2'];
$text=$arr['1'];
$keyword=$arr['0'];
$data['precisions']=$precisions;
$data['keyword']=$keyword;
$data['text']=$text;
$data['createtime']=time();
$data['updatetime']=time();
$where['uid']=session('uid');
$where['token']=session('token');
$where['keyword']=$keyword;
$save['updatetime']=time();
$save['precisions']=$precisions;
$save['text']=$text;
$save['uname']=session('uname');
//如果空行直跳过
if(count($arr)>=2){
$f=$db->where($where)->find();
if($f){
echo $is=$db->where($where)->save($save);
if($is){
$this->handlekeyword($f['id'],'text',$keyword,$precisions);
echo $keyword.----更新成功
;
}else{
echo $keyword.----更新失败
;
}
}else{
$is=$db->add($data);
if($is){
$this->handlekeyword($is,'text',$keyword,$precisions);
echo $keyword.----创建成功
;
}else{
echo $keyword.----创建失败
;
}
}
}else{
echo 空行已过滤
;
}
}
echo 返回查看;
}else{
$this->display();
}
}
//批量导出
public function export(){
$db=d('text');
$p=$_get['p'];
if($p){
$name=$_get['name'];
$p=$p+1;
}else{
$name=date('y-m-d his',time());
$p=1;
}
$where['uid']=session('uid');
$where['token']=session('token');
$count=$db->where($where)->count();
$page=new page($count,50);
$list=$db->where($where)->order('updatetime desc')->limit($page->firstrow.','.$page->listrows)->select();
for($i=0;$i $body=$list[$i]['keyword'].|.$list[$i]['text'].|.$list[$i]['precisions'];
$this->text_beifen($name,$body);
}
if($p>=($count/50)){
$this->success('导出完毕',/beifen/text/.$name..txt);
}else{
$this->success('正在第'.$p.'页',u('text/export','p='.$p.'&name='.$name));
}
}
//分切
public function text_explode($text){
$arr=explode(|,$text);
return $arr;
}
//写记事本
public function text_beifen($name=,$body=){
$fp = fopen(beifen/text/.$name..txt, 'ab');
flock($fp, lock_ex);
fwrite($fp, $body.\r\n );
flock($fp, lock_un);
fclose($fp);
}
//本人菜鸟 代码来自qq839024615
ad:真正免费,域名+虚机+企业邮箱=0元