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

114 lines
3.5 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 ReplyFloorAPI {
public static $identifier = 'replyfloor';
function __construct() {
global $_G;
if(empty($_G['cache']['plugin'][self::$identifier])){
loadcache('plugin');
}
$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 forumdisplay_variables(&$variables) {
global $_G;
$setconfig = $this->setconfig;
if($setconfig['allow_forums'] && !in_array($variables['fid'], $setconfig['allow_forums'])){
return;
}
if($setconfig['add_replies']){
$tids = array();
foreach ($variables['forum_threadlist'] as &$thread) {
$tids[] = $thread['tid'];
}
if(empty($tids)){
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 ($variables['forum_threadlist'] as &$thread) {
if($count[$thread['tid']]){
$thread['replies'] += $count[$thread['tid']];
}
}
}
}
function viewthread_variables(&$variables) {
global $_G;
$setconfig = $this->setconfig;
if($setconfig['allow_forums'] && !in_array($variables['fid'], $setconfig['allow_forums'])){
return;
}
if(empty($_GET['viewpid'])) {
$pids = array();
foreach($variables['postlist'] as $post) {
if(!$post['first']){
$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.'#replyfloor_message')->fetch_message_by_pid($pids, $setconfig['perpage_pc'], $orderby, $setconfig);
foreach($variables['postlist'] as &$post) {
if(!$post['first']){
$count = $messageinfo[$post['pid']]['count'] ? $messageinfo[$post['pid']]['count'] : 0;
$list = $messageinfo[$post['pid']]['list'] ? $messageinfo[$post['pid']]['list'] : array();
$post['replyfloor'] = array('count' => $count, 'list' => $list);
}
}
}
} else {
}
$variables['allowreplyfloor'] = 1;
}
}