Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[分享] 帖子批量合并功能

[复制链接]
寻找if 发表于 2011-8-1 15:33:13 | 显示全部楼层 |阅读模式
                                //批量合并
                                $modaction = 'MRGA';
                                checkreasonpm();//输入原因
                                $threadid = implode(",", $moderate);
                                $query = "SELECT * FROM  {$tablepre}threads WHERE displayorder>='0' AND tid IN ($threadid) ORDER BY dateline";
                                $result = $db->query($query);
                                while($row = mysql_fetch_array($result))
                                {
                                        $otherall[] = $row;
                                }
                                $mergeallnum = count($otherall);
                                if(!$otherall) {
                                        showmessage('admin_merge_nonexistence');//主题不存在
                                } elseif($mergeallnum > 1) {
                                        for($c=0;$c<=$mergeallnum;$c++)
                                        {
                                                if($otherall[$c]['special'])
                                                showmessage('special_noaction');//无法操作特殊主题
                                        }
                                }
                                if($mergeallnum > 1) {
                                        for($c=0;$c<=$mergeallnum;$c++)
                                        {
                                                if($adminid == 3 && $otherall[$c]['fid'] != $forum['fid'])
                                                showmessage('admin_merge_invalid');//请选择其他主题进行合并
                                        }
                                }
                                $otherall[0]['views'] = intval($otherall[0]['views']);
                                $otherall[0]['replies']++;
                                $i=1;
                                $j=0;
                                $postsmerged=0;
                                while($i != $mergeallnum) {
                                $othertid= $otherall[$j]['tid'];
                                $tid = $otherall[$i]['tid'];
                                $views = $otherall[$i]['views'];
                                $replies = $otherall[$i]['replies'];
                                $firstpost = $db->fetch_first("SELECT pid, fid, authorid, author, subject, dateline FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0' ORDER BY dateline LIMIT 1");//查询后续的帖子内容
                                $db->query("UPDATE {$tablepre}posts SET tid='$tid' WHERE tid='$othertid'");//回复表:把需要合并的目标帖子的回复内容的tid转换成当前帖子的id
                                $postsmerged += $db->affected_rows();
                                $db->query("UPDATE {$tablepre}attachments SET tid='$tid' WHERE tid='$othertid'");       
                                $db->query("DELETE FROM {$tablepre}threads WHERE tid='$othertid'");
                                $db->query("DELETE FROM {$tablepre}threadsmod WHERE tid='$othertid'");
                                $db->query("UPDATE {$tablepre}posts SET first=(pid='$firstpost[pid]'), fid='$firstpost[fid]' WHERE tid='$tid'");
                                $db->query("UPDATE {$tablepre}threads SET authorid='$firstpost[authorid]', author='".addslashes($firstpost['author'])."', subject='".addslashes($otherall[0]['subject'])."', dateline='$firstpost[dateline]', views=views+$views, replies=replies+$replies, moderated='1' WHERE tid='$tid'");
                                if($fid == $otherall[0]['fid']) {
                                        $db->query("UPDATE {$tablepre}forums SET threads=threads-1 WHERE fid='$fid'");
                                } else {
                                        $db->query("UPDATE {$tablepre}forums SET threads=threads-1, posts=posts-$postsmerged WHERE fid='$otherall[0][fid]'");
                                        $db->query("UPDATE {$tablepre}forums SET posts=$posts+$postsmerged WHERE fid='$fid'");
                                }
                                $forum['threadcaches'] && deletethreadcaches($thread['tid']);
                                $i++;
                                $j++;

qaz963120 发表于 2011-8-26 17:17:05 | 显示全部楼层
uery = "SELECT *
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-6-18 02:48 , Processed in 0.092199 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表