时时商务社区

标题: dedecms 5.6 删除文章同时删除图片的方法 [打印本页]

作者: 新格网络    时间: 2018-2-13 20:40

最新dedecms5.6删除文章对应删除图片
本代码没改dede代码!只加了删除方法到里面!覆盖就可以了!覆盖时备份好文件!
您也可以看着对应修改!学习一下!
在dede5.6gbk版测试成功!utf8大家自己测试 !覆盖前备份好文件
/include/extend.func.php
复制代码代码如下:
]*){0,}(([^>]*)\.(gif|jpg|png))/isU",$body,$tmpdata);
$picspath = array_unique($tmpdata[2]);//body中所有图片的地址
foreach($picspath as $tmppath)
{
$path = GetTruePath();//获得绝对路径
$picpath = preg_replace("/[a-zA-z]+:\/\/[^ |\/|\s]*/",'',$tmppath);//去掉网址部分
$path .=$picpath;
$delfiles[] = $path;//保存处理后的数据
}
return $delfiles;
}
function WriteToDelFiles($msg)//删除文章的时候会通过此函数记录日志
{
if(empty($msg)) $savemsg="未获得消息";
else $savemsg = $msg;
$errorFile = dirname(__FILE__).'/../data/del_body_file.txt';//删除记录文件
$fp = @fopen($errorFile, 'a');
@fwrite($fp,"\r\n{$savemsg}");
@fclose($fp);
}
//获得文章Body数据
function GetArcBody($aid)
{
global $dsql;
$query = "SELECT dede_addonarticle.body FROM dede_addonarticle WHERE dede_addonarticle.aid = '$aid'";
$row = $dsql->GetOne($query);
if(is_array($row)) return $row;
else return false;
}
function lit($){
global $lit_;
$dsql = new DedeSql(false);
//获取附加表
$row = $dsql->GetOne("SELECT c.addtable FROM dede_archives AS a LEFT JOIN dede_channeltype AS c ON a.channel=c.id where a.id='$'");
$addtable = trim($row['addtable']);
//获取图片附加表字段内容进行处理
$row = $dsql->GetOne("Select `$addtable` where aid='$'");
//调用inc_channel_unit.php中ChannelUnit类
$ChannelUnit = new ChannelUnit(2,$);
//调用ChannelUnit类中GetlitImgLinks方法处理缩略图
$lit_$ChannelUnit->GetlitImgLinks($row['']);
//返回结果
return $lit_;
}
?>
\dede\inc\inc_batchup.php
复制代码代码如下:
GetOne($query);
$nid = $row['nid'];
$maintable = (trim($row['maintable'])=='' ? 'dede_archives' : trim($row['maintable']));
$addtable = trim($row['addtable']);
$issystem = $row['issystem'];
//查询档案信息
if($issystem==-1)
{
$arcQuery = "Select arc.*,tp.* from `$addtable` arc left join `dede_arctype` tp on arc.typeid=tp.id where arc.aid='$aid' ";
}
else
{
$arcQuery = "Select arc.*,tp.*,arc.id as aid from `$maintable` arc left join `dede_arctype` tp on arc.typeid=tp.id where arc.id='$aid' ";
}
$arcRow = $dsql->GetOne($arcQuery);
$arcBodyRow = GetArcBody($aid);
//检测权限
if(!TestPurview('a_Del,sys_ArcBatch'))
{
if(TestPurview('a_AccDel'))
{
if( !in_array($arcRow['typeid'], $admin_catalogs) && (count($admin_catalogs) != 0 || $cfg_admin_channel != 'all') )
{
return false;
}
}
else if(TestPurview('a_MyDel'))
{
if($arcRow['mid'] != $cuserLogin->getUserID())
{
return false;
}
}
else
{
return false;
}
}
//$issystem==-1 是单表模型,不使用回收站
if($issystem == -1) $type = 'OK';
if(!is_array($arcRow)) return false;
/** 删除到回收站 **/
if($cfg_delete == 'Y' && $type == 'ON')
{
$dsql->ExecuteNoneQuery("Update `$maintable` set arcrank='-2' where id='$aid' ");
$dsql->ExecuteNoneQuery("Update `dede_arctiny` set `arcrank` = '-2' where id = '$aid'; ");
}
else
{
//删除数据库记录
if(!$onlyfile)
{
//删除相关附件
if($cfg_upload_switch == 'Y')
{
$dsql->Execute("me", "SELECT * FROM `dede_uploads` WHERE arcid = '$aid'");
while($row = $dsql->GetArray('me'))
{
$addfile = $row['url'];
$aid = $row['aid'];
$dsql->ExecuteNoneQuery("Delete From `dede_uploads` where aid = '$aid' ");
$upfile = $cfg_basedir.$addfile;
if(@file_exists($upfile)) @unlink($upfile);
}
}
$dsql->ExecuteNoneQuery("Delete From `dede_arctiny` where id='$aid'");
if($addtable != '')
{
$dsql->ExecuteNoneQuery("Delete From `$addtable` where aid='$aid' ");
}
if($issystem != -1)
{
$dsql->ExecuteNoneQuery("Delete From `dede_archives` where id='$aid' ");
}
$dsql->ExecuteNoneQuery("Delete From `dede_feedback` where aid='$aid' ");
$dsql->ExecuteNoneQuery("Delete From `dede_member_stow` where aid='$aid' ");
$dsql->ExecuteNoneQuery("Delete From `dede_taglist` where aid='$aid' ");
$dsql->ExecuteNoneQuery("Delete From `dede_erradd` where aid='$aid' ");
}
//删除文本数据
$filenameh = DEDEDATA."/textdata/".(ceil($aid/5000))."/{$aid}-".substr(md5($cfg_cookie_encode),0,16).".txt";
if(@is_file($filenameh)) @unlink($filenameh);
}
if(empty($arcRow['money'])) $arcRow['money'] = 0;
if(empty($arcRow['ismake'])) $arcRow['ismake'] = 1;
if(empty($arcRow['arcrank'])) $arcRow['arcrank'] = 0;
if(empty($arcRow['filename'])) $arcRow['filename'] = '';
//删除HTML
if($arcRow['ismake']==-1 || $arcRow['arcrank']!=0 || $arcRow['typeid']==0 || $arcRow['money']>0)
{
return true;
}
//强制转换非多站点模式,以便统一方式获得实际HTML文件
$GLOBALS['cfg_multi_site'] = 'N';
$arcurl = GetFileUrl($arcRow['aid'],$arcRow['typeid'],$arcRow['senddate'],$arcRow['title'],$arcRow['ismake'],
$arcRow['arcrank'],$arcRow['namerule'],$arcRow['typedir'],$arcRow['money'],$arcRow['filename']);
if(!ereg("\?", $arcurl))
{
$htmlfile = GetTruePath().str_replace($GLOBALS['cfg_basehost'],'',$arcurl);
if(file_exists($htmlfile) && !is_dir($htmlfile))
{
@unlink($htmlfile);
$arcurls = explode(".", $htmlfile);
$sname = $arcurls[count($arcurls)-1];
$fname = ereg_replace("(\.$sname)$", "", $htmlfile);
for($i=2; $i
修改后的文件打包下载





欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2