diff --git a/chat.php b/chat.php index d72b196..a20c93c 100644 --- a/chat.php +++ b/chat.php @@ -54,7 +54,8 @@ cron(); route(); // main program: decide what to do based on queries -function route(){ +function route(): void +{ global $U; if(!isset($_REQUEST['action'])){ send_login(); @@ -232,7 +233,8 @@ function route_admin() : string { return ''; } -function route_setup(){ +function route_setup(): void +{ global $U; if(!valid_admin()){ send_alogin(); @@ -263,7 +265,8 @@ function route_setup(){ } // html output subs -function prepare_stylesheets(string $class){ +function prepare_stylesheets(string $class): void +{ global $U, $db, $scripts, $styles; if($class === 'fatal_error') { $styles[ 'fatal_error' ] = 'body{background-color:#000000;color:#FF0033}'; @@ -295,6 +298,41 @@ function prepare_stylesheets(string $class){ if($class === 'init' || ! $db instanceof PDO){ return; } + if($class === 'frameset'){ + if(($U['status']>=5 || ($U['status']>2 && get_count_mods()==0)) && get_setting('enfileupload')>0 && get_setting('enfileupload')<=$U['status']){ + $postheight='120px'; + }else{ + $postheight='100px'; + } + if((!isset($_REQUEST['sort']) && !$U['sortupdown']) || (isset($_REQUEST['sort']) && $_REQUEST['sort']==0)) { + $styles[ 'frameset' ] = "#frameset-mid{position:fixed;top:$postheight;bottom:45px;left:0;right:0;margin:0;padding:0;overflow:hidden}"; + $styles[ 'frameset' ] .= "#frameset-top{position:fixed;top:0;left:0;right:0;height:$postheight;margin:0;padding:0;overflow:hidden;border-bottom: 1px solid}"; + $styles[ 'frameset' ] .= "#frameset-bot{position:fixed;bottom:0;left:0;right:0;height:45px;margin:0;padding:0;overflow:hidden;border-top:1px solid}"; + } else{ + $styles[ 'frameset' ] =" #frameset-mid{position:fixed;top:45px;bottom:$postheight;left:0;right:0;margin:0;padding:0;overflow:hidden}"; + $styles[ 'frameset' ] .= "#frameset-top{position:fixed;top:0;left:0;right:0;height:45px;margin:0;padding:0;overflow:hidden;border-bottom:1px solid}"; + $styles[ 'frameset' ] .= "#frameset-bot{position:fixed;bottom:0;left:0;right:0;height:$postheight;margin:0;padding:0;overflow:hidden;border-top:1px solid}"; + } + } + if($class === 'filter'){ + $styles['filter'] = 'table table{width:100%} '; + $styles['filter'] .= 'table table td:nth-child(1){width:8em;font-weight:bold} '; + $styles['filter'] .= 'table table td:nth-child(2),table table td:nth-child(3){width:12em} '; + $styles['filter'] .= 'table table td:nth-child(4){width:9em} '; + $styles['filter'] .= 'table table td:nth-child(5),table table td:nth-child(6),table table td:nth-child(7),table table td:nth-child(8){width:5em} '; + } + if($class === 'linkfilter'){ + $styles['linkfilter'] = 'table table{width:100%} '; + $styles['linkfilter'] .= 'table table td:nth-child(1){width:8em;font-weight:bold} '; + $styles['linkfilter'] .= 'table table td:nth-child(2),table table td:nth-child(3){width:12em} '; + $styles['linkfilter'] .= 'table table td:nth-child(4),table table td:nth-child(5){width:5em} '; + } + if($class === 'post'){ + $styles['post'] = '.spacer{width:10px}'; + } + if($class === 'messages'){ + $styles['post'] = '.nicklink{text-decoration:none}.channellink{text-decoration:underline}'; + } $css=get_setting('css'); $coltxt=get_setting('coltxt'); if(!empty($U['bgcolour'])){ @@ -323,7 +361,7 @@ function prepare_stylesheets(string $class){ } } -function print_stylesheet(string $class) +function print_stylesheet(string $class): void { global $scripts, $styles; //default css @@ -331,20 +369,21 @@ function print_stylesheet(string $class) if ( $class === 'init' ) { return; } + if(isset($styles[$class])) { + echo ""; + } //overwrite with custom css echo ""; $allow_js = (bool) get_setting( 'allow_js' ); if ( $allow_js ) { - if($class === 'frameset') { - echo ""; - } - if($class === 'post') { - echo ""; + if(isset($scripts[$class])) { + echo ""; } } } -function print_end(){ +function print_end(): void +{ echo ''; exit; } @@ -396,15 +435,17 @@ function hidden(string $name='', string $value='') : string { return ""; } -function submit($value='', $extra_attribute='') : string { +function submit(string $value='', string $extra_attribute='') : string { return ""; } -function thr(){ +function thr(): void +{ echo '
'; } -function print_start(string $class='', int $ref=0, string $url=''){ +function print_start(string $class='', int $ref=0, string $url=''): void +{ global $I, $language; prepare_stylesheets($class); send_headers(); @@ -429,7 +470,8 @@ function print_start(string $class='', int $ref=0, string $url=''){ } } -function send_redirect(string $url){ +function send_redirect(string $url): void +{ global $I; $url=trim(htmlspecialchars_decode(rawurldecode($url))); preg_match('~^(.*)://~u', $url, $match); @@ -453,7 +495,8 @@ function send_redirect(string $url){ print_end(); } -function send_access_denied(){ +function send_access_denied(): void +{ global $I, $U; http_response_code(403); print_start('access_denied'); @@ -463,7 +506,8 @@ function send_access_denied(){ print_end(); } -function send_captcha(){ +function send_captcha(): void +{ global $I, $db, $memcached; $difficulty=(int) get_setting('captcha'); if($difficulty===0 || !extension_loaded('gd')){ @@ -567,7 +611,8 @@ function send_captcha(){ echo ''.hidden('challenge', $randid).''; } -function send_setup(array $C){ +function send_setup(array $C): void +{ global $I, $U; print_start('setup'); echo "

