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

444 lines
18 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');
}
class plugin_replyfloor {
public static $identifier = 'replyfloor';
function __construct() {
global $_G;
$setconfig = $_G['cache']['plugin'][self::$identifier];
$setconfig['allow_forums'] = (array)unserialize($setconfig['allow_forums']);
if(in_array('', $setconfig['allow_forums'])) {
$setconfig['allow_forums'] = array();
}
$setconfig['allow_groups'] = $setconfig['allow_groups'] ? explode(",", $setconfig['allow_groups']) : array();
$setconfig['open_seccheck'] = (array)unserialize($setconfig['open_seccheck']);
$setconfig['perpage_pc'] = $setconfig['perpage_pc'] > 0 ? $setconfig['perpage_pc'] : 10;
$this->setconfig = $setconfig;
}
function deletethread($value) {
global $_G;
$setconfig = $this->setconfig;
if($value['step'] == 'delete'){
list($tids, $membercount, $credit, $ponly) = $value['param'];
require_once libfile('function/common', 'plugin/replyfloor');
if($setconfig['get_credit']) {
require_once libfile('function/post');
require_once libfile('function/forum');
$wherearr = array();
$wherearr[] = 'tid in ('.dimplode($tids).')';
$wherearr[] = "status = '0'";
$recordlist = DB::fetch_all('SELECT * FROM '.DB::table('plugin_replyfloor_message').($wherearr ? ' WHERE '.implode(' AND ', $wherearr) : ''));
foreach ($recordlist as $value) {
$thread = get_thread_by_tid($value['tid']);
updatepostcredits('-', $value['uid'], 'reply', $thread['fid']);
}
}
replyfloor_deletemessage($ids, 'tid', $setconfig['open_recycle']);
}
}
function deletepost($value) {
global $_G;
$setconfig = $this->setconfig;
if($value['step'] == 'delete'){
list($ids, $idtype, $credit, $posttableid, $recycle) = $value['param'];
require_once libfile('function/common', 'plugin/replyfloor');
if($idtype == 'pid') {
if($setconfig['get_credit']) {
require_once libfile('function/post');
require_once libfile('function/forum');
$wherearr = array();
$wherearr[] = 'pid in ('.dimplode($ids).')';
$wherearr[] = "status = '0'";
$recordlist = DB::fetch_all('SELECT * FROM '.DB::table('plugin_replyfloor_message').($wherearr ? ' WHERE '.implode(' AND ', $wherearr) : ''));
foreach ($recordlist as $value) {
$thread = get_thread_by_tid($value['tid']);
updatepostcredits('-', $value['uid'], 'reply', $thread['fid']);
}
}
replyfloor_deletemessage($ids, 'pid', $setconfig['open_recycle']);
} elseif($idtype == 'tid') {
if($setconfig['get_credit']) {
require_once libfile('function/post');
require_once libfile('function_forum', 'function');
$wherearr = array();
$wherearr[] = 'tid in ('.dimplode($ids).')';
$wherearr[] = "status = '0'";
$recordlist = DB::fetch_all('SELECT * FROM '.DB::table('plugin_replyfloor_message').($wherearr ? ' WHERE '.implode(' AND ', $wherearr) : ''));
foreach ($recordlist as $value) {
$thread = get_thread_by_tid($value['tid']);
updatepostcredits('-', $value['uid'], 'reply', $thread['fid']);
}
}
replyfloor_deletemessage($ids, 'tid', $setconfig['open_recycle']);
} elseif($idtype == 'authorid') {
if($setconfig['get_credit']) {
require_once libfile('function/post');
require_once libfile('function_forum', 'function');
$wherearr = array();
$wherearr[] = 'uid in ('.dimplode($ids).')';
$wherearr[] = "status = '0'";
$recordlist = DB::fetch_all('SELECT * FROM '.DB::table('plugin_replyfloor_message').($wherearr ? ' WHERE '.implode(' AND ', $wherearr) : ''));
foreach ($recordlist as $value) {
$thread = get_thread_by_tid($value['tid']);
updatepostcredits('-', $value['uid'], 'reply', $thread['fid']);
}
}
replyfloor_deletemessage($ids, 'authorid', $setconfig['open_recycle']);
}
}
}
}
class plugin_replyfloor_forum extends plugin_replyfloor {
function forumdisplay_top_output() {
global $_G;
$return = '';
$setconfig = $this->setconfig;
if($setconfig['allow_forums'] && !in_array($_G['fid'], $setconfig['allow_forums'])){
return $return;
}
if($setconfig['add_replies']){
$tids = array();
foreach ($_G['forum_threadlist'] as $key => $value) {
$tids[] = $value['tid'];
}
if(empty($tids)){
return $return;
}
$wherearr = array();
$wherearr[] = 'tid in ('.dimplode($tids).')';
$wherearr[] = "status = '0'";
$recordlist = DB::fetch_all('SELECT tid,count(*) as count FROM '.DB::table('plugin_replyfloor_message').($wherearr ? ' WHERE '.implode(' AND ', $wherearr) : '').' group by tid');
$count = array();
foreach ($recordlist as $value) {
$count[$value['tid']] = $value['count'];
}
foreach ($_G['forum_threadlist'] as &$thread) {
if($count[$thread['tid']]){
$thread['allreplies'] += $count[$thread['tid']];
$thread['replies'] += $count[$thread['tid']];
}
}
}
return $return;
}
function viewthread_top_output() {
global $_G,$allowpostreply;
$setconfig = $this->setconfig;
if(($setconfig['position_pc'] > 0) && (!$setconfig['allow_forums'] || in_array($_G['fid'], $setconfig['allow_forums']))){
if($setconfig['add_replies']){
$_G['forum_thread']['allreplies'] += C::t('#'.self::$identifier.'#'.self::$identifier.'_message')->count_by_search_where(array("tid = '".$_G['tid']."'", "status = '0'"));
}
include template(self::$identifier.':style');
}
return $return;
}
function viewthread_bottom_output() {
global $_G,$allowpostreply, $swfconfig;
$setconfig = $this->setconfig;
if(($setconfig['position_pc'] > 0) && (!$setconfig['allow_forums'] || in_array($_G['fid'], $setconfig['allow_forums']))){
include template(self::$identifier.':js');
}
if($setconfig['replace_pc'] == 1){
if(!$_G['setting']['rewritestatus']){
$_G['setting']['rewritestatus'] = array();
}elseif(!is_array($_G['setting']['rewritestatus'])){
$_G['setting']['rewritestatus'] = array($_G['setting']['rewritestatus']);
}
$_G['setting']['rewritestatus'][] = 'replyfloor_reply';
$_G['setting']['output']['str']['search']['replyfloor'] = "showWindow('reply', this.href)";
$_G['setting']['output']['str']['replace']['replyfloor'] = "replyfloor_reply(this.href)";
}
return $return;
}
function viewthread_postbottom_output() {
global $_G,$postlist,$postno,$postnostick,$allowpostreply;
$setconfig = $this->setconfig;
$t = $pids = array();
if($_G['inajax'] && (empty($_GET['viewpid']) || ($_GET['viewpid'] && $_GET['from']))){
return $t;
}
if(($setconfig['position_pc'] == 1 || $setconfig['position_pc'] == 2) && (!$setconfig['allow_forums'] || in_array($_G['fid'], $setconfig['allow_forums']))){
foreach($postlist as $key => $post) {
if(!$post['first'] || $setconfig['thread_reply']){
$pids[] = $post['pid'];
}
}
if($pids){
if(!$setconfig['order_type']){
$setconfig['order_type'] = empty($_GET['ordertype']) && getstatus($_G['forum_thread']['status'], 4) ? 1 : intval($_GET['ordertype']);
}
$orderby = 'order by createtime desc';
if($setconfig['order_type'] == 2){
$orderby = 'order by createtime asc';
}
$messageinfo = C::t('#'.self::$identifier.'#'.self::$identifier.'_message')->fetch_message_by_pid($pids, $setconfig['perpage_pc'], $orderby, $setconfig);
foreach($postlist as $key => $post) {
if($post['first'] && !$setconfig['thread_reply']){
$t[] = '';
}else{
$count = $messageinfo[$post['pid']]['count'] ? $messageinfo[$post['pid']]['count'] : 0;
$list = $messageinfo[$post['pid']]['list'];
$_GET['ajaxtarget'] = 'replyfloor_content_'.$post['pid'];
$multipage = multi($count, $setconfig['perpage_pc'], 1, 'plugin.php?id=replyfloor:index&tid='.$post['tid'].'&pid='.$post['pid'].($_GET['ordertype'] ? '&ordertype='.$_GET['ordertype'] : ''));
$_GET['ajaxtarget'] = '';
include template(self::$identifier.':viewthread');
if($setconfig['position_pc'] == 1){
$post['message'] .= $return;
$postlist[$key] = $post;
}else{
$t[] = $return;
}
}
}
}
}
return $t;
}
function viewthread_replyfloor_output() {
global $_G,$postlist,$postno,$postnostick,$allowpostreply;
$setconfig = $this->setconfig;
$t = $pids = array();
if($_G['inajax'] && (empty($_GET['viewpid']) || ($_GET['viewpid'] && $_GET['from']))){
return $t;
}
if(($setconfig['position_pc'] == 3) && (!$setconfig['allow_forums'] || in_array($_G['fid'], $setconfig['allow_forums']))){
foreach($postlist as $key => $post) {
if(!$post['first'] || $setconfig['thread_reply']){
$pids[] = $post['pid'];
}
}
if($pids){
if(!$setconfig['order_type']){
$setconfig['order_type'] = empty($_GET['ordertype']) && getstatus($_G['forum_thread']['status'], 4) ? 1 : intval($_GET['ordertype']);
}
$orderby = 'order by createtime desc';
if($setconfig['order_type'] == 2){
$orderby = 'order by createtime asc';
}
$messageinfo = C::t('#'.self::$identifier.'#'.self::$identifier.'_message')->fetch_message_by_pid($pids, $setconfig['perpage_pc'], $orderby, $setconfig);
foreach($postlist as $key => $post) {
if($post['first'] && !$setconfig['thread_reply']){
$t[] = '';
}else{
$count = $messageinfo[$post['pid']]['count'] ? $messageinfo[$post['pid']]['count'] : 0;
$list = $messageinfo[$post['pid']]['list'];
$_GET['ajaxtarget'] = 'replyfloor_content_'.$post['pid'];
$multipage = multi($count, $setconfig['perpage_pc'], 1, 'plugin.php?id=replyfloor:index&tid='.$post['tid'].'&pid='.$post['pid'].($_GET['ordertype'] ? '&ordertype='.$_GET['ordertype'] : ''));
$_GET['ajaxtarget'] = '';
include template(self::$identifier.':viewthread');
$t[] = $return;
}
}
}
}
return $t;
}
}
class plugin_replyfloor_group extends plugin_replyfloor {
function forumdisplay_top_output() {
global $_G;
$return = '';
$setconfig = $this->setconfig;
if($setconfig['allow_groups'] && !$this->_allow_groups($_G['forum'], $setconfig['allow_groups'])){
return $return;
}
if($setconfig['add_replies']){
$tids = array();
foreach ($_G['forum_threadlist'] as $key => $value) {
$tids[] = $value['tid'];
}
if(empty($tids)){
return $return;
}
$wherearr = array();
$wherearr[] = 'tid in ('.dimplode($tids).')';
$wherearr[] = "status = '0'";
$recordlist = DB::fetch_all('SELECT tid,count(*) as count FROM '.DB::table('plugin_replyfloor_message').($wherearr ? ' WHERE '.implode(' AND ', $wherearr) : '').' group by tid');
$count = array();
foreach ($recordlist as $value) {
$count[$value['tid']] = $value['count'];
}
foreach ($_G['forum_threadlist'] as &$thread) {
if($count[$thread['tid']]){
$thread['allreplies'] += $count[$thread['tid']];
}
}
}
return $return;
}
function viewthread_top_output() {
global $_G,$allowpostreply;
$setconfig = $this->setconfig;
if(($setconfig['position_pc'] > 0) && (!$setconfig['allow_groups'] || $this->_allow_groups($_G['forum'], $setconfig['allow_groups']))){
if($setconfig['add_replies']){
$_G['forum_thread']['allreplies'] += C::t('#'.self::$identifier.'#'.self::$identifier.'_message')->count_by_search_where(array("tid = '".$_G['tid']."'", "status = '0'"));
}
include template(self::$identifier.':style');
}
return $return;
}
function viewthread_bottom_output() {
global $_G,$allowpostreply, $swfconfig;
$setconfig = $this->setconfig;
if(($setconfig['position_pc'] > 0) && (!$setconfig['allow_groups'] || $this->_allow_groups($_G['forum'], $setconfig['allow_groups']))){
include template(self::$identifier.':js');
}
if($setconfig['replace_pc'] == 1){
if(!$_G['setting']['rewritestatus']){
$_G['setting']['rewritestatus'] = array();
}elseif(!is_array($_G['setting']['rewritestatus'])){
$_G['setting']['rewritestatus'] = array($_G['setting']['rewritestatus']);
}
$_G['setting']['rewritestatus'][] = 'replyfloor_reply';
$_G['setting']['output']['str']['search']['replyfloor'] = "showWindow('reply', this.href)";
$_G['setting']['output']['str']['replace']['replyfloor'] = "replyfloor_reply(this.href)";
}
return $return;
}
function viewthread_postbottom_output() {
global $_G,$postlist,$postno,$postnostick,$allowpostreply;
$setconfig = $this->setconfig;
$t = $pids = array();
if($_G['inajax'] && (empty($_GET['viewpid']) || ($_GET['viewpid'] && $_GET['from']))){
return $t;
}
if(($setconfig['position_pc'] == 1 || $setconfig['position_pc'] == 2) && (!$setconfig['allow_groups'] || $this->_allow_groups($_G['forum'], $setconfig['allow_groups']))){
foreach($postlist as $key => $post) {
if(!$post['first'] || $setconfig['thread_reply']){
$pids[] = $post['pid'];
}
}
if($pids){
if(!$setconfig['order_type']){
$setconfig['order_type'] = empty($_GET['ordertype']) && getstatus($_G['forum_thread']['status'], 4) ? 1 : intval($_GET['ordertype']);
}
$orderby = 'order by createtime desc';
if($setconfig['order_type'] == 2){
$orderby = 'order by createtime asc';
}
$messageinfo = C::t('#'.self::$identifier.'#'.self::$identifier.'_message')->fetch_message_by_pid($pids, $setconfig['perpage_pc'], $orderby, $setconfig);
foreach($postlist as $key => $post) {
if($post['first'] && !$setconfig['thread_reply']){
$t[] = '';
}else{
$count = $messageinfo[$post['pid']]['count'] ? $messageinfo[$post['pid']]['count'] : 0;
$list = $messageinfo[$post['pid']]['list'];
$_GET['ajaxtarget'] = 'replyfloor_content_'.$post['pid'];
$multipage = multi($count, $setconfig['perpage_pc'], 1, 'plugin.php?id=replyfloor:index&tid='.$post['tid'].'&pid='.$post['pid'].($_GET['ordertype'] ? '&ordertype='.$_GET['ordertype'] : ''));
$_GET['ajaxtarget'] = '';
include template(self::$identifier.':viewthread');
if($setconfig['position_pc'] == 1){
$post['message'] .= $return;
$postlist[$key] = $post;
}else{
$t[] = $return;
}
}
}
}
}
return $t;
}
function viewthread_replyfloor_output() {
global $_G,$postlist,$postno,$postnostick,$allowpostreply;
$setconfig = $this->setconfig;
$t = $pids = array();
if($_G['inajax'] && (empty($_GET['viewpid']) || ($_GET['viewpid'] && $_GET['from']))){
return $t;
}
if(($setconfig['position_pc'] == 3) && (!$setconfig['allow_groups'] || $this->_allow_groups($_G['forum'], $setconfig['allow_groups']))){
foreach($postlist as $key => $post) {
if(!$post['first'] || $setconfig['thread_reply']){
$pids[] = $post['pid'];
}
}
if($pids){
if(!$setconfig['order_type']){
$setconfig['order_type'] = empty($_GET['ordertype']) && getstatus($_G['forum_thread']['status'], 4) ? 1 : intval($_GET['ordertype']);
}
$orderby = 'order by createtime desc';
if($setconfig['order_type'] == 2){
$orderby = 'order by createtime asc';
}
$messageinfo = C::t('#'.self::$identifier.'#'.self::$identifier.'_message')->fetch_message_by_pid($pids, $setconfig['perpage_pc'], $orderby, $setconfig);
foreach($postlist as $key => $post) {
if($post['first'] && !$setconfig['thread_reply']){
$t[] = '';
}else{
$count = $messageinfo[$post['pid']]['count'] ? $messageinfo[$post['pid']]['count'] : 0;
$list = $messageinfo[$post['pid']]['list'];
$_GET['ajaxtarget'] = 'replyfloor_content_'.$post['pid'];
$multipage = multi($count, $setconfig['perpage_pc'], 1, 'plugin.php?id=replyfloor:index&tid='.$post['tid'].'&pid='.$post['pid'].($_GET['ordertype'] ? '&ordertype='.$_GET['ordertype'] : ''));
$_GET['ajaxtarget'] = '';
include template(self::$identifier.':viewthread');
$t[] = $return;
}
}
}
}
return $t;
}
function _allow_groups($forum, $groupids) {
global $_G;
if(empty($forum) || empty($forum['fid']) || empty($forum['name'])) {
return false;
}
loadcache('grouptype');
$groupsecond = $_G['cache']['grouptype']['second'];
if($forum['type'] == 'sub') {
$secondtype = !empty($groupsecond[$forum['fup']]) ? $groupsecond[$forum['fup']] : array();
} else {
$secondtype = !empty($groupsecond[$forum['fid']]) ? $groupsecond[$forum['fid']] : array();
}
$firstid = !empty($secondtype) ? $secondtype['fup'] : (!empty($forum['fup']) ? $forum['fup'] : $forum['fid']);
$firsttype = $_G['cache']['grouptype']['first'][$firstid];
if($firsttype && in_array($firsttype['fid'], $groupids)) {
return true;
}
if($secondtype && in_array($secondtype['fid'], $groupids)) {
return true;
}
return false;
}
}
?>