editpost.inc.php
来自「速度很快的PHP论坛源程序」· PHP 代码 · 共 282 行
PHP
282 行
<?
/*
[DISCUZ!] include/editpost.inc.php - post editing for post module
This is NOT a freeware, use is subject to license terms
Version: 4.0.0
Web: http://www.comsenz.com
Copyright: 2001-2005 Comsenz Technology Ltd.
Last Modified: 2004/7/25 05:09
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
$discuz_action = 13;
$query = $db->query("SELECT pid FROM {$tablepre}posts WHERE tid='$tid' ORDER BY dateline LIMIT 1");
$isfirstpost = $db->result($query, 0) == $pid ? 1 : 0;
$query = $db->query("SELECT m.adminid, p.authorid, p.dateline, u.allowhtml FROM {$tablepre}posts p
LEFT JOIN {$tablepre}members m ON m.uid=p.authorid
LEFT JOIN {$tablepre}usergroups u ON u.groupid=m.groupid
WHERE pid='$pid' AND tid='$tid' AND fid='$fid'");
$orig = $db->fetch_array($query);
$isorigauthor = $discuz_uid && $discuz_uid == $orig['authorid'];
$alloweditpost = $alloweditpost && !(in_array($orig['adminid'], array(1, 2, 3)) && $adminid > $orig['adminid']) ? 1 : 0;
if((!$forum['ismoderator'] || !$alloweditpost) && !$isorigauthor) {
showmessage('post_edit_nopermission', NULL, 'HALTED');
} elseif($isorigauthor && !$forum['ismoderator']) {
if($edittimelimit && $timestamp - $orig['dateline'] > $edittimelimit * 60) {
showmessage('post_edit_timelimit', NULL, 'HALTED');
} elseif(($isfirstpost && $modnewthreads) || (!$isfirstpost && $modnewreplies)) {
showmessage('post_edit_moderate');
}
}
if(!submitcheck('editsubmit')) {
include_once language('misc');
if(is_array($_DCACHE['icons']) && $isfirstpost) {
$key = 0;
foreach($_DCACHE['icons'] as $id => $icon) {
$icons .= ' <input type="radio" name="iconid" value="'.$id.'" '.($thread['iconid'] == $id ? 'checked' : NULL).'><img src="'.SMDIR.'/'.$icon.'">';
$icons .= !(++$key % 9) ? '<br>' : NULL;
}
}
$query = $db->query("SELECT * FROM {$tablepre}posts WHERE pid='$pid' AND tid='$tid' AND fid='$fid'");
$postinfo = $db->fetch_array($query);
$usesigcheck = $postinfo['usesig'] ? 'checked' : '';
$urloffcheck = $postinfo['parseurloff'] ? 'checked' : '';
$smileyoffcheck = $postinfo['smileyoff'] == 1 ? 'checked' : '';
$codeoffcheck = $postinfo['bbcodeoff'] == 1 ? 'checked' : '';
$htmloncheck = $postinfo['htmlon'] ? 'checked' : '';
if(($alloweditpoll || $thread['authorid'] == $discuz_uid) && $thread['poll']) {
$query = $db->query("SELECT pollopts FROM {$tablepre}polls WHERE tid='$tid'");
$polloptions = unserialize($db->result($query, 0));
for($i = 0; $i < count($polloptions['options']); $i++) {
$polloptions['options'][$i][0] = htmlspecialchars(stripslashes($polloptions['options'][$i][0]))."\n";
}
} else {
$polloptions = '';
}
if($postinfo['attachment']) {
require_once DISCUZ_ROOT.'./include/attachment.func.php';
$attachments = array();
$query = $db->query("SELECT * FROM {$tablepre}attachments WHERE pid='$postinfo[pid]'");
while($attach = $db->fetch_array($query)) {
$attach['filesize'] = sizecount($attach[filesize]);
$attach['filetype'] = attachtype(fileext($attach['attachment'])."\t".$attach['filetype']);
$attachments[] = $attach;
}
}
$postinfo['subject'] = str_replace('"', """, $postinfo['subject']);
$postinfo['message'] = dhtmlspecialchars($postinfo['message']);
$postinfo['message'] = preg_replace($language['post_edit_regexp'], '', $postinfo['message']);
if($previewpost) {
$postinfo['message'] = $message;
}
include template('post_editpost');
} else {
if(!$delete) {
if($post_invalid = checkpost()) {
showmessage($post_invalid);
}
if($isfirstpost) {
if($subject == '' || $message == '') {
showmessage('post_sm_isnull');
}
$pollopts = '';
if(($alloweditpoll || $thread['authorid'] == $discuz_uid) && $thread['poll'] && trim($polloptions)) {
$query = $db->query("SELECT pollopts FROM {$tablepre}polls WHERE tid='$tid'");
$pollarray = unserialize($db->result($query, 0));
$optsdeleted = 0;
$pollarray['max'] = 0;
foreach($polloptions as $key => $option) {
if(trim($option)) {
$pollarray['options'][$key][0] = $option;
if($pollarray['options'][$key][1] > $pollarray['max']) {
$pollarray['max'] = $pollarray['options'][$key][1];
}
} else {
$optsdeleted = 1;
$pollarray['total'] -= $pollarray['options'][$key][1];
unset($pollarray['options'][$key]);
}
}
if($optsdeleted) {
$newoptions = array();
foreach($pollarray['options'] as $option) {
$newoptions[] = $option;
}
$pollarray['options'] = $newoptions;
unset($newoptions);
}
if($pollarray['options']) {
$poll = 1;
$pollarray['multiple'] = $multiplepoll;
$pollopts = addslashes(serialize($pollarray));
} else {
$poll = 0;
$pollopts = '';
}
}
$db->query("UPDATE {$tablepre}threads SET iconid='$iconid', subject='$subject', poll='$poll' WHERE tid='$tid'", 'UNBUFFERED');
if($thread['poll']) {
if($poll) {
$db->query("UPDATE {$tablepre}polls SET pollopts='$pollopts' WHERE tid='$tid'", 'UNBUFFERED');
} else {
$db->query("DELETE FROM {$tablepre}polls WHERE tid='$tid'", 'UNBUFFERED');
}
}
} else {
if($subject == '' && $message == '') {
showmessage('post_sm_isnull');
}
}
if($editedby && ($timestamp - $orig['dateline']) > 60 && $adminid != 1) {
include_once language('misc');
$editdate = gmdate($_DCACHE['settings']['dateformat'], $timestamp + $timeoffset * 3600);
$edittime = gmdate($_DCACHE['settings']['timeformat'], $timestamp + $timeoffset * 3600);
eval("\$message .= \"$language[post_edit]\";");
}
$bbcodeoff = checkbbcodes($message, $bbcodeoff);
$smileyoff = checksmilies($message, $smileyoff);
$htmlon = $orig['allowhtml'] && $htmlon ? 1 : 0;
$viewpermadd = ($allowsetviewperm && $isfirstpost) ? ", creditsrequire='$viewperm'" : '';
$pattachment = ($allowpostattach && $attachments = attach_upload()) ? 1 : 0;
$tattachment = 0;
if(is_array($attachcreditsrequire)) {
$query = $db->query("SELECT aid, creditsrequire FROM {$tablepre}attachments WHERE pid='$pid' AND aid IN ('".implode('\',\'', array_flip($attachcreditsrequire))."')");
while($attach = $db->fetch_array($query)) {
if($allowsetattachperm && $attach['creditsrequire'] != $attachcreditsrequire[$attach['aid']]) {
$db->query("UPDATE {$tablepre}attachments SET creditsrequire='{$attachcreditsrequire[$attach[aid]]}' WHERE aid='$attach[aid]'");
}
}
}
if(is_array($deleteaid) || $pattachment) {
if(is_array($deleteaid)) {
$deleteaids = '\''.implode("','", $deleteaid).'\'';
$query = $db->query("SELECT aid, attachment FROM {$tablepre}attachments WHERE aid IN ($deleteaids) AND pid='$pid'");
$deleteaids = '0';
while($attach = $db->fetch_array($query)) {
@unlink($attachdir.'/'.$attach['attachment']);
$deleteaids .= ','.$attach['aid'];
}
$db->query("DELETE FROM {$tablepre}attachments WHERE aid IN ($deleteaids)");
}
if($pattachment) {
foreach($attachments as $attach) {
$db->query("INSERT INTO {$tablepre}attachments (tid, pid, creditsrequire, filename, filetype, filesize, attachment, downloads)
VALUES ('$tid', '$pid', '$attach[perm]', '$attach[name]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
}
} else {
$query = $db->query("SELECT aid FROM {$tablepre}attachments WHERE pid='$pid' LIMIT 1");
$pattachment = $db->result($query, 0) ? 1 : 0;
}
if($pattachment) {
$tattachment = 1;
} else {
$query = $db->query("SELECT a.aid FROM {$tablepre}posts p, {$tablepre}attachments a WHERE p.tid='$tid' AND p.invisible='0' AND a.pid=p.pid LIMIT 1");
$tattachment = $db->result($query, 0) ? 1 : 0;
}
$db->query("UPDATE {$tablepre}threads SET attachment='$tattachment' $viewpermadd WHERE tid='$tid'");
} elseif($viewpermadd) {
$db->query("UPDATE {$tablepre}threads SET ".substr($viewpermadd, 2)." WHERE tid='$tid'", 'UNBUFFERED');
}
$db->query("UPDATE {$tablepre}posts SET message='$message', usesig='$usesig', htmlon='$htmlon', bbcodeoff='$bbcodeoff', parseurloff='$parseurloff', smileyoff='$smileyoff', subject='$subject'
".($pattachment ? ", attachment='1'" : '')." WHERE pid='$pid'");
if(!$isorigauthor) {
require_once DISCUZ_ROOT.'./include/misc.func.php';
modlog($thread, 'EDT');
}
} else {
if(!$isorigauthor || ($isfirstpost && $thread['replies'] >= 1)) {
showmessage('post_edit_nopermission', NULL, 'HALTED');
}
updatemember('-', $orig['authorid'], $deletedcredits);
$thread_attachment = $post_attachment = 0;
$query = $db->query("SELECT pid, attachment FROM {$tablepre}attachments WHERE tid='$tid'");
while($attach = $db->fetch_array($query)) {
if($attach['pid'] == $pid) {
$post_attachment = 1;
@unlink($attachdir.'/'.$attach['attachment']);
} else {
$thread_attachment = 1;
}
}
if($post_attachment) {
$db->query("DELETE FROM {$tablepre}attachments WHERE pid='$pid'", 'UNBUFFEREED');
}
$db->query("DELETE FROM {$tablepre}posts WHERE pid='$pid'");
if($isfirstpost) {
$db->query("DELETE FROM {$tablepre}threadsmod WHERE tid='$tid'", 'UNBUFFERED');
$db->query("DELETE FROM {$tablepre}threads WHERE tid='$tid'", 'UNBUFFERED');
$db->query("UPDATE {$tablepre}forums SET threads=threads-1, posts=posts-1 WHERE fid='$fid'", 'UNBUFFERED');
} else {
$query = $db->query("SELECT author, dateline FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0' ORDER BY dateline DESC LIMIT 1");
$lastpost = $db->fetch_array($query);
$lastpost['author'] = addslashes($lastpost['author']);
$db->query("UPDATE {$tablepre}threads SET replies=replies-1, attachment='$thread_attachment', lastposter='$lastpost[author]', lastpost='$lastpost[dateline]' WHERE tid='$tid'", 'UNBUFFERED');
$db->query("UPDATE {$tablepre}forums SET posts=posts-1 WHERE fid='$fid'", 'UNBUFFERED');
}
}
($delete && $isfirstpost) ? showmessage('post_edit_delete_succeed', "forumdisplay.php?fid=$fid") :
showmessage('post_edit_succeed', "viewthread.php?tid=$tid&page=$page#pid$pid");
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?