$I[setup]

".form('setup', 'save'); @@ -765,7 +810,8 @@ function send_setup(array $C){ print_end(); } -function restore_backup(array $C){ +function restore_backup(array $C): void +{ global $db, $memcached; if(!extension_loaded('json')){ return; @@ -834,7 +880,8 @@ function restore_backup(array $C){ } } -function send_backup(array $C){ +function send_backup(array $C): void +{ global $I, $db; $code=[]; if($_POST['do']==='backup'){ @@ -923,7 +970,8 @@ function send_backup(array $C){ print_end(); } -function send_destroy_chat(){ +function send_destroy_chat(): void +{ global $I; print_start('destroy_chat'); echo "'; echo "
$I[confirm]
"; @@ -932,7 +980,8 @@ function send_destroy_chat(){ print_end(); } -function send_delete_account(){ +function send_delete_account(): void +{ global $I; print_start('delete_account'); echo "'; echo "
$I[confirm]
"; @@ -941,7 +990,8 @@ function send_delete_account(){ print_end(); } -function send_init(){ +function send_init(): void +{ global $I, $L; print_start('init'); echo "

$I[init]

"; @@ -958,14 +1008,16 @@ function send_init(){ print_end(); } -function send_update(string $msg){ +function send_update(string $msg): void +{ global $I; print_start('update'); echo "

$I[dbupdate]


".form('setup').submit($I['initgosetup'])."$msg
".credit(); print_end(); } -function send_alogin(){ +function send_alogin(): void +{ global $I, $L; print_start('alogin'); echo form('setup').''; @@ -982,7 +1034,8 @@ function send_alogin(){ print_end(); } -function send_sa_password_reset(){ +function send_sa_password_reset(): void +{ global $I, $L, $db; print_start('sa_password_reset'); echo "

