From 9d001984a502aa48b800682a9265881472e372ca Mon Sep 17 00:00:00 2001 From: Rexzooly Kai Black Date: Mon, 23 Jun 2025 15:30:57 +0100 Subject: [PATCH 1/2] Update chat.php Added setting noguestpm this lets you enable and disabled guests pms via the admin setting (Disable Guests private messages) = Enabled/Disabled Added a mini function to PM the Guest that sent a PM when it's disabled, this function can PM user it's called system_pm Only problem is right now it's not supported by the Language filess --- chat.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/chat.php b/chat.php index 1c9b72d..32dc628 100644 --- a/chat.php +++ b/chat.php @@ -2,7 +2,7 @@ /* * LE CHAT-PHP - a PHP Chat based on LE CHAT - Main program * -* Copyright (C) 2015-2021 Daniel Winzen +* Copyright (C) 2015-2025 Daniel Winzen * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -115,7 +115,20 @@ function route(): void } } }elseif(isset($_POST['message']) && isset($_POST['sendto'])){ - send_post(validate_input()); + if($_POST['sendto']!=='s *'){ + if($U['status']==='1'){ // Check if user if Guest + $noguespm=(bool) get_setting('noguestpm'); // get the Guest PM settings + if(!$noguespm){ + send_post(validate_input()); + }else{ + system_pm('noguestpm'); // Return a PM from the System to tell the guest it didn't work/ + } + }else{ + send_post(validate_input()); // Not a guest + } + }else{ + send_post(validate_input()); // Sent to everyone + } } send_post(); }elseif($_REQUEST['action']==='login'){ @@ -295,6 +308,7 @@ function route_setup(): void 'incognito' => _('Incognito mode'), 'sendmail' => _('Send mail on new public message'), 'modfallback' => _('Fallback to waiting room, if no moderator is present to approve guests'), + 'noguestpm' =>_('Disable Guests private messages'), 'disablepm' => _('Disable private messages'), 'eninbox' => _('Enable offline inbox'), 'enablegreeting' => _('Show a greeting message before showing the messages'), @@ -2049,7 +2063,7 @@ function send_post(string $rejected=''): void if(isset($_POST['multi'])){ echo hidden('multi', 'on'); } - echo '
'; + echo '
'.style_this(htmlspecialchars($U['nickname']), $U['style']).':
'; if(isset($_POST['multi'])){ echo ""; }else{ @@ -3348,8 +3362,16 @@ function add_user_defaults(string $password): void $U['exiting']=0; } +// Sending system messages via PM to users +/* This can be used for many different warnings or information*/ +function system_pm(string $type) : string { + global $U; + if($type == 'noguestpm'){ // Disabled Guest PM Message. + add_system_pm_message('[System - ' . $U['nickname'] . '] Unable to send private messages while your in guest mode.', $U['nickname'], ''); + } + return ''; +} // message handling - function validate_input() : string { global $U, $db; $inbox=false; @@ -3657,7 +3679,33 @@ function add_system_message(string $mes, string $doer): void } write_message($sysmessage); } +function add_system_pm_message(string $mes, string $recipient, string $doer): void +{ + if($mes===''){ + return; + } + if($doer==='' || !get_setting('namedoers')){ + $sysmessage=[ + 'postdate' =>time(), + 'poststatus' =>9, + 'poster' =>'System', + 'recipient' => $recipient, + 'text' =>"$mes", + 'delstatus' =>4 + ]; + } else { + $sysmessage=[ + 'postdate' =>time(), + 'poststatus' =>9, + 'poster' =>'System', + 'recipient' => $recipient, + 'text' =>"$mes ($doer)", + 'delstatus' =>4 + ]; + } + write_message($sysmessage); +} function write_message(array $message): void { global $db; @@ -4264,6 +4312,7 @@ function init_chat(): void ['defaultrefresh', '20'], ['dismemcaptcha', '0'], ['suguests', '0'], + ['noguestpm', '0'], ['imgembed', '1'], ['timestamps', '1'], ['trackip', '0'], @@ -4451,7 +4500,7 @@ function update_db(): void } $stmt->execute([$style, $temp['id']]); } - $db->exec('INSERT INTO ' . PREFIX . "settings (setting, value) VALUES ('colbg', '000000'), ('coltxt', 'FFFFFF'), ('maxname', '20'), ('minpass', '5'), ('defaultrefresh', '20'), ('dismemcaptcha', '0'), ('suguests', '0'), ('imgembed', '1'), ('timestamps', '1'), ('trackip', '0'), ('captchachars', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), ('memkick', '1'), ('forceredirect', '0'), ('redirect', ''), ('incognito', '1');"); + $db->exec('INSERT INTO ' . PREFIX . "settings (setting, value) VALUES ('colbg', '000000'), ('coltxt', 'FFFFFF'), ('maxname', '20'), ('minpass', '5'), ('defaultrefresh', '20'), ('dismemcaptcha', '0'), ('suguests', '0'), ('noguestpm', '0'), ('imgembed', '1'), ('timestamps', '1'), ('trackip', '0'), ('captchachars', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), ('memkick', '1'), ('forceredirect', '0'), ('redirect', ''), ('incognito', '1');"); } if($dbversion<12){ $db->exec('ALTER TABLE ' . PREFIX . 'captcha MODIFY code char(5) NOT NULL, DROP INDEX id, ADD PRIMARY KEY (id) USING BTREE;'); From cfc8b9acc59cf3de4129c599d742193d5dfcaf38 Mon Sep 17 00:00:00 2001 From: Rexzooly Kai Black Date: Mon, 23 Jun 2025 15:34:30 +0100 Subject: [PATCH 2/2] Update chat.php Removed a little debug string no longer needed/never needed in the live script. --- chat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chat.php b/chat.php index 32dc628..ca1eb1a 100644 --- a/chat.php +++ b/chat.php @@ -2063,7 +2063,7 @@ function send_post(string $rejected=''): void if(isset($_POST['multi'])){ echo hidden('multi', 'on'); } - echo '
' . $U['status'] . ' ' .style_this(htmlspecialchars($U['nickname']), $U['style']).':
'; + echo '
' . $U['status'] . ' ' .style_this(htmlspecialchars($U['nickname']), $U['style']).':
'; if(isset($_POST['multi'])){ echo ""; }else{
' . style_this(htmlspecialchars($U['nickname']), $U['style']) . ':