查看: 26|回复: 2

Discuz! 防止版主或超级版主删除管理员的主帖和楼层回帖

[复制链接]

1502

主题

25

回帖

4172

积分

管理员

金钱
2645
发表于 昨天 15:52 | 显示全部楼层 |阅读模式
【修改代码之前请记得先备份文件】
通过 google gemini 的帮助,在 viewthread 和 viewthread_node 模板修改代码隐藏对管理员帖子删除的按钮,
目前只在 Discuz! X3.5 测试,版主或超级版主进入管理员发表的主帖和回帖将不会显示删除的按钮,
超级版主进入超级版主或其他会员的帖删除按钮还是会显示,修改代码的方法:

打开 template\default\forum\viewthread.htm,查找(大约第在 83 行):

  1. <!--{if $_G['forum']['ismoderator']}-->
  2.                                                                 <!--{if $_G['group']['allowwarnpost']}--><a href="javascript:;" onclick="modaction('warn')">{lang modmenu_warn}</a><span class="pipe">|</span><!--{/if}-->
  3.                                                                 <!--{if $_G['group']['allowbanpost']}--><a href="javascript:;" onclick="modaction('banpost')">{lang modmenu_banpost}</a><span class="pipe">|</span><!--{/if}-->
  4.                                                                 <!--{if $_G['group']['allowdelpost'] && !$rushreply}--><a href="javascript:;" onclick="modaction('delpost')">{lang modmenu_deletepost}</a><span class="pipe">|</span><!--{/if}-->
  5.                                                         <!--{/if}-->
复制代码

修改为:

  1. <!--{if $_G['forum']['ismoderator']}-->
  2.         <!--{if $_G['group']['allowwarnpost']}--><a href="javascript:;" onclick="modaction('warn')">{lang modmenu_warn}</a><span class="pipe">|</span><!--{/if}-->
  3.         <!--{if $_G['group']['allowbanpost']}--><a href="javascript:;" onclick="modaction('banpost')">{lang modmenu_banpost}</a><span class="pipe">|</span><!--{/if}-->
  4.         <!--{if $_G['group']['allowdelpost'] && !$rushreply && ($_G['forum_thread']['authorid'] != 1 || $_G['uid'] == 1)}--><a href="javascript:;" onclick="modaction('delpost')">{lang modmenu_deletepost}</a><span class="pipe">|</span><!--{/if}-->
  5. <!--{/if}-->
复制代码


再查找(大约第在 107 行):

  1. <!--{if $_G['forum']['ismoderator']}-->
  2.                         <!--{if $_G['group']['allowdelpost']}--><!--{eval $modopt++}--><a href="javascript:;" onclick="modthreads(3, 'delete')">{lang modmenu_deletethread}</a><span class="pipe">|</span><!--{/if}-->
复制代码

修改为:

  1. <!--{if $_G['forum']['ismoderator']}-->
  2.         <!--{if $_G['group']['allowdelpost'] && ($_G['forum_thread']['authorid'] != 1 || $_G['uid'] == 1)}--><!--{eval $modopt++}--><a href="javascript:;" onclick="modthreads(3, 'delete')">{lang modmenu_deletethread}</a><span class="pipe">|</span><!--{/if}-->
复制代码

打开 template\default\forum\viewthread_node.htm,查找(大约第在 382 行):

  1.         <span class="y">
  2.                                 <label for="manage$post[pid]">
  3.                                 <input type="checkbox" id="manage$post[pid]" class="pc" {if !empty($modclick)}checked="checked" {/if}onclick="pidchecked(this);modclick(this, $post[pid])" value="$post[pid]" autocomplete="off" />
  4.                                 {lang manage}
  5.                                 </label>
  6.                                 </span>
  7.                         <!--{/if}-->
复制代码

修改为:

  1. <span class="y">
  2.         <label for="manage$post[pid]">
  3.         <input type="checkbox" id="manage$post[pid]" class="pc" {if !empty($modclick)}checked="checked" {/if}onclick="pidchecked(this);modclick(this, $post[pid])" value="$post[pid]" autocomplete="off" />
  4.         {lang manage}
  5.         </label>
  6.         </span>
复制代码


修改后到后台更新缓存。


回复

使用道具 举报

1502

主题

25

回帖

4172

积分

管理员

金钱
2645
 楼主| 发表于 昨天 23:15 | 显示全部楼层
从官网得到的方法(这个我还没试)
文件路径:source/include/topicadmin/topicadmin_moderate.php,找到:

  1. loadcache('threadtableids');
复制代码

在它上面添加权限判断

  1. foreach($threadlist as $t_item) {
  2.         $th_author = C::t('common_member')->fetch($t_item['authorid']);
  3.         $author_aid = $th_author['adminid'];
  4.         if($author_aid > 0 && $_G['adminid'] > $author_aid) {
  5.                 showmessage('你无权删除管理员帖子,请重新选择');
  6.         }
  7. }
复制代码


来源:https://www.dismall.com/thread-29164-2-1.html

回复

使用道具 举报

1502

主题

25

回帖

4172

积分

管理员

金钱
2645
 楼主| 发表于 12 小时前 | 显示全部楼层