$I[resetpassword]

"; @@ -1007,7 +1060,8 @@ function send_sa_password_reset(){ print_end(); } -function send_admin(string $arg){ +function send_admin(string $arg): void +{ global $I, $U, $db; $ga=(int) get_setting('guestaccess'); print_start('admin'); @@ -1178,7 +1232,8 @@ function send_admin(string $arg){ print_end(); } -function send_sessions(){ +function send_sessions(): void +{ global $I, $U, $db; $stmt=$db->prepare('SELECT nickname, style, lastpost, status, useragent, ip FROM ' . PREFIX . 'sessions WHERE entry!=0 AND (incognito=0 OR statusexecute([$U['status'], $U['nickname']]); @@ -1376,20 +1431,21 @@ function get_linkfilters() : array { return $filters; } -function send_filter(string $arg=''){ +function send_filter(string $arg=''): void +{ global $I, $U; print_start('filter'); echo "

$I[filter]

$arg
"; thr(); - echo ''; } echo ''; + echo "
'; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + echo ''; $filters=get_filters(); foreach($filters as $filter){ @@ -1416,41 +1472,42 @@ function send_filter(string $arg=''){ } echo ''; + echo "
$I[fid]$I[match]$I[replace]$I[allowpm]$I[regex]$I[kick]$I[cs]$I[apply]
'; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; echo '
$I[fid]$I[match]$I[replace]$I[allowpm]$I[regex]$I[kick]$I[cs]$I[apply]
'; echo form('admin', 'filter').hidden('id', $filter['id']); - echo ""; - echo ""; - echo '"; - echo ""; - echo ""; - echo ""; - echo ""; - echo '
$I[filter] $filter[id]:'.submit($I['change']).'
"; + echo ""; + echo '"; + echo ""; + echo ""; + echo ""; + echo ""; + echo '
$I[filter] $filter[id]:'.submit($I['change']).'
'; echo form('admin', 'filter').hidden('id', '+'); - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo '
$I[newfilter]'.submit($I['add']).'
"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo '
$I[newfilter]'.submit($I['add']).'

"; echo form('admin', 'filter').submit($I['reload']).''; print_end(); } -function send_linkfilter(string $arg=''){ +function send_linkfilter(string $arg=''): void +{ global $I, $U; print_start('linkfilter'); echo "

$I[linkfilter]

$arg"; thr(); - echo ''; } echo ''; + echo "
'; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + echo ''; $filters=get_linkfilters(); foreach($filters as $filter){ @@ -1462,25 +1519,26 @@ function send_linkfilter(string $arg=''){ } echo ''; + echo "
$I[fid]$I[match]$I[replace]$I[regex]$I[apply]
'; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; echo '
$I[fid]$I[match]$I[replace]$I[regex]$I[apply]
'; echo form('admin', 'linkfilter').hidden('id', $filter['id']); - echo ""; - echo ""; - echo '"; - echo ""; - echo '
$I[filter] $filter[id]:'.submit($I['change']).'
"; + echo ""; + echo '"; + echo ""; + echo '
$I[filter] $filter[id]:'.submit($I['change']).'
'; echo form('admin', 'linkfilter').hidden('id', '+'); - echo ""; - echo ""; - echo ""; - echo ""; - echo '
$I[newfilter]'.submit($I['add']).'
"; + echo ""; + echo ""; + echo ""; + echo '
$I[newfilter]'.submit($I['add']).'

