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

378 lines
15 KiB
PHP
Executable File

<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class plugin_thread_across {
protected $__pbforums = array();
protected $__pbthreads = 0;
public function global_myitem_extra(){
global $_G;
if( !$_G['cache']['plugin']['thread_across']['open'] ) return;
return '<li><a href="home.php?mod=spacecp&ac=plugin&id=thread_across:userpb">屏蔽版块</a></li>';
}
function deletemember($p){
global $_G;
if( !empty($p['param'][0]) ){
C::t('#thread_across#across_pbforums')->delete( $p['param'][0] );
}
}
protected function __thread_edit(){
global $_G, $thread, $isfirstpost;
if( !$_G['cache']['plugin']['thread_across']['open'] || !$_G['uid'] ) return;
$_G['cache']['plugin']['thread_across']['groupids'] = dunserialize($_G['cache']['plugin']['thread_across']['groupids']);
if( ! in_array($_G['groupid'], $_G['cache']['plugin']['thread_across']['groupids']) ) return;
if( $_GET['action'] == 'reply' ) return;
if( $_GET['action'] == 'edit' && !$isfirstpost ) return;
include_once libfile('function/forumlist');
$thread['across_fids'] = array_filter(explode(',', $thread['across_fids']));
$forums = forumselect(false, 0, $thread['across_fids']);
include template('thread_across:block_thread_edit');
return $return;
}
protected function __thread_save($param){
global $_G , $isfirstpost;
$pvars = $_G['cache']['plugin']['thread_across'];
$isfirstpost = in_array($param['param'][0] , array('post_newthread_succeed','post_newthread_mod_succeed')) ? 1 : $isfirstpost;
if( !$isfirstpost || !$pvars['open'] ) return;
if(!empty($param['param'][2]['tid'])){
C::t('forum_thread')->update($param['param'][2]['tid'], array(
'across_fids' => $_GET['across_fids'] ? (','. implode(',', $_GET['across_fids']) . ',') : ''
));
}
}
protected function __forumdisplay_lists(){
global $_G;
if( !$_G['cache']['plugin']['thread_across']['open'] || !$_G['uid'] ) return;
$this->__pbforums = $pbforums = C::t('#thread_across#across_pbforums')->fetch_by_uid( $_G['uid'] );
if($_G['forum_threadlist']){
$dblastposts = array_column($_G['forum_threadlist'], 'dblastpost');
$lastpost_end = current($dblastposts);
$lastpost_start = end($dblastposts);
}
foreach($_G['forum_threadlist'] as $key => $thread){
if( !empty($thread['across_fids']) ){
$thread['across_fids'] = array_filter(explode(',', $thread['across_fids']));
if( in_array($thread['fid'], $pbforums['fids']) ){//帖子发布的原版块也在屏蔽板块中时也不显示
unset($_G['forum_threadlist'][$key]);
$_G['forum_threadcount']--;
$this->__pbthreads++;
}
if( array_intersect($thread['across_fids'], $pbforums['fids']) ){//帖子的跨越版块也在屏蔽板块中时也不显示
unset($_G['forum_threadlist'][$key]);
$_G['forum_threadcount']--;
$this->__pbthreads++;
}
}
}
if( empty($_G['forum_threadlist']) && $_GET['page'] <= 1 ){
$lastpost_end = TIMESTAMP;
$lastpost_start = 0;
}
/*
if($_GET['orderby'] == 'lastpost'){//最新回复
}else if($_GET['orderby'] == 'dateline'){//最新发帖
}else if($_GET['orderby'] == 'heats'){//热门
}else if($_GET['filter'] == 'hot'){//热帖
}else if($_GET['filter'] == 'digest'){//精华
}*/
if( $_GET['page'] <= 1 ){
$sql = 'select * from %t where displayorder=0 and fid!=%d and across_fids like %s and lastpost>=%d order by lastpost desc';
$arg = array('forum_thread', $_G['fid'], "%,{$_G['fid']},%", $lastpost_start);
$across_threads = DB::fetch_all($sql, $arg);
}else{
if($_G['forum_threadlist']){
$sql = 'select * from %t where displayorder=0 and fid!=%d and across_fids like %s and lastpost>=%d and lastpost<%d order by lastpost desc';
$arg = array('forum_thread', $_G['fid'], "%,{$_G['fid']},%", $lastpost_start, $lastpost_end);
$across_threads = DB::fetch_all($sql, $arg);
}
}
$_G['forum']['threads'] += DB::result_first('select count(*) from %t where displayorder=0 and fid!=%d and across_fids like %s limit 1', array('forum_thread', $_G['fid'], "%,{$_G['fid']},%"));
$todaytime = strtotime(dgmdate(TIMESTAMP, 'Ymd'));
foreach($across_threads as $key => $thread){
$thread['across_fids'] = array_filter(explode(',', $thread['across_fids']));
if( in_array($thread['fid'], $pbforums['fids']) ){//帖子发布的原版块也在屏蔽板块中时也不显示
$this->__pbthreads++;
continue;
}
if( array_intersect($thread['across_fids'], $pbforums['fids']) ){//帖子的跨越版块也在屏蔽板块中时也不显示
$this->__pbthreads++;
continue;
}
$thread['allreplies'] = $thread['replies'] + $thread['comments'];
$thread['ordertype'] = getstatus($thread['status'], 4);
if($_G['forum']['picstyle'] && empty($_G['cookie']['forumdefstyle'])) {
$thread['coverpath'] = getthreadcover($thread['tid'], $thread['cover']);
$thread['cover'] = abs($thread['cover']);
}
//$thread['forumstick'] = in_array($thread['tid'], $forumstickytids);
$thread['related_group'] = 0;
$thread['lastposterenc'] = rawurlencode($thread['lastposter']);
if($thread['typeid'] && !empty($_G['forum']['threadtypes']['prefix']) && isset($_G['forum']['threadtypes']['types'][$thread['typeid']])) {
if($_G['forum']['threadtypes']['prefix'] == 1) {
$thread['typehtml'] = '<em>[<a href="forum.php?mod=forumdisplay&fid='.$_G['fid'].'&amp;filter=typeid&amp;typeid='.$thread['typeid'].'">'.$_G['forum']['threadtypes']['types'][$thread['typeid']].'</a>]</em>';
} elseif($_G['forum']['threadtypes']['icons'][$thread['typeid']] && $_G['forum']['threadtypes']['prefix'] == 2) {
$thread['typehtml'] = '<em><a title="'.strip_tags($_G['forum']['threadtypes']['types'][$thread['typeid']]).'" href="forum.php?mod=forumdisplay&fid='.$_G['fid'].'&amp;filter=typeid&amp;typeid='.$thread['typeid'].'">'.'<img style="vertical-align: middle;padding-right:4px;" src="'.$_G['forum']['threadtypes']['icons'][$thread['typeid']].'" alt="'.strip_tags($_G['forum']['threadtypes']['types'][$thread['typeid']]).'" /></a></em>';
}
$thread['typename'] = $_G['forum']['threadtypes']['types'][$thread['typeid']];
} else {
$thread['typename'] = $thread['typehtml'] = '';
}
$thread['sorthtml'] = $thread['sortid'] && !empty($_G['forum']['threadsorts']['prefix']) && isset($_G['forum']['threadsorts']['types'][$thread['sortid']]) ?
'<em>[<a href="forum.php?mod=forumdisplay&fid='.$_G['fid'].'&amp;filter=sortid&amp;sortid='.$thread['sortid'].'">'.$_G['forum']['threadsorts']['types'][$thread['sortid']].'</a>]</em>' : '';
$thread['multipage'] = '';
//$topicposts = $thread['special'] ? $thread['replies'] : $thread['replies'] + 1;
//$multipate_archive = $_GET['archiveid'] && in_array($_GET['archiveid'], $threadtableids) ? "archiveid={$_GET['archiveid']}" : '';
// if($topicposts > $_G['ppp']) {
// $pagelinks = '';
// $thread['pages'] = ceil($topicposts / $_G['ppp']);
// $realtid = $_G['forum']['status'] != 3 && $thread['isgroup'] == 1 ? $thread['closed'] : $thread['tid'];
// for($i = 2; $i <= 6 && $i <= $thread['pages']; $i++) {
// $pagelinks .= "<a href=\"forum.php?mod=viewthread&tid=$realtid&amp;".(!empty($multipate_archive) ? "$multipate_archive&amp;" : '')."extra=$extra&amp;page=$i\" onclick=\"atarget(this)\">$i</a>";
// }
// if($thread['pages'] > 6) {
// $pagelinks .= "..<a href=\"forum.php?mod=viewthread&tid=$realtid&amp;".(!empty($multipate_archive) ? "$multipate_archive&amp;" : '')."extra=$extra&amp;page=$thread[pages]\" onclick=\"atarget(this)\">$thread[pages]</a>";
// }
// $thread['multipage'] = '&nbsp;...'.$pagelinks;
// }
if($thread['highlight']) {
$string = sprintf('%02d', $thread['highlight']);
$stylestr = sprintf('%03b', $string[0]);
$thread['highlight'] = ' style="';
$thread['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
$thread['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
$thread['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
$thread['highlight'] .= $string[1] ? 'color: '.$_G['forum_colorarray'][$string[1]].';' : '';
if($thread['bgcolor']) {
$thread['highlight'] .= "background-color: {$thread['bgcolor']};";
}
$thread['highlight'] .= '"';
} else {
$thread['highlight'] = '';
}
$thread['recommendicon'] = '';
if(!empty($_G['setting']['recommendthread']['status']) && $thread['recommends']) {
foreach($_G['setting']['recommendthread']['iconlevels'] as $k => $i) {
if($thread['recommends'] > $i) {
$thread['recommendicon'] = $k+1;
break;
}
}
}
$thread['moved'] = $thread['heatlevel'] = $thread['new'] = 0;
if($_G['forum']['status'] != 3 && ($thread['closed'] || ($_G['forum']['autoclose'] && $thread['fid'] == $_G['fid'] && TIMESTAMP - $thread[$closedby] > $_G['forum']['autoclose']))) {
if($thread['isgroup'] == 1) {
$thread['folder'] = 'common';
$grouptids[] = $thread['closed'];
} else {
if($thread['closed'] > 1) {
$thread['moved'] = $thread['tid'];
$thread['allreplies'] = $thread['replies'] = '-';
$thread['views'] = '-';
}
$thread['folder'] = 'lock';
}
} elseif($_G['forum']['status'] == 3 && $thread['closed'] == 1) {
$thread['folder'] = 'lock';
} else {
$thread['folder'] = 'common';
$thread['weeknew'] = TIMESTAMP - 604800 <= $thread['dateline'];
if($thread['allreplies'] > $thread['views']) {
$thread['views'] = $thread['allreplies'];
}
if($_G['setting']['heatthread']['iconlevels']) {
foreach($_G['setting']['heatthread']['iconlevels'] as $k => $i) {
if($thread['heats'] > $i) {
$thread['heatlevel'] = $k + 1;
break;
}
}
}
}
$thread['icontid'] = $thread['forumstick'] || !$thread['moved'] && $thread['isgroup'] != 1 ? $thread['tid'] : $thread['closed'];
if(!$thread['forumstick'] && ($thread['isgroup'] == 1 || $thread['fid'] != $_G['fid'])) {
$thread['icontid'] = $thread['closed'] > 1 ? $thread['closed'] : $thread['tid'];
}
$thread['istoday'] = $thread['dateline'] > $todaytime ? 1 : 0;
$thread['dbdateline'] = $thread['dateline'];
$thread['dateline'] = dgmdate($thread['dateline'], 'u', '9999', getglobal('setting/dateformat'));
$thread['dblastpost'] = $thread['lastpost'];
$thread['lastpost'] = dgmdate($thread['lastpost'], 'u');
$thread['hidden'] = $_G['setting']['threadhidethreshold'] && $thread['hidden'] >= $_G['setting']['threadhidethreshold'] || in_array($thread['tid'], $thide);
$_G['forum_threadlist'][] = $thread;
$_G['forum_threadcount'] ++;
}
if( $across_threads ){
array_multisort(array_column($_G['forum_threadlist'], 'dblastpost'), SORT_DESC, $_G['forum_threadlist']);
}
}
public function __forumdisplay_bottom_showtip(){
global $_G;
$html = '';
if( $this->__pbthreads > 0 ) {
if( $_G['mobile'] ){
$html = '<div style="font-size:16px;text-align:center;line-height:50px;">某些帖子因您的隐私设置无法显示</div>';
}else{
$html = '<div style="font-size:16px;text-align:center;line-height:34px;">某些帖子因您的隐私设置无法显示</div>';
}
}
return $html;
}
}
class plugin_thread_across_forum extends plugin_thread_across {
public function forumdisplay_forumaction(){
global $_G;
if( !$_G['cache']['plugin']['thread_across']['open'] || !$_G['uid'] ) return;
$pbforums = C::t('#thread_across#across_pbforums')->fetch_by_uid( $_G['uid'] );
$html = '<span class="pipe">|</span>';
if( in_array($_G['fid'], $pbforums['fids']) ){
$html.= '<img src="source/plugin/thread_across/static/icon_pingbi.svg" style="vertical-align:middle;height:15px;margin-top:-2px;padding-right:4px;">已屏蔽此版块';
}else{
$html.= '<a href="plugin.php?id=thread_across:ajax&formhash='.FORMHASH.'&op=pbforum_add&fid='.$_G['fid'].'" id="a_forumpb" onclick="showWindow(this.id, this.href, \'get\', 0);">';
$html.= '<img src="source/plugin/thread_across/static/icon_pingbi.svg" style="vertical-align:middle;height:15px;margin-top:-2px;padding-right:4px;">屏蔽此版块</a>';
}
return $html;
}
public function post_middle_output(){
return $this->__thread_edit();
}
public function forumdisplay_top_output(){
$this->__forumdisplay_lists();
}
public function forumdisplay_postbutton_bottom_output(){
return $this->__forumdisplay_bottom_showtip();
}
public function forumdisplay_bottom_output(){
}
public function post_checkreply_message($param){
$this->__thread_save($param);
}
public function index_top_output(){
global $forumlist;
foreach($forumlist as $fid => $forum){
$forumlist[$fid]['threads'] += DB::result_first('select count(*) from %t where displayorder=0 and fid!=%d and across_fids like %s limit 1', array('forum_thread', $forum['fid'], "%,{$forum['fid']},%"));
}
}
}
class mobileplugin_thread_across extends plugin_thread_across {
}
class mobileplugin_thread_across_home extends plugin_thread_across {
public function space_profile_nav_extra_mobile(){
global $_G;
if( !$_G['cache']['plugin']['thread_across']['open'] || !$_G['uid'] ) return;
//return '<li><a href="home.php?mod=spacecp&ac=plugin&id=thread_across:userpb"><i class="dm-error"></i>屏蔽版块</a></li>';
return '<li>
<a href="home.php?mod=spacecp&ac=plugin&id=thread_across:userpb">
<img src="template/bygsjw_sj/image/bl_liebiao.png" alt="广播">
屏蔽版块
<img src="template/bygsjw_sj/image/jinru.png" alt="进入" class="myinfo_list_jinru">
</a>
</li>';
}
}
class mobileplugin_thread_across_forum extends plugin_thread_across {
public function forumdisplay_nav_mobile(){
global $_G;
if( !$_G['cache']['plugin']['thread_across']['open'] || !$_G['uid'] ) return;
$pbforums = C::t('#thread_across#across_pbforums')->fetch_by_uid( $_G['uid'] );
$html = '<style>.forumdisplay-top h2 #a_forumpb {float:right;height:28px;line-height:28px;font-size:12px;padding:0 10px;margin-top:10px;margin-left:5px;background-color:var(--dz-BG-3);color:var(--dz-FC-fff);border-radius:4px;}</style>';
if( in_array($_G['fid'], $pbforums['fids']) ){
$html .= '<script type="text/javascript" reload="1">$(".forumdisplay_top_y").append(\'<p><a href="javascript:;" id="a_forumpb" style="margin-top:10px">已屏蔽</a></p>\')</script>';
}else{
$html .= '<script type="text/javascript" reload="1">$(".forumdisplay_top_y").append(\'<p><a href="plugin.php?id=thread_across:ajax&formhash='.FORMHASH.'&op=pbforum_add&fid='.$_G['fid'].'" id="a_forumpb" class="dialog" style="margin-top:10px">屏蔽版块</a></p>\')</script>';
}
return $html;
}
public function post_middle_mobile_output(){
return $this->__thread_edit();
}
public function forumdisplay_top_mobile_output(){
$this->__forumdisplay_lists();
}
public function forumdisplay_bottom_mobile_output(){
return $this->__forumdisplay_bottom_showtip();
}
public function post_checkreply_message($param){
$this->__thread_save($param);
}
public function index_top_mobile_output(){
global $forumlist;
foreach($forumlist as $fid => $forum){
$forumlist[$fid]['threads'] += DB::result_first('select count(*) from %t where displayorder=0 and fid!=%d and across_fids like %s limit 1', array('forum_thread', $forum['fid'], "%,{$forum['fid']},%"));
}
}
}
?>