From 83e8cd61e0d6b65c92aeb260dbd8e650971f3b5a Mon Sep 17 00:00:00 2001 From: Rey Date: Thu, 24 Nov 2022 20:34:13 +0800 Subject: [PATCH 1/2] add settings of privacy protection forums (#135) add settings of privacy protection forums Co-authored-by: kongrui --- lang/chs/lang_forums.php | 1 + lang/chs/lang_settings.php | 3 +++ lang/cht/lang_forums.php | 1 + lang/cht/lang_settings.php | 3 +++ lang/en/lang_forums.php | 1 + lang/en/lang_settings.php | 3 +++ public/forums.php | 24 +++++++++++++++++++++++- public/settings.php | 8 ++++++-- 8 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lang/chs/lang_forums.php b/lang/chs/lang_forums.php index b49a916d..9f4d771f 100644 --- a/lang/chs/lang_forums.php +++ b/lang/chs/lang_forums.php @@ -198,6 +198,7 @@ $lang_forums = array 'text_topic_asc' => "发布时间升序", 'text_post_asc' => "最近回复升序", 'text_post_desc' => "最近回复降序", + 'text_post_protected' => "[size=3][b]--本版块为隐私保护版块---[/b]\n当前帖子内容仅楼主、回复作者、本版版主、管理员以上可见[/size]", ); ?> diff --git a/lang/chs/lang_settings.php b/lang/chs/lang_settings.php index f1ea0152..e9b0d498 100644 --- a/lang/chs/lang_settings.php +++ b/lang/chs/lang_settings.php @@ -796,6 +796,9 @@ $lang_settings = array 'text_destroy_disabled_note_two' => "天不登录,将被从数据库彻底物理删除。默认'500',请设置一个大于上边任何一种导致封禁的值。设为'0'来禁止此规则。", 'row_enable_global_search_system' => '启用全站搜索', 'text_global_search_system_note' => "默认:'是'。若启用,当有多个分区时,主菜单右下角显示全站搜索入口。", + 'row_protected_forum' => '隐私保护论坛板块', + 'text_protected_forum' => '输入开启隐私保护的论坛板块ID,该版块的回复仅楼主作者及管理员以上可见,使用逗号分割(如:1,2,3)', + 'forum_format_error' => '论坛ID格式错误,请检查输入!', ); ?> diff --git a/lang/cht/lang_forums.php b/lang/cht/lang_forums.php index 0f8d3735..00f09c61 100644 --- a/lang/cht/lang_forums.php +++ b/lang/cht/lang_forums.php @@ -198,6 +198,7 @@ $lang_forums = array 'text_topic_asc' => "發布時間升序", 'text_post_asc' => "最近回覆升序", 'text_post_desc' => "最近回覆降序", + 'text_post_protected' => "[size=3][b]--本版為隱私保護版---[/b]\n當前帖子內容僅樓主、回復作者、本版版主、管理員以上等級可查看[/size]", ); ?> diff --git a/lang/cht/lang_settings.php b/lang/cht/lang_settings.php index b0fe01c7..5b7f8282 100644 --- a/lang/cht/lang_settings.php +++ b/lang/cht/lang_settings.php @@ -796,6 +796,9 @@ $lang_settings = array 'text_destroy_disabled_note_two' => "天不登錄,將被從數據庫徹底物理刪除。默認'500',請設置一個大於上邊任何一種導致封禁的值。設為'0'來禁止此規則。", 'row_enable_global_search_system' => '啟用全站搜索', 'text_global_search_system_note' => "默認:'是'。若啟用,當有多個分區時,主菜單右下角顯示全站搜索入口。", + 'row_protected_forum' => '隱私保護論壇板塊', + 'text_protected_forum' => '輸入開啟隱私保護的論壇板塊ID,該版塊的回覆僅樓主作者及管理員以上可見,使用逗號分割(如:1,2,3)', + 'forum_format_error' => '論壇ID格式錯誤,請核查校對!', ); ?> diff --git a/lang/en/lang_forums.php b/lang/en/lang_forums.php index f3948496..39b787a2 100644 --- a/lang/en/lang_forums.php +++ b/lang/en/lang_forums.php @@ -198,6 +198,7 @@ $lang_forums = array 'text_topic_asc' => "Topic Time Ascendant", 'text_post_asc' => "Last Post Time Ascendant", 'text_post_desc' => "Last Post Time Descendant", + 'text_post_protected' => "[size=3][b]--Privacy protection is enabled in this forum---[/b]\nOnly topic poster,mods,admins and reply's author can read the content.[/size]", ); ?> diff --git a/lang/en/lang_settings.php b/lang/en/lang_settings.php index 90e33587..452ad664 100644 --- a/lang/en/lang_settings.php +++ b/lang/en/lang_settings.php @@ -796,6 +796,9 @@ $lang_settings = array 'text_destroy_disabled_note_two' => "Days without logging in, will be physically deleted from the database completely. Default '500', please set a value greater than any of the above to cause disable. Set to '0' to disable this rule." , 'row_enable_global_search_system' => 'Enable global search', 'text_global_search_system_note' => "Default: 'Yes'. If enabled, when there are multiple sections, the global search portal is displayed in the bottom right corner of the main menu.", + 'row_protected_forum' => 'Privacy Protection Forums', + 'text_protected_forum' => 'The IDs of forums\' which enables privacy protection , seperated by commas(e.g. 1,2,3)', + 'forum_format_error' => 'The format of forums is wrong, please check it again!', ); ?> diff --git a/public/forums.php b/public/forums.php index 131a01c2..2feee4a8 100644 --- a/public/forums.php +++ b/public/forums.php @@ -539,6 +539,7 @@ if ($action == "viewtopic") $hlcolor = $arr['hlcolor']; $views = $arr['views']; $forumid = $arr["forumid"]; + $base_posterid = $arr['userid']; $row = get_forum_row($forumid); //------ Get forum name, moderators @@ -672,6 +673,18 @@ if ($action == "viewtopic") $lpr = get_last_read_post_id($topicid); if ($Advertisement->enable_ad()) $forumpostad=$Advertisement->get_ad('forumpost'); + + //check if privacy protection enabled in this forum + $protected_forums = Nexus\Database\NexusDB::remember("setting_protected_forum", 600, function () { + return \App\Models\Setting::getByName('misc.protected_forum'); + }); + + if ($protected_forums and in_array(strval($forumid),explode(",",$protected_forums))){ + $protected_enabled=true; + }else{ + $protected_enabled=false; + } + foreach ($allPosts as $arr) { if ($pn>=1) @@ -738,7 +751,16 @@ if ($action == "viewtopic") print("\n"); print("\n"); - + + //hidden content applied to second or higher floor post (for whose user class below Ad , not poster , not mods ,not reply's author) + if ($protected_enabled && $pn+$offset>1 && get_user_class()"; $bodyContent = format_comment($arr["body"]); if ($highlight){ diff --git a/public/settings.php b/public/settings.php index 7e390585..f7ae7df0 100644 --- a/public/settings.php +++ b/public/settings.php @@ -288,9 +288,12 @@ elseif ($action == 'savesettings_advertisement') // save advertisement elseif ($action == 'savesettings_misc') { stdhead($lang_settings['row_misc_settings']); - $validConfig = array('donation_custom', ); + $validConfig = array('donation_custom', 'protected_forum',); GetVar($validConfig); $data = []; + if (!empty($protected_forum) && !preg_match("/^[,\\d]*[\\d]+$/",$protected_forum)){ + stderr($lang_settings['std_error'],$lang_settings['forum_format_error'].'
'.$lang_settings['std_click']."".$lang_settings['std_here']."".$lang_settings['std_to_go_back'],false,false); + } foreach($validConfig as $config) { $data[$config] = $$config ?? null; } @@ -923,7 +926,8 @@ elseif ($action == 'miscsettings') print ($notice); print ("
"); tr($lang_settings['row_misc_donation_custom'],"
".$lang_settings['text_donation_custom_note'], 1); - tr($lang_settings['row_save_settings'],"", 1); + tr($lang_settings['row_protected_forum'], " ".$lang_settings['text_protected_forum'], 1); + tr($lang_settings['row_save_settings'],"", 1); print (""); } elseif ($action == 'showmenu') // settings main page From 11a174fe1e39b8c74da69f0f115929dae8e59619 Mon Sep 17 00:00:00 2001 From: Rey Date: Fri, 25 Nov 2022 03:10:26 +0800 Subject: [PATCH 2/2] fix protected forums problem (#136) Co-authored-by: kongrui --- public/forums.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/public/forums.php b/public/forums.php index 2feee4a8..9eaa2578 100644 --- a/public/forums.php +++ b/public/forums.php @@ -751,7 +751,8 @@ if ($action == "viewtopic") print("
\n"); print("\n"); - + + $body = "
"; //hidden content applied to second or higher floor post (for whose user class below Ad , not poster , not mods ,not reply's author) if ($protected_enabled && $pn+$offset>1 && get_user_class()"; - $bodyContent = format_comment($arr["body"]); if ($highlight){ $bodyContent = highlight($highlight,$body); }