"; echo form('admin', 'linkfilter').submit($I['reload']).''; print_end(); } -function send_frameset(){ +function send_frameset(): void +{ global $U, $db, $language; prepare_stylesheets('frameset'); send_headers(); @@ -1504,11 +1562,6 @@ function send_frameset(){ $stmt->execute([$U['sortupdown'], $U['nocache'], $U['nocache_old'], $U['nickname']]); } } - if(($U['status']>=5 || ($U['status']>2 && get_count_mods()==0)) && get_setting('enfileupload')>0 && get_setting('enfileupload')<=$U['status']){ - $postheight='120px'; - }else{ - $postheight='100px'; - } $bottom=''; if(get_setting('enablegreeting')){ $action_mid='greeting'; @@ -1522,20 +1575,14 @@ function send_frameset(){ $action_top='post'; $action_bot='controls'; $sort_bot='&sort=1'; - $frameset_mid_style="position:fixed;top:$postheight;bottom:45px;left:0;right:0;margin:0;padding:0;overflow:hidden;"; - $frameset_top_style="position:fixed;top:0;left:0;right:0;height:$postheight;margin:0;padding:0;overflow:hidden;border-bottom: 1px solid;"; - $frameset_bot_style="position:fixed;bottom:0;left:0;right:0;height:45px;margin:0;padding:0;overflow:hidden;border-top:1px solid;"; }else{ $action_top='controls'; $action_bot='post'; $sort_bot=''; - $frameset_mid_style="position:fixed;top:45px;bottom:$postheight;left:0;right:0;margin:0;padding:0;overflow:hidden;"; - $frameset_top_style="position:fixed;top:0;left:0;right:0;height:45px;margin:0;padding:0;overflow:hidden;border-bottom:1px solid;"; - $frameset_bot_style="position:fixed;bottom:0;left:0;right:0;height:$postheight;margin:0;padding:0;overflow:hidden;border-top:1px solid;"; - } - echo "
"; - echo "
"; - echo "
"; + } + echo "
"; + echo "
"; + echo "
"; echo ''; exit; } @@ -1545,7 +1592,8 @@ function noframe_html() : string { return "$I[noframes]".form_target('_parent', '').submit($I['backtologin'], 'class="backbutton"').''; } -function send_messages(){ +function send_messages(): void +{ global $I, $U, $language; if($U['nocache']){ $nocache='&nc='.substr(time(), -6); @@ -1580,7 +1628,8 @@ function send_messages(){ print_end(); } -function send_inbox(){ +function send_inbox(): void +{ global $I, $U, $db; print_start('inbox'); echo form('inbox', 'clean').submit($I['delselmes'], 'class="delbutton"').'

'; @@ -1614,7 +1663,8 @@ function send_inbox(){ print_end(); } -function send_notes(int $type){ +function send_notes(int $type): void +{ global $I, $U, $db; print_start('notes'); $personalnotes=(bool) get_setting('personalnotes'); @@ -1712,7 +1762,8 @@ function send_notes(int $type){ print_end(); } -function send_approve_waiting(){ +function send_approve_waiting(): void +{ global $I, $db; print_start('approve_waiting'); echo "

$I[waitingroom]

"; @@ -1739,7 +1790,8 @@ function send_approve_waiting(){ print_end(); } -function send_waiting_room(){ +function send_waiting_room(): void +{ global $I, $U, $db, $language; $ga=(int) get_setting('guestaccess'); if($ga===3 && (get_count_mods()>0 || !get_setting('modfallback'))){ @@ -1781,7 +1833,8 @@ function send_waiting_room(){ } } -function send_choose_messages(){ +function send_choose_messages(): void +{ global $I, $U; print_start('choose_messages'); echo form('admin', 'clean'); @@ -1791,7 +1844,8 @@ function send_choose_messages(){ print_end(); } -function send_del_confirm(){ +function send_del_confirm(): void +{ global $I; print_start('del_confirm'); echo "
$I[confirm]
".form('delete'); @@ -1812,7 +1866,8 @@ function send_del_confirm(){ print_end(); } -function send_post(string $rejected=''){ +function send_post(string $rejected=''): void +{ global $I, $U, $db; print_start('post'); if(!isset($_REQUEST['sendto'])){ @@ -1899,7 +1954,7 @@ function send_post(string $rejected=''){ echo hidden('multi', 'on'); } echo hidden('sendto', htmlspecialchars($_REQUEST['sendto'])).hidden('what', 'all'); - echo submit($I['delall'], 'class="delbutton"').''.form('post'); + echo submit($I['delall'], 'class="delbutton"').''.form('post'); if(isset($_POST['multi'])){ echo submit($I['switchsingle']); }else{ @@ -1910,7 +1965,8 @@ function send_post(string $rejected=''){ print_end(); } -function send_greeting(){ +function send_greeting(): void +{ global $I, $U, $language; print_start('greeting', (int) $U['refresh'], "$_SERVER[SCRIPT_NAME]?action=view&session=$U[session]&lang=$language"); printf("

