dedecms 5.6 删除文章同时删除图片的方法

dedecms的数据库操作类,非常实用,在二次开发中尤其重要,这个数据库操作类说明算是奉献给大家的小礼物了。

最新dedecms5.6删除文章对应删除图片
本代码没改dede代码!只加了删除方法到里面!覆盖就可以了!覆盖时备份好文件!
您也可以看着对应修改!学习一下!
在dede5.6gbk版测试成功!utf8大家自己测试 !覆盖前备份好文件
/include/extend.func.php

引入common.inc.php文件

复制代码代码如下:
function GetPicsTruePath($body,$litpic)
//解析body数据,获得所有图片的绝对地址
{
$delfiles = array();//存储图片地址数据
if(!empty($litpic))
{
$litpicpath = GetTruePath();
$litpicpath .= $litpic;
$delfiles[] = $litpicpath;//缩略图地址
}
preg_match_all(“/src=[“|’|S|s]([^
|/|>]*){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(apizl_file).’/../data/del_body_file.txt’;//删除记录文件
$fp = @fopen($errorFile, ‘a’);
@fwrite($fp,”rn{$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 litimgurls($imgid=0){
global $lit_imglist;
$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=’$imgid'”);
$addtable = trim($row[‘addtable’]);
//获取图片附加表imgurls字段内容进行处理
$row = $dsql->GetOne(“Select imgurls From `$addtable` where
aid=’$imgid'”);
//调用inc_channel_unit.php中ChannelUnit类
$ChannelUnit = new ChannelUnit(2,$imgid);
//调用ChannelUnit类中GetlitImgLinks方法处理缩略图
$lit_imglist = $ChannelUnit->GetlitImgLinks($row[‘imgurls’]);
//返回结果
return $lit_imglist;
}
?>

require_once (dirname(__FILE__) . /include/common.inc.php);

dedeincinc_batchup.php

获取一条记录的内容

复制代码代码如下:
function DelArc($aid,$type=’ON’,$onlyfile=false)
{
global $dsql,$cfg_cookie_encode,$cfg_multi_site,$cfg_medias_dir;
global $cuserLogin,$cfg_upload_switch,$cfg_delete,$cfg_basedir;
global $admin_catalogs, $cfg_admin_channel;
if($cfg_delete == ‘N’) $type = ‘OK’;
if(empty($aid)) return ;
$aid = ereg_replace(“[^0-9]”, ”, $aid);
$arctitle = $arcurl = ”;
//查询表信息
$query = “Select ch.maintable,ch.addtable,ch.nid,ch.issystem From
`dede_arctiny` arc
left join `dede_arctype` tp on tp.id=arc.typeid
left join `dede_channeltype`澳门新浦京8455com, ch on ch.id=arc.channel where
arc.id=’$aid’ “;
$row = $dsql->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<=100; $i++)
{
$htmlfile = $fname.”_{$i}.”.$sname;
if( @file_exists($htmlfile) ) @unlink($htmlfile);
else break;
}
}
}
//解析Body中的资源,并删除
$willDelFiles =
GetPicsTruePath($arcBodyRow[‘body’],$arcRow[‘litpic’]);
$nowtime = time();
$executetime = MyDate(‘Y-m-d H:i:s’,$nowtime);//获得执行时间
$msg = “rn文章标题:$arcRow[title]”;
WriteToDelFiles($msg);
if(!empty($willDelFiles))
{
foreach($willDelFiles as $file)
{
if(file_exists($file) && !is_dir($file))
{
if(unlink($file)) $msg =
“rn位置:$filern结果:删除成功!rn时间:$executetime”;
else $msg =
“rn位置:$filern结果:删除失败!rn时间:$executetime”;
}
else $msg =
“rn位置:$filern结果:文件不存!rn时间:$executetime”;
WriteToDelFiles($msg);
}//END foreach
}
else
{
$msg =
“rn未在Body中解析到数据rnBody原始数据:$arcBodyRow[body]rn时间:$executetime”;
WriteToDelFiles($msg);
}
return true;
}
//获取真实路径
function GetTruePath($siterefer=”, $sitepath=”)
{
$truepath = $GLOBALS[‘cfg_basedir’];
return $truepath;
}
?>

$row = $dsql-GetOne(Select * From dede_* where id = $aid);

echo $row[id];

修改后的文件打包下载

将查询获取总数输出

$row = $dsql-GetOne(select count(*) as dd where typeid = $typeid);

echo $row[dd];//输出总数

将查询的若干条记录输出

$sql = Select * from dede_*;

$dsql-SetQuery($sql);//将SQL查询语句格式化

$dsql-Execute();//执行SQL操作

//通过循环输出执行查询中的结果

while($row = $dsql-GetArray()){

echo $row[id];

echo $row[title];

}

//或者采取这种方式输出内容

while($row = $dsql-GetObject()){

echo $row-id;

echo $row-Title;

}

将查询的若干条记录输出dedecms5

$dsql-SetQuery(Select id,typename From `dede_arctype` where reid=0
And channeltype=1 And ishidden=0 And ispart2 order by sortrank);

$dsql-Execute();

while($row=$dsql-GetObject())

{

$channellist .= a
href=wap.php?action=listid={$row-id}{$row-typename}/a ;

echo $row-id;

}

插入一条记录

$sql =

INSERT INTO
`dede_member_flink`(mid,title,url,linktype,imgurl,imgwidth,imgheight)

VALUES(.$cfg_ml-M_ID.,$title,$url,$linktype,$imgurl,$imgwidth,$imgheight);;//插入记录数据库

$dsql-SetQuery($sql);//格式化查询语句

$dsql-ExecNoneQuery();//执行SQL操作

经实践证明,上面的语句不能正常插入数据库,下面是正确的语句

$sql =

INSERT INTO
`dede_member_flink`(mid,title,url,linktype,imgurl,imgwidth,imgheight)

VALUES(.$cfg_ml-M_ID.,$title,$url,$linktype,$imgurl,$imgwidth,$imgheight);;//插入记录数据库

$dsql-ExecuteNoneQuery($sql);//执行SQL操作

$gid = $dsql-GetLastID();//获取刚刚插入的id

删除一条记录

$sql = Delete From dede_member_flink where aid=$aid And
mid=.$cfg_ml-M_ID.;;

$dsql-SetQuery($sql);

$dsql-ExecNoneQuery();

//或者使用简化模式

$dsql-ExecNoneQuery(Delete From dede_member_flink where aid=$aid And
mid=.$cfg_ml-M_ID.;);

更新一条记录

$upquery =

Update dede_member_flink set

title=$title,url=$url,linktype=$linktype,

imgurl=$imgurl,imgwidth=$imgwidth,imgheight=$imgheight

where aid=$aid And mid=.$cfg_ml-M_ID.;

;

$rs = $dsql-ExecuteNoneQuery($upquery);

判断获取数据库内容的常用方法

$row = $dsql-GetOne(Select * From dede_moneycard_type where
tid={$pid});

if(!is_array($row)){

echo 失败;

exit();

}

/////////////////////////////

$upquery = Update dede_member_flink set

title=$title,url=$url,linktype=$linktype,

imgurl=$imgurl,imgwidth=$imgwidth,imgheight=$imgheight

where aid=$aid And mid=.$cfg_ml-M_ID.;

;

$rs = $dsql-ExecuteNoneQuery($upquery);

if($rs){

echo 成功;

}else{

echo 失败;

}

获取总数

$dsql = new DedeSql(false);

$dsql-SetQuery(Select * from `dede_admin` where userid=$userid Or
uname=$uname);

$dsql-Execute();

$ns = $dsql-GetTotalRow();

关闭数据库

$dsql-Close();

实例

?php

/*

DedeCms 数据库使用实例说明

*/

require_once
dirname(__FILE__).pub_db_mysql.php;//引用数据库文件

//确保数据库信息填写正确

//数据库连接信息

$cfg_dbhost = localhost;

$cfg_dbname = sccms;

$cfg_dbuser = root;

$cfg_dbpwd = 123456;

$cfg_dbprefix = sc_;

$cfg_db_language = utf8;

//新建一个数据库操作类

$dsql = new ScSql(false);

////////////////////////////////获取一条记录的内容///////////////////////////////

//下面是获取一条记录使用实例

$row = $dsql-GetOne(Select * From dede_* where id = $aid);

//获取数据内容保存在数组$row中,通过下标可以将其调用出来

echo $row[id];

//下面是循环调用记录

///////////////////////////////////////////////////////////////////////////////

//////////////////////////////将查询获取总数输出/////////////////////////////

//获取一个查询记录总数

$row = $dsql-GetOne(select count(*) as dd where typeid = $typeid);

echo $row[dd];//输出总数

///////////////////////////////////////////////////////////////////////////////

//////////////////////////////将查询的若干条记录输出//////////////////////////////////

$sql = Select * from dede_*;

$dsql-SetQuery($sql);//将SQL查询语句格式化

$dsql-Execute();//执行SQL操作

//通过循环输出执行查询中的结果

while($row = $dsql-GetArray()){

echo $row[id];

echo $row[title];

}

//或者采取这种方式输出内容

while($row = $dsql-GetObject()){

echo $row-id;

echo $row-Title;

}

///////////////////////////////////////////////////////////////////////////////

//////////////////////////////插入一条记录///////////////////////////////

$sql =

INSERT INTO
`dede_member_flink`(mid,title,url,linktype,imgurl,imgwidth,imgheight)

VALUES(.$cfg_ml-M_ID.,$title,$url,$linktype,$imgurl,$imgwidth,$imgheight);;//插入记录数据库

$dsql-SetQuery($sql);//格式化查询语句

$dsql-ExecNoneQuery();//执行SQL操作

///////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////删除一条记录///////////////////////////

$sql = Delete From dede_member_flink where aid=$aid And
mid=.$cfg_ml-M_ID.;;

$dsql-SetQuery($sql);

$dsql-ExecNoneQuery();

//或者使用简化模式

$dsql-ExecNoneQuery(Delete From dede_member_flink where aid=$aid And
mid=.$cfg_ml-M_ID.;);

///////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////更新一条记录//////////////////////////

$upquery =

Update dede_member_flink set

title=$title,url=$url,linktype=$linktype,

imgurl=$imgurl,imgwidth=$imgwidth,imgheight=$imgheight

where aid=$aid And mid=.$cfg_ml-M_ID.;

;

$rs = $dsql-ExecuteNoneQuery($upquery);

///////////////////////////////////////////////////////////////////////////////

////////////////////////////////判断获取数据库内容的常用方法///////////////////

$row = $dsql-GetOne(Select * From dede_moneycard_type where
tid={$pid});

if(!is_array($row)){

echo 失败;

exit();

}

/////////////////////////////

$upquery = Update dede_member_flink set

title=$title,url=$url,linktype=$linktype,

imgurl=$imgurl,imgwidth=$imgwidth,imgheight=$imgheight

where aid=$aid And mid=.$cfg_ml-M_ID.;

;

$rs = $dsql-ExecuteNoneQuery($upquery);

if($rs){

echo 成功;

}else{

echo 失败;

}

//////////////////////////////////获取总数//////////////////////////////////

$dsql = new DedeSql(false);

$dsql-SetQuery(Select * from `dede_admin` where userid=$userid Or
uname=$uname);

$dsql-Execute();

$ns = $dsql-GetTotalRow();

////////////////////////////////关闭数据库///////////////////////////////////

$dsql-Close();

///////////////////////////////////////////////////////////////////////////////

?

dede数据库类使用方法–$dsql

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图