来源:https://www.dismall.com/thread-29164-2-1.html (13楼)
修改文件一:
绝对路径:/source/module/forum/forum_topicadmin.php
定位方式
找到以下代码:

  1. if(!$specialperm && (!$_G['uid'] || !$_G['forum']['ismoderator'])) {
  2. showmessage('admin_nopermission', NULL);
  3. }
复制代码

在它之后插入权限验证:

  1. // ===== 权限验证:禁止非创始人删除管理员的帖子 =====
  2. // 仅拦截删除操作:action=delpost(删除回帖)或 action=moderate&operation=delete(删除主题)
  3. $is_delete_action = ($_GET['action'] == 'delpost') || ($_GET['action'] == 'moderate' && $_GET['operation'] == 'delete');

  4. if ($is_delete_action) {
  5.     // 从 config_global.php 读取创始人 UID
  6.     global $_G;
  7.     $founder_uid = intval($_G['config']['admincp']['founder']);
  8.     if (empty($founder_uid)) {
  9.         showmessage('创始人UID未在config_global.php中配置');
  10.     }
  11.     $current_uid = intval($_G['uid']);
  12.    
  13.     // 获取被操作的帖子/主题ID列表
  14.     $target_ids = array();
  15.     if (!empty($_GET['topiclist']) && is_array($_GET['topiclist'])) {
  16.         $target_ids = $_GET['topiclist'];
  17.     } elseif (!empty($_GET['moderate']) && is_array($_GET['moderate'])) {
  18.         $target_ids = $_GET['moderate'];
  19.     } elseif (!empty($_GET['topiclist']) && !is_array($_GET['topiclist'])) {
  20.         $target_ids = explode(',', $_GET['topiclist']);
  21.     }
  22.    
  23.     $has_admin_author = false;
  24.     if (!empty($target_ids)) {
  25.         foreach ($target_ids as $id) {
  26.             $id = intval($id);
  27.             if (!$id) continue;
  28.             // 先查主题表(适用于主题操作)
  29.             $thread_author = DB::fetch_first(
  30.                 "SELECT authorid FROM " . DB::table('forum_thread') . " WHERE tid = " . $id
  31.             );
  32.             if ($thread_author && $thread_author['authorid'] > 0) {
  33.                 $author_info = C::t('common_member')->fetch($thread_author['authorid']);
  34.                 if ($author_info && ($author_info['groupid'] == 1 || $author_info['adminid'] == 1)) {
  35.                     $has_admin_author = true;
  36.                     break;
  37.                 }
  38.             }
  39.             // 如果主题表没有,再查帖子表(回帖操作)
  40.             if (!$has_admin_author) {
  41.                 $post_author = DB::fetch_first(
  42.                     "SELECT authorid FROM " . DB::table('forum_post') . " WHERE pid = " . $id . " OR tid = " . $id . " LIMIT 1"
  43.                 );
  44.                 if ($post_author && $post_author['authorid'] > 0) {
  45.                     $author_info = C::t('common_member')->fetch($post_author['authorid']);
  46.                     if ($author_info && ($author_info['groupid'] == 1 || $author_info['adminid'] == 1)) {
  47.                         $has_admin_author = true;
  48.                         break;
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.     }
  54.    
  55.     if ($has_admin_author && $current_uid != $founder_uid) {
  56.         showmessage('只有创始人才可以删除管理员的帖子');
  57.     }
  58. }
  59. // ===== 权限验证结束 =====
复制代码

修改文件二:
绝对路径:/source/include/modcp/modcp_thread.php
定位方式
在 if($do == 'delete' && submitcheck('deletesubmit')) { 这一行后面(即函数体的第一行)插入以下代码

  1.     // ===== 权限验证:禁止非创始人删除管理员的帖子 =====
  2.     // 从 config_global.php 读取创始人 UID
  3.     global $_G;
  4.     $founder_uid = intval($_G['config']['admincp']['founder']);
  5.     if (empty($founder_uid)) {
  6.         showmessage('创始人UID未在config_global.php中配置');
  7.     }
  8.     $current_uid = intval($_G['uid']);
  9.    
  10.     // 获取被删除的帖子ID列表
  11.     $pids = dimplode($_GET['delete']);
  12.     $has_admin_author = false;
  13.     if (!empty($pids)) {
  14.         foreach ($pids as $pid) {
  15.             $post_author = DB::fetch_first(
  16.                 "SELECT authorid FROM " . DB::table('forum_post') . " WHERE pid = " . intval($pid)
  17.             );
  18.             if ($post_author && $post_author['authorid'] > 0) {
  19.                 $author_info = C::t('common_member')->fetch($post_author['authorid']);
  20.                 if ($author_info && ($author_info['groupid'] == 1 || $author_info['adminid'] == 1)) {
  21.                     $has_admin_author = true;
  22.                     break;
  23.                 }
  24.             }
  25.         }
  26.     }
  27.    
  28.     if ($has_admin_author && $current_uid != $founder_uid) {
  29.         showmessage('只有创始人才可以删除管理员的帖子');
  30.     }
  31.     // ===== 权限验证结束 =====
复制代码

这个方案将验证逻辑放在入口处,逻辑最清晰,拦截最早。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|网站地图|文强阁

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖
返回顶部