$I[greetingmsg]

", style_this(htmlspecialchars($U['nickname']), $U['style'])); @@ -1922,7 +1978,8 @@ function send_greeting(){ print_end(); } -function send_help(){ +function send_help(): void +{ global $I, $U; print_start('help'); $rulestxt=get_setting('rulestxt'); @@ -1946,7 +2003,8 @@ function send_help(){ print_end(); } -function view_publicnotes(){ +function view_publicnotes(): void +{ global $I, $db; $dateformat = get_setting('dateformat'); print_start('publicnotes'); @@ -1971,7 +2029,8 @@ function view_publicnotes(){ print_end(); } -function send_profile(string $arg=''){ +function send_profile(string $arg=''): void +{ global $I, $L, $U, $db, $language; print_start('profile'); echo form('profile', 'save')."

$I[profile]

$arg"; @@ -2119,7 +2178,8 @@ function send_profile(string $arg=''){ print_end(); } -function send_controls(){ +function send_controls(): void +{ global $I, $U; print_start('controls'); $personalnotes=(bool) get_setting('personalnotes'); @@ -2177,7 +2237,8 @@ function send_controls(){ print_end(); } -function send_download(){ +function send_download(): void +{ global $I, $db; if(isset($_GET['id'])){ $stmt=$db->prepare('SELECT filename, type, data FROM ' . PREFIX . 'files WHERE hash=?;'); @@ -2198,14 +2259,16 @@ function send_download(){ } } -function send_logout(){ +function send_logout(): void +{ global $I, $U; print_start('logout'); echo '

'.sprintf($I['bye'], style_this(htmlspecialchars($U['nickname']), $U['style'])).'

'.form_target('_parent', '').submit($I['backtologin'], 'class="backbutton"').''; print_end(); } -function send_colours(){ +function send_colours(): void +{ global $I; print_start('colours'); echo "

$I[colourtable]

"; @@ -2223,7 +2286,8 @@ function send_colours(){ print_end(); } -function send_login(){ +function send_login(): void +{ global $I, $L; $ga=(int) get_setting('guestaccess'); if($ga===4){ @@ -2278,20 +2342,23 @@ function send_login(){ print_end(); } -function send_chat_disabled(){ +function send_chat_disabled(): void +{ print_start('disabled'); echo get_setting('disabletext'); print_end(); } -function send_error(string $err){ +function send_error(string $err): void +{ global $I; print_start('error'); echo "

$I[error]: $err

