Files
web-discuz/source/plugin/replyfloor/index.inc.php
2025-06-27 21:04:18 +08:00

418 lines
16 KiB
PHP

<?php
/**
* This is NOT a freeware, use is subject to license terms
* 应用名称: 贴吧楼中楼回复 9.0
* 下载地址: https://addon.dismall.com/plugins/replyfloor.html
* 应用开发者: 乘凉
* 开发者QQ: 594433766
* 更新日期: 202505310549
* 授权域名: www.shitangsweet.com
* 授权码: 2025053105b89RrI3R9n
* 未经应用程序开发者/所有者的书面许可,不得进行反向工程、反向汇编、反向编译等,不得擅自复制、修改、链接、转载、汇编、发表、出版、发展与之有关的衍生产品、作品等
*/
/**
* $author: 乘凉 $
*/
if (!defined('IN_DISCUZ')) {
exit('Access Denied');
}
require_once libfile('function/common', 'plugin/replyfloor');
$setconfig = $_G['cache']['plugin'][CURMODULE];
$setconfig['open_seccheck'] = (array)unserialize($setconfig['open_seccheck']);
$setconfig['audit_users'] = (array)unserialize($setconfig['audit_users']);
$ac = in_array($_GET['ac'], array('index', 'post', 'delete', 'report')) ? $_GET['ac'] : 'index';
require_once libfile('function/forum');
loadforum();
$thread = $_G['thread'];
if(!$thread || $thread['displayorder'] < 0) {
showmessage('thread_nonexistence');
}
$post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $_GET['pid']);
if(!$post['tid']) {
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_post_nonexistence'));
}
if($post['tid'] != $_G['tid']) {
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_post_error'));
}
if($ac == 'index') {
$_G['setting']['dateconvert'] = $setconfig['date_convert'];
$msgid = intval($_GET['msgid']);
if($msgid) {
$msginfo = C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->fetch_by_id($msgid);
if(!$msginfo) {
showmessage(lang('plugin/'.CURMODULE, 'message_nonexistence'));
}
$msginfo['message'] = replyfloor_discuzcode($msginfo['message']);
if($setconfig['show_br']) {
$msginfo['message'] = nl2br($msginfo['message']);
}
if($setconfig['show_location']) {
$msginfo['location'] = replyfloor_location($msginfo['postip']);
}else{
$msginfo['location'] = '';
}
$msginfo['createtime'] = $setconfig['date_convert'] ? dgmdate($msginfo['createtime'], 'u', 9999, $setconfig['time_format']) : dgmdate($msginfo['createtime'], $setconfig['time_format']);
if(file_exists(DISCUZ_ROOT.'./source/plugin/'.CURMODULE.'/extend/extend_hidenum.php')){
require_once libfile('extend/hidenum', 'plugin/replyfloor');
$msginfo['message'] = replyfloor_extend_hidenum($msginfo['message']);
}
$uids = array();
$uids[] = $msginfo['uid'];
if($msginfo['ruid']){
$uids[] = $msginfo['ruid'];
}
if($uids) {
loadcache('usergroups');
foreach(C::t('common_member')->fetch_all($uids) as $uid => $postuser) {
if($msginfo['uid'] == $uid) {
$msginfo['groupcolor'] = $_G['cache']['usergroups'][$postuser['groupid']]['color'];
}
if($msginfo['ruid'] == $uid) {
$msginfo['rgroupcolor'] = $_G['cache']['usergroups'][$postuser['groupid']]['color'];
}
}
}
}else{
$page = max(1, $_G['page']);
if(defined('IN_MOBILE')) {
$shownum = $setconfig['shownum_mobile'] > 0 ? $setconfig['shownum_mobile'] : 5;
$perpage = $setconfig['perpage_mobile'] > 0 ? $setconfig['perpage_mobile'] : 10;
}else{
$shownum = $setconfig['shownum_pc'] > 0 ? $setconfig['shownum_pc'] : 5;
$perpage = $setconfig['perpage_pc'] > 0 ? $setconfig['perpage_pc'] : 10;
}
$start = ($page-1)*$perpage;
if((!defined('IN_MOBILE') && $setconfig['pagemode_pc']) || (defined('IN_MOBILE') && $setconfig['pagemode_mobile'])){
if($page == 1){
$perpage = $shownum;
}else{
$start = ($page-2)*$perpage + $shownum;
}
}
$mpurl = 'plugin.php?id='.CURMODULE.':index&tid='.$post['tid'].'&pid='.$post['pid'].($_GET['ordertype'] ? '&ordertype='.$_GET['ordertype'] : '');
$wherearr = array();
if($_G['uid']){
$wherearr[] = "(status = '0' or (status = '-1' and uid = '".$_G['uid']."'))";
}else{
$wherearr[] = "status = '0'";
}
$wherearr[] = "pid = '".$post['pid']."'";
$count = C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->count_by_search_where($wherearr);
if(!$setconfig['order_type']){
$setconfig['order_type'] = empty($_GET['ordertype']) && getstatus($thread['status'], 4) ? 1 : intval($_GET['ordertype']);
}
$orderby = 'order by createtime desc';
if($setconfig['order_type'] == 2){
$orderby = 'order by createtime asc';
}
$list = C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->fetch_all_by_search_where($wherearr, $orderby, $start, $perpage);
$uids = array();
foreach ($list as $key => $value) {
$value['message'] = replyfloor_discuzcode($value['message']);
if($setconfig['show_br']) {
$value['message'] = nl2br($value['message']);
}
if($setconfig['show_location']) {
$value['location'] = replyfloor_location($value['postip']);
}else{
$value['location'] = '';
}
$value['createtime'] = $setconfig['date_convert'] ? dgmdate($value['createtime'], 'u', 9999, $setconfig['time_format']) : dgmdate($value['createtime'], $setconfig['time_format']);
$list[$key] = $value;
$uids[] = $value['uid'];
if($value['ruid']){
$uids[] = $value['ruid'];
}
}
if(defined('IN_MOBILE')) {
$multipage = multi($count, $perpage, $page, $mpurl, 0, 3, false, true);
}else{
$multipage = multi($count, $perpage, $page, $mpurl);
}
if(file_exists(DISCUZ_ROOT.'./source/plugin/'.CURMODULE.'/extend/extend_hidenum.php')){
require_once libfile('extend/hidenum', 'plugin/replyfloor');
foreach ($list as $key => $value) {
$value['message'] = replyfloor_extend_hidenum($value['message']);
$list[$key] = $value;
}
}
if($uids) {
loadcache('usergroups');
foreach(C::t('common_member')->fetch_all($uids) as $uid => $postuser) {
foreach ($list as $key => $value) {
if($value['uid'] == $uid) {
$value['groupcolor'] = $_G['cache']['usergroups'][$postuser['groupid']]['color'];
}
if($value['ruid'] == $uid) {
$value['rgroupcolor'] = $_G['cache']['usergroups'][$postuser['groupid']]['color'];
}
$list[$key] = $value;
}
}
}
}
include template(CURMODULE.':message');
} elseif($ac == 'post') {
if(empty($_G['uid'])) {
showmessage('to_login', '', array(), array('showmsg' => true));
}
//新手回复见习期
cknewuser();
require_once libfile('function/post');
require_once libfile('function/forumlist');
$allowpostreply = ($_G['forum']['allowreply'] != -1) && (($_G['forum_thread']['isgroup'] || (!$_G['forum_thread']['closed'] && !checkautoclose($_G['forum_thread']))) || $_G['forum']['ismoderator']) && ((!$_G['forum']['replyperm'] && $_G['group']['allowreply']) || ($_G['forum']['replyperm'] && forumperm($_G['forum']['replyperm'])) || $_G['forum']['allowreply']);
if(!$allowpostreply) {
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_no_permission_to_post'));
}
$ruid = 0;
$rusername = '';
$_GET['msgid'] = intval($_GET['msgid']);
if($_GET['msgid']) {
$remsg = C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->fetch_by_id($_GET['msgid']);
if($remsg) {
$ruid = $remsg['uid'];
$rusername = $remsg['username'];
}
}
$seccodecheck = in_array($_G['groupid'], $setconfig['open_seccheck']) ? 1 : 0;
if(submitcheck('savesubmit', 0, $seccodecheck)) {
if(file_exists(DISCUZ_ROOT.'./source/plugin/allowreply/extend/extend_replyfloor.php')){
@include_once libfile('extend/replyfloor', 'plugin/allowreply');
}
$message = isset($_GET['message']) ? censor($_GET['message']) : '';
$attach = isset($_GET['attach']) ? $_GET['attach'] : array();
//$message = messagecutstr($message, 200, '');
if(strlen(preg_replace("/[\r\n]{1,2}/", "\n", $message)) < $setconfig['message_minsize']) {
showmessage(lang('plugin/'.CURMODULE, 'message_message_tooshort'), '', array('message_minsize' => $setconfig['message_minsize']));
}
if(strlen(preg_replace("/[\r\n]{1,2}/", "\n", $message)) > $setconfig['message_maxsize']) {
showmessage(lang('plugin/'.CURMODULE, 'message_message_toolong'), '', array('message_maxsize' => $setconfig['message_maxsize']));
}
//两次发表时间间隔
if(checkflood()) {
showmessage('post_flood_ctrl', '', array('floodctrl' => $_G['setting']['floodctrl']));
}
$modnewreplies = 0;
if($setconfig['moderate_reply'] == 1) {
list(, $modnewreplies) = threadmodstatus($message);
}elseif($setconfig['moderate_reply'] == 2) {
if(in_array($_G['groupid'], $setconfig['audit_users'])) {
$modnewreplies = 1;
}
}
$attachment = $usedattach = $queryattach = array();
if($attach){
$queryattach = C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment_unused')->fetch_all_by_id($attach);
foreach($attach as $aid){
if($queryattach[$aid]){
$usedattach[] = $queryattach[$aid];
if(in_array($queryattach[$aid]['fileext'], array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'webp'))){
$attachment[] = ($queryattach[$aid]['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'replyfloor/'. $queryattach[$aid]['attachment'];
}
}
}
}
if(empty($message) && empty($attachment)) {
showmessage(lang('plugin/'.CURMODULE, 'message_message_empty'));
}
if(discuz_process::islocked("replyfloor_post_".$_G['uid'], 600)) {
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_request_error'));
}
$data = array(
'tid' => $post['tid'],
'pid' => $post['pid'],
'uid' => $_G['uid'],
'username' => $_G['username'],
'ruid' => $ruid,
'rusername' => $rusername,
'message' => $message,
'attachment' => implode("\t", $attachment),
'mobile' => defined('IN_MOBILE') ? IN_MOBILE : 0,
'createtime' => $_G['timestamp'],
'postip' => $_G['clientip'],
'status' => $modnewreplies ? -1 : 0,
);
$msgid = C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->insert($data, true);
$i = 1;
foreach($usedattach as $value){
$displayorder = in_array($value['fileext'], array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'webp')) ? $i : 0;
$attachdata = array(
'id' => $value['id'],
'displayorder' => $displayorder,
'tid' => $post['tid'],
'pid' => $post['pid'],
'msgid' => $msgid,
'uid' => $value['uid'],
'username' => $value['username'],
'filename' => $value['filename'],
'filesize' => $value['filesize'],
'fileext' => $value['fileext'],
'attachment' => $value['attachment'],
'remote' => $value['remote'],
'width' => $value['width'],
'height' => $value['height'],
'dateline' => $value['dateline'],
);
C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment')->insert($attachdata, false, true);
C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment_unused')->delete_by_id($value['id']);
$i++;
}
//更新帖子回复数
//C::t('forum_thread')->increase($_G['tid'], array('replies' => 1));
//更新版块帖子数
//C::t('forum_forum')->update_forum_counter($_G['fid'], 0, 1);
//更新今日帖子数
if($setconfig['today_posts']) {
C::t('forum_forum')->update_forum_counter($_G['fid'], 0, 0, 1);
}
//增加主题热度
if($setconfig['open_heatthread']) {
update_threadpartake($_G['tid']);
}
discuz_process::unlock("replyfloor_post_".$_G['uid']);
if($modnewreplies) {
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_post_mod_succeed'), dreferer(), array('tid' => $post['tid'], 'pid' => $post['pid'], 'msgid' => $msgid));
}
if($setconfig['get_credit']) {
updatepostcredits('+', $_G['uid'], 'reply', $_G['fid']);
}
if($setconfig['thread_bump']) {
$expiration = $_G['timestamp'];
if($thread['lastpost'] < $expiration){
C::t('forum_thread')->update($thread['tid'], array('lastpost'=>$expiration, 'lastposter'=>$_G['username']), true);
}else{
C::t('forum_thread')->update($thread['tid'], array('lastposter'=>$_G['username']), true);
}
C::t('forum_forum')->update($_G['fid'], array('lastpost' => "$thread[tid]\t$thread[subject]\t$expiration\t$_G[username]"));
$_G['forum']['threadcaches'] && deletethreadcaches($thread['tid']);
}
if($setconfig['notice_author'] == 1 || ($setconfig['notice_author'] == 2 && $_GET['notice_author'])) {
$nauthorid = $ruid ? $ruid : $post['authorid'];
if($nauthorid != $_G['uid']){
notification_add($nauthorid, 'post', 'replyfloor:replyfloor_noticeauthor', array(
'tid' => $thread['tid'],
'subject' => $thread['subject'],
'fid' => $_G['fid'],
'pid' => $post['pid'],
'from_id' => $post['tid'],
'from_idtype' => 'post',
));
}
}
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_post_succeed'), dreferer(), array('tid' => $post['tid'], 'pid' => $post['pid'], 'msgid' => $msgid));
} else {
include template(CURMODULE.':post');
}
} elseif($ac == 'delete') {
if(empty($_G['uid'])) {
showmessage('to_login', '', array(), array('showmsg' => true, 'login' => 1));
}
$msgid = intval($_GET['msgid']);
if(!$msgid) {
showmessage(lang('plugin/'.CURMODULE, 'message_nonexistence'));
}
$msginfo = C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->fetch_by_id($msgid);
if(!$msginfo) {
showmessage(lang('plugin/'.CURMODULE, 'message_nonexistence'));
}
if(!($_G['forum']['ismoderator'] && $_G['group']['allowdelpost']) && !($setconfig['allow_delete'] && $_G['uid'] && $_G['uid'] == $_G['thread']['authorid']) && !($setconfig['self_delete'] && $_G['uid'] && $_G['uid'] == $msginfo['uid'])){
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_no_permission'));
}
require_once libfile('function/misc');
if(submitcheck('modsubmit')) {
if($setconfig['get_credit']) {
require_once libfile('function/post');
updatepostcredits('-', $msginfo['uid'], 'reply', $_G['fid']);
}
replyfloor_deletemessage(array($msgid), 'id', $setconfig['open_recycle']);
$wherearr = array();
$wherearr[] = "status = '0'";
$wherearr[] = "pid = '".$post['pid']."'";
$count = C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->count_by_search_where($wherearr);
showmessage('', dreferer(), array('tid' => $post['tid'], 'pid' => $post['pid'], 'count' => $count));
} else {
include template(CURMODULE.':delete');
}
} elseif($ac == 'report') {
if(empty($_G['uid'])) {
showmessage('to_login', '', array(), array('showmsg' => true, 'login' => 1));
}
$msgid = intval($_GET['msgid']);
if(!$msgid) {
showmessage(lang('plugin/'.CURMODULE, 'message_nonexistence'));
}
$msginfo = C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->fetch_by_id($msgid);
if(!$msginfo) {
showmessage(lang('plugin/'.CURMODULE, 'message_nonexistence'));
}
if(submitcheck('savesubmit')) {
$message = trim($_GET['message']);
if(empty($message)) {
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_report_message'));
}
require_once libfile('class/upload', 'plugin/'.CURMODULE);
$upload = new discuz_upload();
$images = array();
$filelist = $_FILES['filedata'];
for ($i=0;$i<count($filelist["name"]);$i++) {
$filedata = array("tmp_name" => $filelist["tmp_name"][$i], "name" => $filelist["name"][$i], "size" => $filelist["size"][$i], "type" => $filelist["type"][$i]);
$upres = $upload->init($filedata, CURMODULE);
if($upres && $upload->attach['isimage'] && $upload->save()) {
$images[] = array("name" => $upload->attach['name'], "image" => $upload->attach['attachment']);
}
}
$data = array(
'uid' => $_G['uid'],
'username' => $_G['username'],
'msgid' => $msginfo['id'],
'message' => dhtmlspecialchars($message),
'images' => serialize($images),
'createtime' => $_G['timestamp'],
'postip' => $_G['clientip'],
);
C::t('#'.CURMODULE.'#'.CURMODULE.'_report')->insert($data);
C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->update_reportnum($msginfo['id']);
//接受提醒
if($setconfig['report_remind']){
foreach(explode(',', $setconfig['report_remind']) as $userid){
if(preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $userid)){
require_once libfile('function/mail');
$res = sendmail($userid, lang('plugin/'.CURMODULE, 'replyfloor_newreport_title'), lang('plugin/'.CURMODULE, 'replyfloor_newreport_message'));
}elseif(is_numeric($userid)){
notification_add($userid, 'report', 'replyfloor:replyfloor_newreport_notice', array('from_id' => 1, 'from_idtype' => 'newreport', 'username' => $_G['username']), 1);
}else{
$getuser = C::t('common_member')->fetch_by_username($userid, 1);
if($getuser){
notification_add($getuser['uid'], 'report', 'replyfloor:replyfloor_newreport_notice', array('from_id' => 1, 'from_idtype' => 'newreport', 'username' => $_G['username']), 1);
}
}
}
}
showmessage(lang('plugin/'.CURMODULE, 'replyfloor_report_succeed'), dreferer(), array(), array('closetime' => true, 'showdialog' => 1, 'alert' => 'right'));
} else {
$navtitle = lang('plugin/'.CURMODULE, 'replyfloor_navtitle_report');
include template(CURMODULE.':report');
}
}