topicadmin_split.php
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: topicadmin_split.php 30872 2012-06-27 10:11:44Z liulanbo $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
if(!$_G['group']['allowsplitthread']) {
showmessage('no_privilege_splitthread');
}
$thread = C::t('forum_thread')->fetch($_G['tid']);
$posttableid = $thread['posttableid'];
if(!submitcheck('modsubmit')) {
require_once libfile('function/discuzcode');
$replies = $thread['replies'];
if($replies <= 0) {
showmessage('admin_split_invalid');
}
$postlist = array();
foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tableid'], $_G['tid'], 'ASC') as $post) {
$post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], sprintf('%00b', $post['htmlon']), $_G['forum']['allowsmilies'], $_G['forum']['allowbbcode'], $_G['forum']['allowimgcode'], $_G['forum']['allowhtml']);
$postlist[] = $post;
}
include template('forum/topicadmin_action');
} else {
if(!trim($_GET['subject'])) {
showmessage('admin_split_subject_invalid');
} elseif(!($nos = explode(',', $_GET['split']))) {
showmessage('admin_split_new_invalid');
}
sort($nos);
foreach(C::t('forum_post')->fetch_all_by_tid_position($thread['posttableid'], $_G['tid'], $nos) as $post) {
$pids[] = $post['pid'];
}
if(!($pids = implode(',',$pids))) {
showmessage('admin_split_new_invalid');
}
$modaction = 'SPL';
$reason = checkreasonpm();
$subject = dhtmlspecialchars($_GET['subject']);
$newtid = C::t('forum_thread')->insert(array('fid'=>$_G['fid'], 'posttableid'=>$posttableid, 'subject'=>$subject), true);
C::t('forum_post')->update('tid:'.$_G['tid'], explode(',', $pids), array('tid' => $newtid));
updateattachtid('pid', (array)explode(',', $pids), $_G['tid'], $newtid);
$splitauthors = array();
foreach(C::t('forum_post')->fetch_all_visiblepost_by_tid_groupby_authorid('tid:'.$_G['tid'], $newtid) as $splitauthor) {
$splitauthor['subject'] = $subject;
$splitauthors[] = $splitauthor;
}
C::t('forum_post')->update('tid:'.$_G['tid'], $splitauthors[0]['pid'], array('first' => 1, 'subject' => $subject), true);
$query = C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $_G['tid'], false, 'ASC', 0, 1);
foreach($query as $row) {
$fpost = $row;
}
C::t('forum_thread')->update($_G['tid'], array('author'=>$fpost['author'], 'authorid'=>$fpost['authorid'],'dateline'=>$fpost['dateline'], 'moderated'=>1));
C::t('forum_post')->update('tid:'.$_G['post'], $fpost['pid'], array('subject' => $thread['subject']));
$query = C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $newtid, false, 'ASC', 0, 1);
foreach($query as $row) {
$fpost = $row;
}
$maxposition = 1;
foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $_G['tid'], false, 'ASC') as $row) {
if($row['position'] != $maxposition) {
C::t('forum_post')->update('tid:'.$_G['tid'], $row['pid'], array('position' => $maxposition));
}
$maxposition ++;
}
C::t('forum_thread')->update($_G['tid'], array('maxposition' => $maxposition));
$maxposition = 1;
foreach(C::t('forum_post')->fetch_all_by_tid('tid:'.$_G['tid'], $newtid, false, 'ASC') as $row) {
if($row['position'] != $maxposition) {
C::t('forum_post')->update('tid:'.$_G['tid'], $row['pid'], array('position' => $maxposition));
}
$maxposition ++;
}
C::t('forum_thread')->update($newtid, array('author'=>$fpost['author'], 'authorid'=>$fpost['authorid'], 'dateline'=>$fpost['dateline'], 'rate'=>intval(@($fpost['rate'] / abs($fpost['rate']))), 'maxposition' => $maxposition));
updatethreadcount($_G['tid']);
updatethreadcount($newtid);
updateforumcount($_G['fid']);
$_G['forum']['threadcaches'] && deletethreadcaches($thread['tid']);
$modpostsnum++;
$resultarray = array(
'redirect' => "forum.php?mod=forumdisplay&fid=$_G[fid]",
'reasonpm' => ($sendreasonpm ? array('data' => $splitauthors, 'var' => 'thread', 'item' => 'reason_moderate', 'notictype' => 'post') : array()),
'reasonvar' => array('tid' => $thread['tid'], 'subject' => $thread['subject'], 'modaction' => $modaction, 'reason' => $reason),
'modtids' => $thread['tid'].','.$newtid,
'modlog' => array($thread, array('tid' => $newtid, 'subject' => $subject))
);
}
?>