".form_target('_parent', '').submit($I['backtologin'], 'class="backbutton"').''; print_end(); } -function send_fatal_error(string $err){ +function send_fatal_error(string $err): void +{ global $I, $language, $styles; prepare_stylesheets('fatal_error'); send_headers(); @@ -2303,7 +2370,8 @@ function send_fatal_error(string $err){ print_end(); } -function print_notifications(){ +function print_notifications(): void +{ global $I, $U, $db; echo ''; $stmt=$db->prepare('SELECT loginfails FROM ' . PREFIX . 'members WHERE nickname=?;'); @@ -2332,7 +2400,8 @@ function print_notifications(){ echo ''; } -function print_chatters(){ +function print_chatters(): void +{ global $I, $U, $db, $language; if(!$U['hidechatters']){ echo '
'; @@ -2340,8 +2409,8 @@ function print_chatters(){ $stmt->execute([$U['nickname'], $U['nickname']]); $nc=substr(time(), -6); $G=$M=$S=$A=[]; - $channellink="fetch(PDO::FETCH_NUM)){ $link=$nicklink.urlencode($user[0]).'" target="post">'.style_this(htmlspecialchars($user[0]), $user[1]).''; if($user[2]<3){ // guest or superguest @@ -2360,23 +2429,24 @@ function print_chatters(){ echo "'; } if($U['status']>4){ // can chat in staff channel - echo ''; + echo ''; } else { - echo "'; + echo "'; } if($U['status']>=3){ // can chat in member channel - echo ''; + echo ''; } else { - echo "'; + echo "'; } - echo ''; + echo ''; echo '
$I[admin]: ".implode('   ', $A).'
' . $channellink . 's %" target="post">' . $I['staff'] . ':
 '.implode('   ', $S).'' . $channellink . 's %" target="post">' . $I['staff'] . ': '.implode('   ', $S).'
$I[staff]:
 ".implode('   ', $S).'$I[staff]: ".implode('   ', $S).'' . $channellink . 's ?" target="post">
' . $I['members'] . ':
 '.implode('   ', $M).'' . $channellink . 's ?" target="post">' . $I['members'] . ': '.implode('   ', $M).'
$I[members]:
 ".implode('   ', $M).'$I[members]: ".implode('   ', $M).'' . $channellink . 's *" target="post">
' . $I['guests'] . ':
 '.implode('   ', $G).'' . $channellink . 's *" target="post">' . $I['guests'] . ': '.implode('   ', $G).'
