From 30260b75301e54beb76368d96dd9b15b073e259e Mon Sep 17 00:00:00 2001 From: Xkeeper Date: Sat, 29 Mar 2025 12:32:35 -0700 Subject: [PATCH] more php 8 fixes --- editprofile.php | 4 +- index.php | 16 +++-- lib/function.php | 161 +++---------------------------------------- lib/mysql_compat.php | 2 +- lib/reporting.php | 149 +++++++++++++++++++++++++++++++++++++++ lib/threadpost.php | 2 +- login.php | 2 +- profile.php | 2 +- 8 files changed, 175 insertions(+), 163 deletions(-) create mode 100644 lib/reporting.php diff --git a/editprofile.php b/editprofile.php index 4ace254..bd40db7 100644 --- a/editprofile.php +++ b/editprofile.php @@ -6,7 +6,7 @@ if($loguser['profile_locked'] == 1) { errorpage("You are not allowed to edit your profile."); } - if($loguser['posts']>=500 or ($loguser[posts]>=250 && (ctime()-$loguser[regdate])>=100*86400)) $postreq=1; + if($loguser['posts']>=500 or ($loguser['posts']>=250 && (ctime()-$loguser['regdate'])>=100*86400)) $postreq=1; if($loguser['titleoption']==0 || $banned) $titleopt=0; if($loguser['titleoption']==1 && ($postreq or $power>0 or $loguser[title])) $titleopt=1; if($loguser['titleoption']==2) $titleopt=1; @@ -233,7 +233,7 @@ $title=preg_replace("'(face|style|class|size|id)=([^ ].*?)'si", '', $title); } $title = addslashes($title); - + $bio=preg_replace("'nload', $bio); diff --git a/index.php b/index.php index f60af5c..acca85c 100644 --- a/index.php +++ b/index.php @@ -63,12 +63,13 @@ $blist.= "$userurl ($y)"; } - $onlinetime=ctime()-300; - $onusers=$sql->query("SELECT id,name,powerlevel,lastactivity,sex,minipic,aka,birthday FROM users WHERE lastactivity>$onlinetime OR lastposttime>$onlinetime ORDER BY name"); - $numonline=mysql_num_rows($onusers); + $onlinetime = ctime()-300; + $onusers = $sql->query("SELECT id,name,powerlevel,lastactivity,sex,minipic,aka,birthday FROM users WHERE lastactivity > $onlinetime OR lastposttime > $onlinetime ORDER BY name"); + $numonline = mysql_num_rows($onusers); - $numguests=$sql->resultq("SELECT count(*) FROM guests WHERE date>$onlinetime",0,0); - if ($numguests) $guestcount=" | $numguests guest".($numguests>1?"s":""); + $numguests = $sql->resultq("SELECT count(*) FROM guests WHERE date>$onlinetime",0,0); + $guestcount = ""; + if ($numguests) $guestcount = " | $numguests guest".($numguests>1?"s":""); $onlineusersa = array(); for ($numon=0; $onuser = $sql->fetch($onusers);$numon++) { @@ -149,7 +150,8 @@ $pms = $sql->getresultsbykey("SELECT msgread, COUNT(*) num FROM pmsgs WHERE userto=$loguserid GROUP BY msgread", 'msgread', 'num'); $pms[0] = intval($pms[0] ?? 0); // unread $pms[1] = intval($pms[1] ?? 0); // read - $totalpms = $pms[0] + $pms[1]; + $totalpms = $pms[0] + $pms[1]; + $lastmsg = ""; if ($totalpms) { if ($pms[0]) $new = $statusicons['new']; @@ -250,7 +252,7 @@ // Quicker (?) new posts calculation that's hopefully accurate v.v if ($log) { $qadd = array(); - foreach ($forums as $forum) $qadd[] = "(lastpostdate > '{$postread[$forum['id']]}' AND forum = '{$forum['id']}')\r\n"; + foreach ($forums as $forum) $qadd[] = "(lastpostdate > '". ($postread[$forum['id']] ?? 0) ."' AND forum = '{$forum['id']}')\r\n"; $qadd = implode(' OR ', $qadd); $forumnew = $sql->getresultsbykey("SELECT forum, COUNT(*) AS unread FROM threads t LEFT JOIN threadsread tr ON (tr.tid = t.id AND tr.uid = $loguser[id]) diff --git a/lib/function.php b/lib/function.php index 6a9ca98..eb79149 100644 --- a/lib/function.php +++ b/lib/function.php @@ -20,6 +20,7 @@ require 'lib/config.php'; require 'lib/mysql.php'; + require 'lib/reporting.php'; if (isset($board_timezone)) { date_default_timezone_set($board_timezone); @@ -348,7 +349,7 @@ function timeunits2($sec){ } function calcexpgainpost($posts,$days) {return @floor(1.5*@pow($posts*$days,0.5));} -function calcexpgaintime($posts,$days) {return sprintf('%01.3f',172800*@(@pow(@($days/$posts),0.5)/$posts));} +function calcexpgaintime($posts,$days) {return ($posts == 0 ? 0 : sprintf('%01.3f',172800*@(@pow(@($days/$posts),0.5)/$posts)));} function calcexpleft($exp) {return calclvlexp(calclvl($exp)+1)-$exp;} function totallvlexp($lvl) {return calclvlexp($lvl+1)-calclvlexp($lvl);} @@ -407,6 +408,7 @@ function generatenumbergfx($num,$minlen=0,$double=false){ function dotags($msg, $user, &$tags = array()) { global $sql, $dateformat, $tzoff; + if (!is_string($msg)) return ""; if (is_string($tags)) { $tags = json_decode($tags, true); } @@ -604,8 +606,8 @@ function doforumlist($id){ return $forumlinks; } -function ctime(){return time(); } // +3*3600;} -function cmicrotime(){return microtime(true); } // +3*3600;} +function ctime(){return time() - 3*3600; } // +3*3600;} +function cmicrotime(){return microtime(true) - 3*3600; } // +3*3600;} function getrank($rankset,$title,$posts,$powl){ global $hacks, $sql; @@ -787,7 +789,7 @@ function getuserlink(&$u, $substitutions = null, $urlclass = '') { ? " title='Also known as: {$akafield}'" : ''); } - $u[$fn['name']] = htmlspecialchars($u[$fn['name']], ENT_QUOTES); + $u[$fn['name']] = htmlspecialchars($u[$fn['name']] ?? "", ENT_QUOTES); global $tzoff; $birthday = ($u[$fn['birthday']] ?? null) && (date('m-d', $u[$fn['birthday']]) == date('m-d',ctime() + $tzoff)); @@ -903,7 +905,7 @@ function getnamecolor($sex, $powl, $prefix = true){ case 96: // Kak - Witch $namecolor .= $nmcol[2][3]; break; // Make it readable in case the user has a light theme default: - $namecolor .= $nmcol[$sex][$powl]; + $namecolor .= $nmcol[$sex][$powl] ?? $nmcol[0][2]; break; } @@ -933,7 +935,7 @@ function fonlineusers($id){ $namelink = getuserlink($onuser); $onlineusers .=''; - $onuser['minipic'] =str_replace('>','>',$onuser['minipic']); + $onuser['minipic'] =str_replace('>','>',$onuser['minipic'] ?? ""); if($onuser['minipic']) $onlineusers .=" "; if($onuser['lastactivity'] <=$onlinetime) $namelink="($namelink)"; $onlineusers .="$namelink"; @@ -985,6 +987,7 @@ function postradar($userid){ global $sql, $loguser, $loguserid; if (!$userid) return ""; + $race = ""; //$postradar = $sql->query("SELECT posts,id,name,aka,sex,powerlevel,birthday FROM users u RIGHT JOIN postradar p ON u.id=p.comp WHERE p.user={$userid} ORDER BY posts DESC", MYSQL_ASSOC); $postradar = $sql->query("SELECT posts,id,name,aka,sex,powerlevel,birthday FROM users,postradar WHERE postradar.user={$userid} AND users.id=postradar.comp ORDER BY posts DESC", MYSQL_ASSOC); if (@mysql_num_rows($postradar)>0) { @@ -1344,117 +1347,14 @@ function addslashes_array($data) { $data[$key] = addslashes_array($value); } return $data; + } elseif (is_null($data)) { + return ""; } else { return addslashes($data); } } - function report($type, $msg) { - if (!function_exists('get_discord_webhook')) return; - - $wh_url = get_discord_webhook($type, null); - - if (!$wh_url) return; - - discord_send($wh_url, $outdiscord); - } - - // general purpose report function, now with discord! - function xk_ircout($type, $user, $in) { - - // gone - // return; - # and back - - $dest = min(1, max(0, $in['pow'])); - if ($in['fid'] == 99) { - $dest = 6; - } elseif ($in['fid'] == 98) { - $dest = 7; - } - - global $x_hacks; - - if ($type == "user") { - if ($in['pmatch']) { - $color = array(8, 7); - if ($in['pmatch'] >= 3) $color = array(7, 4); - elseif ($in['pmatch'] >= 5) $color = array(4, 5); - $extra = " (". xk($color[1]) ."Password matches: ". xk($color[0]) . $in['pmatch'] . xk() .")"; - $extradiscord = " (**Password matches**: " . $in['pmatch'] . ")"; - } - - $out = "1|New user: #". xk(12) . $in['id'] . xk(11) ." $user ". xk() ."(IP: ". xk(12) . $in['ip'] . xk() .")$extra: https://jul.rustedlogic.net/?u=". $in['id']; - $outdiscord = "New user: **#" . $in['id'] . "** ". $user . " (IP: " . $in['ip'] . ")$extra: "; - - } else { -// global $sql; -// $res = $sql -> resultq("SELECT COUNT(`id`) FROM `posts`"); - $out = "$dest|New $type by ". xk(11) . $user . xk() ." (". xk(12) . $in['forum'] .": ". xk(11) . $in['thread'] . xk() ."): https://jul.rustedlogic.net/?p=". $in['pid']; - $outdiscord = "New $type by **" . $user . "** (" . $in['forum'] . ": **" . $in['thread'] . "**): "; - - } - - xk_ircsend($out); - - // discord part - - // logic to decide where the message goes based on info provided - if (!function_exists('get_discord_webhook')) return; - - $wh_url = get_discord_webhook($type, $in); - - if (!$wh_url) return; - - discord_send($wh_url, $outdiscord); - - } - - function xk_ircsend($str) { - $str = str_replace(array("%10", "%13"), array("", ""), rawurlencode($str)); - - $str = html_entity_decode($str); - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, "http://treeki.rustedlogic.net:5000/reporting.php?t=$str"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // <---- HERE - curl_setopt($ch, CURLOPT_TIMEOUT, 5); // <---- HERE - $file_contents = curl_exec($ch); - curl_close($ch); - - return true; - } - - function discord_send($url, $msg) { - // stripped down from https://gist.github.com/Mo45/cb0813cb8a6ebcd6524f6a36d4f8862c - $json_data = json_encode([ - "content" => $msg - ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - - - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - - $response = curl_exec($ch); - // echo $response; - curl_close($ch); - - return true; - } - - function xk($n = -1) { - if ($n == -1) $k = ""; - else $k = str_pad($n, 2, 0, STR_PAD_LEFT); - return "\x03". $k; - } - function formatting_trope($input) { $in = "/[A-Z][^A-Z]/"; $out = " \\0"; @@ -1586,42 +1486,3 @@ function printtimedif($timestart){ */ } - -function ircerrors($type, $msg, $file, $line, $context) { - global $loguser; - - // They want us to shut up? (@ error control operator) Shut the fuck up then! - if (!error_reporting()) - return true; - - switch($type) { - case E_USER_ERROR: $typetext = xk(4) . "- Error"; break; - case E_USER_WARNING: $typetext = xk(7) . "- Warning"; break; - case E_USER_NOTICE: $typetext = xk(8) . "- Notice"; break; - default: return false; - } - - // Get the ACTUAL location of error for mysql queries - if ($type == E_USER_ERROR && substr($file, -9) === "mysql.php") { - $backtrace = debug_backtrace(); - for ($i = 1; isset($backtrace[$i]); ++$i) { - if (substr($backtrace[$i]['file'], -9) !== "mysql.php") { - $file = $backtrace[$i]['file']; - $line = $backtrace[$i]['line']; - break; - } - } - } - // Get the location of error for deprecation - elseif ($type == E_USER_NOTICE && substr($msg, 0, 10) === "Deprecated") { - $backtrace = debug_backtrace(); - $file = $backtrace[2]['file']; - $line = $backtrace[2]['line']; - } - - $errorlocation = str_replace($_SERVER['DOCUMENT_ROOT'], "", $file) ." #$line"; - - xk_ircsend("102|".($loguser['id'] ? xk(11) . $loguser['name'] .' ('. xk(10) . $_SERVER['REMOTE_ADDR'] . xk(11) . ')' : xk(10) . $_SERVER['REMOTE_ADDR']) . - " $typetext: ".xk()."($errorlocation) $msg"); - return true; -} diff --git a/lib/mysql_compat.php b/lib/mysql_compat.php index 7b0023d..88a64e7 100644 --- a/lib/mysql_compat.php +++ b/lib/mysql_compat.php @@ -68,7 +68,7 @@ namespace { return false; } \Dshafik\MySQL::$last_connection = $conn; - $conn->hash = $hash; + @$conn->hash = $hash; \Dshafik\MySQL::$connections[$hash] = array('refcount' => 1, 'conn' => $conn); return $conn; diff --git a/lib/reporting.php b/lib/reporting.php new file mode 100644 index 0000000..20662c9 --- /dev/null +++ b/lib/reporting.php @@ -0,0 +1,149 @@ += 3) $color = array(7, 4); + elseif ($in['pmatch'] >= 5) $color = array(4, 5); + $extra = " (". xk($color[1]) ."Password matches: ". xk($color[0]) . $in['pmatch'] . xk() .")"; + $extradiscord = " (**Password matches**: " . $in['pmatch'] . ")"; + } + + $out = "1|New user: #". xk(12) . $in['id'] . xk(11) ." $user ". xk() ."(IP: ". xk(12) . $in['ip'] . xk() .")$extra: https://jul.rustedlogic.net/?u=". $in['id']; + $outdiscord = "New user: **#" . $in['id'] . "** ". $user . " (IP: " . $in['ip'] . ")$extra: "; + + } else { +// global $sql; +// $res = $sql -> resultq("SELECT COUNT(`id`) FROM `posts`"); + $out = "$dest|New $type by ". xk(11) . $user . xk() ." (". xk(12) . $in['forum'] .": ". xk(11) . $in['thread'] . xk() ."): https://jul.rustedlogic.net/?p=". $in['pid']; + $outdiscord = "New $type by **" . $user . "** (" . $in['forum'] . ": **" . $in['thread'] . "**): "; + + } + + xk_ircsend($out); + + // discord part + + // logic to decide where the message goes based on info provided + if (!function_exists('get_discord_webhook')) return; + + $wh_url = get_discord_webhook($type, $in); + + if (!$wh_url) return; + + discord_send($wh_url, $outdiscord); + + } + + function xk_ircsend($str) { + $str = str_replace(array("%10", "%13"), array("", ""), rawurlencode($str)); + + $str = html_entity_decode($str); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "http://treeki.rustedlogic.net:5000/reporting.php?t=$str"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); // <---- HERE + curl_setopt($ch, CURLOPT_TIMEOUT, 5); // <---- HERE + $file_contents = curl_exec($ch); + curl_close($ch); + + return true; + } + + function discord_send($url, $msg) { + // stripped down from https://gist.github.com/Mo45/cb0813cb8a6ebcd6524f6a36d4f8862c + $json_data = json_encode([ + "content" => $msg + ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + + + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + + $response = curl_exec($ch); + // echo $response; + curl_close($ch); + + return true; + } + + function xk($n = -1) { + if ($n == -1) $k = ""; + else $k = str_pad($n, 2, 0, STR_PAD_LEFT); + return "\x03". $k; + } + + + +function ircerrors($type, $msg, $file, $line, $context) { + global $loguser; + + // They want us to shut up? (@ error control operator) Shut the fuck up then! + if (!error_reporting()) + return true; + + switch($type) { + case E_USER_ERROR: $typetext = xk(4) . "- Error"; break; + case E_USER_WARNING: $typetext = xk(7) . "- Warning"; break; + case E_USER_NOTICE: $typetext = xk(8) . "- Notice"; break; + default: return false; + } + + // Get the ACTUAL location of error for mysql queries + if ($type == E_USER_ERROR && substr($file, -9) === "mysql.php") { + $backtrace = debug_backtrace(); + for ($i = 1; isset($backtrace[$i]); ++$i) { + if (substr($backtrace[$i]['file'], -9) !== "mysql.php") { + $file = $backtrace[$i]['file']; + $line = $backtrace[$i]['line']; + break; + } + } + } + // Get the location of error for deprecation + elseif ($type == E_USER_NOTICE && substr($msg, 0, 10) === "Deprecated") { + $backtrace = debug_backtrace(); + $file = $backtrace[2]['file']; + $line = $backtrace[2]['line']; + } + + $errorlocation = str_replace($_SERVER['DOCUMENT_ROOT'], "", $file) ." #$line"; + + xk_ircsend("102|".($loguser['id'] ? xk(11) . $loguser['name'] .' ('. xk(10) . $_SERVER['REMOTE_ADDR'] . xk(11) . ')' : xk(10) . $_SERVER['REMOTE_ADDR']) . + " $typetext: ".xk()."($errorlocation) $msg"); + return true; +} diff --git a/lib/threadpost.php b/lib/threadpost.php index 9d628d7..2d33ef9 100644 --- a/lib/threadpost.php +++ b/lib/threadpost.php @@ -11,7 +11,7 @@ $userlink = getuserlink($post, array('id'=>'uid'), $linkclass); unset($postuser); - $set['userrank'] = getrank($post['useranks'],str_replace("idiot", $post['title']),$post['posts'],$post['powerlevel']); + $set['userrank'] = getrank($post['useranks'],str_replace("idiot", $post['title'] ?? ""),$post['posts'],$post['powerlevel']); $set['userlink'] = "{$userlink}"; $set['date'] = date($dateformat,$post['date']+$tzoff); diff --git a/login.php b/login.php index 4725d8e..bc83167 100644 --- a/login.php +++ b/login.php @@ -107,7 +107,7 @@ MSG; $tccellh width=40%>  $tccell1>User name: - $tccell2l>$inpt=username maxlength=25 style='width:280px;' ". (!$username ? "autofocus='1' " : "") ."tabindex='1' value=\"". htmlspecialchars($username) ."\"> + $tccell2l>$inpt=username maxlength=25 style='width:280px;' ". (!$username ? "autofocus='1' " : "") ."tabindex='1' value=\"". htmlspecialchars($username ?? "") ."\"> $tccell1 rowspan=2>IP Verification: $tccell2l rowspan=2>