'; } } // session management -function create_session(bool $setup, string $nickname, string $password){ +function create_session(bool $setup, string $nickname, string $password): void +{ global $I, $U; $U['nickname']=preg_replace('/\s/', '', $nickname); if(check_member($password)){ @@ -2411,7 +2481,8 @@ function create_session(bool $setup, string $nickname, string $password){ write_new_session($password); } -function check_captcha(string $challenge, string $captcha_code){ +function check_captcha(string $challenge, string $captcha_code): void +{ global $I, $db, $memcached; $captcha=(int) get_setting('captcha'); if($captcha!==0){ @@ -2456,7 +2527,8 @@ function is_definitely_ssl() : bool { return false; } -function set_secure_cookie(string $name, string $value){ +function set_secure_cookie(string $name, string $value): void +{ if (version_compare(PHP_VERSION, '7.3.0') >= 0) { setcookie($name, $value, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => is_definitely_ssl(), 'httponly' => true, 'samesite' => 'Strict']); }else{ @@ -2464,7 +2536,8 @@ function set_secure_cookie(string $name, string $value){ } } -function write_new_session(string $password){ +function write_new_session(string $password): void +{ global $I, $U, $db, $session; $stmt=$db->prepare('SELECT * FROM ' . PREFIX . 'sessions WHERE nickname=?;'); $stmt->execute([$U['nickname']]); @@ -2508,7 +2581,8 @@ function write_new_session(string $password){ } } -function show_fails() { +function show_fails(): void +{ global $db, $I, $U; $stmt=$db->prepare('SELECT loginfails FROM ' . PREFIX . 'members WHERE nickname=?;'); $stmt->execute([$U['nickname']]); @@ -2523,7 +2597,8 @@ function show_fails() { } } -function approve_session(){ +function approve_session(): void +{ global $db; if(isset($_POST['what'])){ if($_POST['what']==='allowchecked' && isset($_POST['csid'])){ @@ -2552,7 +2627,8 @@ function approve_session(){ } } -function check_login(){ +function check_login(): void +{ global $I, $U; $ga=(int) get_setting('guestaccess'); parse_sessions(); @@ -2588,7 +2664,8 @@ function check_login(){ } } -function kill_session(){ +function kill_session(): void +{ global $U, $db, $session; parse_sessions(); check_expired(); @@ -2645,7 +2722,8 @@ function kick_chatter(array $names, string $mes, bool $purge) : bool { return false; } -function logout_chatter(array $names){ +function logout_chatter(array $names): void +{ global $U, $db; $stmt=$db->prepare('DELETE FROM ' . PREFIX . 'sessions WHERE nickname=? AND statusquery('SELECT COUNT(*) FROM ' . PREFIX . 'sessions WHERE entry!=0 AND status>0 AND incognito=0;'); @@ -2709,7 +2791,8 @@ function get_nowchatting(){ echo ''; } -function parse_sessions(){ +function parse_sessions(): void +{ global $U, $db, $session; // look for our session if(!empty($session)){ @@ -2752,7 +2835,8 @@ function check_member(string $password) : bool { return false; } -function delete_account(){ +function delete_account(): void +{ global $U, $db; if($U['status']<8){ $stmt=$db->prepare('UPDATE ' . PREFIX . 'sessions SET status=1, incognito=0 WHERE nickname=?;'); @@ -2891,7 +2975,8 @@ function passreset(string $nick, string $pass) : string { } } -function amend_profile(){ +function amend_profile(): void +{ global $U; if(isset($_POST['refresh'])){ $U['refresh']=$_POST['refresh']; @@ -3043,7 +3128,8 @@ function set_new_nickname() : string { } //sets default settings for guests -function add_user_defaults(string $password){ +function add_user_defaults(string $password): void +{ global $U; $U['refresh']=get_setting('defaultrefresh'); $U['bgcolour']=get_setting('colbg'); @@ -3356,7 +3442,8 @@ function add_message(string $message, string $recipient, string $poster, int $de return true; } -function add_system_message(string $mes, string $doer){ +function add_system_message(string $mes, string $doer): void +{ if($mes===''){ return; } @@ -3383,7 +3470,8 @@ function add_system_message(string $mes, string $doer){ write_message($sysmessage); } -function write_message($message){ +function write_message(array $message): void +{ global $db; if(MSGENCRYPTED){ try { @@ -3402,13 +3490,15 @@ function write_message($message){ } } -function clean_room(){ +function clean_room(): void +{ global $U, $db; $db->query('DELETE FROM ' . PREFIX . 'messages;'); add_system_message(sprintf(get_setting('msgclean'), get_setting('chatname')), $U['nickname']); } -function clean_selected(int $status, string $nick){ +function clean_selected(int $status, string $nick): void +{ global $db; if(isset($_POST['mid'])){ $stmt=$db->prepare('DELETE FROM ' . PREFIX . 'messages WHERE id=? AND (poster=? OR recipient=? OR (poststatusprepare('DELETE FROM ' . PREFIX . 'inbox WHERE id=? AND recipient=?;'); @@ -3428,7 +3519,8 @@ function clean_inbox_selected(){ } } -function del_all_messages(string $nick, int $entry){ +function del_all_messages(string $nick, int $entry): void +{ global $db, $U; $globally = (bool) get_setting('postbox_delete_globally'); if($globally && $U['status'] > 4){ @@ -3445,7 +3537,8 @@ function del_all_messages(string $nick, int $entry){ } } -function del_last_message(){ +function del_last_message(): void +{ global $U, $db; if($U['status']>1){ $entry=0; @@ -3468,7 +3561,8 @@ function del_last_message(){ } } -function print_messages(int $delstatus=0){ +function print_messages(int $delstatus=0): void +{ global $I, $U, $db; $dateformat=get_setting('dateformat'); if(!$U['embed'] && get_setting('imgembed')){ @@ -3525,7 +3619,8 @@ function print_messages(int $delstatus=0){ echo ''; } -function prepare_message_print(array &$message, bool $removeEmbed){ +function prepare_message_print(array &$message, bool $removeEmbed): void +{ if(MSGENCRYPTED){ try { $message['text']=sodium_crypto_aead_aes256gcm_decrypt(base64_decode($message['text']), null, AES_IV, ENCRYPTKEY); @@ -3544,7 +3639,8 @@ function prepare_message_print(array &$message, bool $removeEmbed){ // this and that -function send_headers(){ +function send_headers(): void +{ global $U, $scripts, $styles; header('Content-Type: text/html; charset=UTF-8'); header('Pragma: no-cache'); @@ -3574,7 +3670,8 @@ function send_headers(){ } } -function save_setup(array $C){ +function save_setup(array $C): void +{ global $db; //sanity checks and escaping foreach($C['msg_settings'] as $setting){ @@ -3647,7 +3744,8 @@ function save_setup(array $C){ } } -function set_default_tz(){ +function set_default_tz(): void +{ global $U; if(isset($U['tz'])){ date_default_timezone_set($U['tz']); @@ -3691,7 +3789,8 @@ function valid_regex(string &$regex) : bool { return (@preg_match("/$_POST[match]/u", '') !== false); } -function get_timeout(int $lastpost, int $expire){ +function get_timeout(int $lastpost, int $expire): void +{ $s=($lastpost+60*$expire)-time(); $m=floor($s/60); $s%=60; @@ -3710,7 +3809,8 @@ function get_timeout(int $lastpost, int $expire){ } } -function print_colours(){ +function print_colours(): void +{ global $I; // Prints a short list with selected named HTML colours and filters out illegible text colours for the given background. // It's a simple comparison of weighted grey values. This is not very accurate but gets the job done well enough. @@ -3743,7 +3843,8 @@ function check_init() : bool { } // run every minute doing various database cleanup task -function cron(){ +function cron(): void +{ global $db; $time=time(); if(get_setting('nextcron')>$time){ @@ -3808,7 +3909,8 @@ function cron(){ $db->query('DELETE FROM ' . PREFIX . 'notes WHERE (type=2 OR type=3) AND editedby NOT IN (SELECT nickname FROM ' . PREFIX . 'members);'); } -function destroy_chat(array $C){ +function destroy_chat(array $C): void +{ global $I, $db, $memcached, $session; setcookie(COOKIENAME, false); $session = ''; @@ -3839,9 +3941,9 @@ function destroy_chat(array $C){ print_end(); } -function init_chat(){ +function init_chat(): void +{ global $I, $db; - $suwrite=''; if(check_init()){ $suwrite=$I['initdbexist']; $result=$db->query('SELECT null FROM ' . PREFIX . 'members WHERE status=8;'); @@ -4021,7 +4123,8 @@ function init_chat(){ print_end(); } -function update_db(){ +function update_db(): void +{ global $I, $db, $memcached; $dbversion=(int) get_setting('dbversion'); $msgencrypted=(bool) get_setting('msgencrypted'); @@ -4418,7 +4521,8 @@ function get_setting(string $setting) : string { return $value; } -function update_setting(string $setting, $value){ +function update_setting(string $setting, $value): void +{ global $db, $memcached; $stmt=$db->prepare('UPDATE ' . PREFIX . 'settings SET value=? WHERE setting=?;'); $stmt->execute([$value, $setting]); @@ -4429,7 +4533,8 @@ function update_setting(string $setting, $value){ // configuration, defaults and internals -function check_db(){ +function check_db(): void +{ global $I, $db, $memcached; $options=[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT=>PERSISTENT]; try{ @@ -4517,7 +4622,8 @@ function load_fonts() : array { ]; } -function load_lang(){ +function load_lang(): void +{ global $I, $L, $language; $L=[ 'ar' =>'العربية', @@ -4558,7 +4664,8 @@ function load_lang(){ } } -function load_config(){ +function load_config(): void +{ mb_internal_encoding('UTF-8'); define('VERSION', '1.24.1'); // Script version define('DBVERSION', 47); // Database layout version