Standarize some variables and address some php warnings.

This commit is contained in:
Retro_Guy 2024-06-05 04:05:17 -07:00
parent f8ec3d9ca6
commit 3ff76df4fe
5 changed files with 2919 additions and 2908 deletions

View File

@ -1 +1 @@
0.9.131 0.9.132

View File

@ -202,11 +202,14 @@ function message_read($id, $bodynum = 0, $group = "")
} }
if ($memcacheD) { if ($memcacheD) {
$memcache_key = $memcache_key_prefix . '_' . 'message_read-' . $id . '-0-' . $group; $memcache_key = $memcache_key_prefix . '_' . 'message_read-' . $id . '-0-' . $group;
if ($message = unserialize(gzuncompress($memcacheD->get($memcache_key)))) { $message_data = $memcacheD->get($memcache_key);
if ($enable_memcache_logging) { if ($message_data) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $memcache_key", FILE_APPEND); if ($message = unserialize(gzuncompress($message_data))) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $memcache_key", FILE_APPEND);
}
return $message;
} }
return $message;
} }
} }
$message = new messageType(); $message = new messageType();

View File

@ -73,12 +73,15 @@ function thread_cache_load($group)
} }
// Check memcache // Check memcache
if ($memcacheD) { if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group; $memcache_key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
if ($headers = unserialize(gzuncompress($memcacheD->get($key)))) { $message_data = $memcacheD->get($memcache_key);
if ($enable_memcache_logging) { if ($message_data) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $key", FILE_APPEND); if ($headers = unserialize(gzuncompress($message_data))) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $memcache_key", FILE_APPEND);
}
return $headers;
} }
return $headers;
} }
} }
@ -94,23 +97,21 @@ function thread_cache_load($group)
$dbh = null; $dbh = null;
} }
if ($memcacheD) { if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
$add_thread = gzcompress(serialize($headers), 9); $add_thread = gzcompress(serialize($headers), 9);
$thread_bytes = strlen($add_thread); $thread_bytes = strlen($add_thread);
$too_big = false; $too_big = false;
if($thread_bytes < $memcache_maxitemsize) { if ($thread_bytes < $memcache_maxitemsize) {
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl); $nicole = $memcacheD->add($memcache_key, $add_thread, $memcache_ttl);
} else { } else {
$nicole = false; $nicole = false;
$too_big = true; $too_big = true;
} }
if ($nicole && $enable_memcache_logging) { if ($nicole && $enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $key (" . strlen($add_thread) . " bytes)", FILE_APPEND); file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $memcache_key (" . strlen($add_thread) . " bytes)", FILE_APPEND);
} }
if ($too_big) { if ($too_big) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " $key too large (" . $thread_bytes . " bytes)", FILE_APPEND); file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " $memcache_key too large (" . $thread_bytes . " bytes)", FILE_APPEND);
} }
} }
return ($headers); return ($headers);
@ -151,26 +152,26 @@ function thread_cache_save($headers, $group)
$dbh->commit(); $dbh->commit();
$dbh = null; $dbh = null;
if ($memcacheD) { if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group; $memcache_key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
$del = $memcacheD->delete($key); $del = $memcacheD->delete($memcache_key);
$add_thread = gzcompress(serialize($headers), 9); $add_thread = gzcompress(serialize($headers), 9);
$thread_bytes = strlen($add_thread); $thread_bytes = strlen($add_thread);
$too_big = false; $too_big = false;
if($thread_bytes < $memcache_maxitemsize) { if ($thread_bytes < $memcache_maxitemsize) {
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl); $nicole = $memcacheD->add($memcache_key, $add_thread, $memcache_ttl);
} else { } else {
$too_big = true; $too_big = true;
$nicole = false; $nicole = false;
} }
if ($enable_memcache_logging) { if ($enable_memcache_logging) {
if ($del) { if ($del) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache delete) $key", FILE_APPEND); file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache delete) $memcache_key", FILE_APPEND);
} }
if ($nicole) { if ($nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $key (" . $thread_bytes . " bytes)", FILE_APPEND); file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $memcache_key (" . $thread_bytes . " bytes)", FILE_APPEND);
} }
if ($too_big) { if ($too_big) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " $key too large (" . $thread_bytes . " bytes)", FILE_APPEND); file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " $memcache_key too large (" . $thread_bytes . " bytes)", FILE_APPEND);
} }
} }
} }

View File

@ -640,16 +640,19 @@ function groups_show($gruppen)
// Get last article info from article database // Get last article info from article database
// First check memcache // First check memcache
if ($memcacheD) { if ($memcacheD) {
$lar_memcache = $memcache_key_prefix . '_' . 'lastarticleinfo-' . $g->name; $memcache_key = $memcache_key_prefix . '_' . 'lastarticleinfo-' . $g->name;
$groupfile = $spooldir . '/' . $g->name . '-lastarticleinfo.dat'; $groupfile = $spooldir . '/' . $g->name . '-lastarticleinfo.dat';
if ($lastarticleinfo = unserialize($memcacheD->get($lar_memcache))) { $lar = $memcacheD->get($memcache_key);
if ($lastarticleinfo && file_exists($groupfile) && filemtime($groupfile) <= $lastarticleinfo['date']) { if ($lar) {
if ($enable_memcache_logging) { if ($lastarticleinfo = unserialize($lar)) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . ' (cache hit) lastarticleinfo for ' . $g->name, FILE_APPEND); if ($lastarticleinfo && file_exists($groupfile) && filemtime($groupfile) <= $lastarticleinfo['date']) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . ' (cache hit) lastarticleinfo for ' . $g->name, FILE_APPEND);
}
$found = 1;
} else {
unset($lastarticleinfo);
} }
$found = 1;
} else {
unset($lastarticleinfo);
} }
} }
} }
@ -687,13 +690,13 @@ function groups_show($gruppen)
$lastarticleinfo = $row; $lastarticleinfo = $row;
if ($memcacheD) { if ($memcacheD) {
touch($groupfile, $lastarticleinfo['date']); touch($groupfile, $lastarticleinfo['date']);
$nicole = $memcacheD->delete($lar_memcache); $nicole = $memcacheD->delete($memcache_key);
$memcacheD->add($lar_memcache, serialize($row), $memcache_ttl); $memcacheD->add($memcache_key, serialize($row), $memcache_ttl);
if ($enable_memcache_logging) { if ($enable_memcache_logging) {
if ($nicole) { if ($nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache update) $lar_memcache", FILE_APPEND); file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache update) $memcache_key", FILE_APPEND);
} else { } else {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $lar_memcache", FILE_APPEND); file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $memcache_key", FILE_APPEND);
} }
} }
} }
@ -1128,34 +1131,34 @@ function html_parse($text)
function display_links_in_body($text) function display_links_in_body($text)
{ {
global $config_dir; global $config_dir;
preg_match_all('/(https?|ftp|scp|news|gopher|gemini|telnet):\/\/[a-zA-Z0-9.?%=\-\+\;\:\,\~\@\!\(\)\$\#&_\/]+/', $text, $matches); preg_match_all('/(https?|ftp|scp|news|gopher|gemini|telnet):\/\/[a-zA-Z0-9.?%=\-\+\;\:\,\~\@\!\(\)\$\#&_\/]+/', $text, $matches);
$isquote = false; $isquote = false;
if (strpos($text, ">") == 0) { if (strpos($text, ">") == 0) {
$isquote = true; $isquote = true;
echo '<blockquote class="np_article_quote">'; echo '<blockquote class="np_article_quote">';
} }
foreach ($matches[0] as $match) { foreach ($matches[0] as $match) {
if (! $match) { if (! $match) {
continue; continue;
} }
// Get rid of unwanted trailing characters // Get rid of unwanted trailing characters
$match = rtrim(htmlspecialchars_decode($match), '/>,"'); $match = rtrim(htmlspecialchars_decode($match), '/>,"');
$match = htmlspecialchars($match); $match = htmlspecialchars($match);
$linkurl = preg_replace("/(<|>)/", '', htmlspecialchars_decode($match)); $linkurl = preg_replace("/(<|>)/", '', htmlspecialchars_decode($match));
$url = preg_replace("/(<|>)/", ' ', $match); $url = preg_replace("/(<|>)/", ' ', $match);
$pattern = preg_quote($url); $pattern = preg_quote($url);
$pattern = "!$pattern!"; $pattern = "!$pattern!";
$text = preg_replace($pattern, '<a href="' . $linkurl . '" rel="nofollow" target="_blank">' . $url . '</a>', $text, 1); $text = preg_replace($pattern, '<a href="' . $linkurl . '" rel="nofollow" target="_blank">' . $url . '</a>', $text, 1);
} }
if (file_exists($config_dir . '/rewrite_body.inc.php')) { if (file_exists($config_dir . '/rewrite_body.inc.php')) {
include ($config_dir . '/rewrite_body.inc.php'); include ($config_dir . '/rewrite_body.inc.php');
} }
echo $text; echo $text;
if ($isquote) { if ($isquote) {
echo '</blockquote>'; echo '</blockquote>';
} }
} }
/* /*
@ -1623,14 +1626,16 @@ function get_newsgroups_by_msgid($msgid, $noarray = false)
include $config_dir . '/memcache.inc.php'; include $config_dir . '/memcache.inc.php';
} }
if ($memcacheD) { if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'get_newsgroups_by_msgid-' . $msgid; $memcache_key = $memcache_key_prefix . '_' . 'get_newsgroups_by_msgid-' . $msgid;
if ($groups = $memcacheD->get($key)) { if ($getgroups = $memcacheD->get($memcache_key)) {
if ($enable_memcache_logging) { if ($groups = unserialize($getgroups)) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $key", FILE_APPEND); if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $memcache_key", FILE_APPEND);
}
} }
} }
} }
if (! $groups) { if (!isset($groups)) {
$database = $spooldir . '/articles-overview.db3'; $database = $spooldir . '/articles-overview.db3';
$table = 'overview'; $table = 'overview';
$overview_dbh = overview_db_open($database, $table); $overview_dbh = overview_db_open($database, $table);
@ -1649,9 +1654,9 @@ function get_newsgroups_by_msgid($msgid, $noarray = false)
} }
$overview_dbh = null; $overview_dbh = null;
if ($groups && $memcacheD) { if ($groups && $memcacheD) {
$nicole = $memcacheD->add($key, $groups, $memcache_ttl); $nicole = $memcacheD->add($memcache_key, serialize($groups), $memcache_ttl);
if ($enable_memcache_logging && $nicole) { if ($enable_memcache_logging && $nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $key", FILE_APPEND); file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $memcache_key", FILE_APPEND);
} }
} }
} }
@ -1975,24 +1980,24 @@ function get_poster_name($name)
$fromline = address_decode($name, "nowhere"); $fromline = address_decode($name, "nowhere");
if (! isset($fromline[0]["host"])) if (! isset($fromline[0]["host"]))
$fromline[0]["host"] = ""; $fromline[0]["host"] = "";
$name_from = $fromline[0]["mailbox"] . "@" . $fromline[0]["host"]; $name_from = $fromline[0]["mailbox"] . "@" . $fromline[0]["host"];
$name_username = $fromline[0]["mailbox"]; $name_username = $fromline[0]["mailbox"];
if (! isset($fromline[0]["personal"])) { if (! isset($fromline[0]["personal"])) {
$poster_name = $fromline[0]["mailbox"]; $poster_name = $fromline[0]["mailbox"];
} else {
$poster_name = $fromline[0]["personal"];
}
if (trim($poster_name) == '') {
$fromoutput = explode("<", html_entity_decode($name));
if (strlen($fromoutput[0]) < 1) {
$poster_name = $fromoutput[1];
} else { } else {
$poster_name = $fromline[0]["personal"]; $poster_name = $fromoutput[0];
} }
if (trim($poster_name) == '') { }
$fromoutput = explode("<", html_entity_decode($name)); $thisposter['name'] = $poster_name;
if (strlen($fromoutput[0]) < 1) { $thisposter['from'] = $name_from;
$poster_name = $fromoutput[1]; return ($thisposter);
} else {
$poster_name = $fromoutput[0];
}
}
$thisposter['name'] = $poster_name;
$thisposter['from'] = $name_from;
return ($thisposter);
} }
/* /*
@ -2094,25 +2099,26 @@ function disable_page_by_user_agent($client_device, $useragent, $script = "Page"
} }
} }
function throttle_hits($client_device) function throttle_hits($client_device = null)
{ {
global $CONFIG, $OVERRIDES, $logdir, $config_name; global $CONFIG, $OVERRIDES, $logdir, $config_name;
$logfile = $logdir . '/newsportal.log'; $logfile = $logdir . '/newsportal.log';
$client_device = get_client_user_agent_info(); if (! $client_device) {
$client_device = get_client_user_agent_info();
}
$client_device = strtolower($client_device); $client_device = strtolower($client_device);
$useragent = strtolower($useragent);
$_SESSION['rsactive'] = true; $_SESSION['rsactive'] = true;
if (isset($OVERRIDES['block_by_user_agent'])) { if (isset($OVERRIDES['block_by_user_agent'])) {
$ua = strtolower($_SERVER["HTTP_USER_AGENT"]); $ua = strtolower($_SERVER["HTTP_USER_AGENT"]);
foreach($OVERRIDES['block_by_user_agent'] as $user_agent) { foreach ($OVERRIDES['block_by_user_agent'] as $user_agent) {
if(stripos($ua, $user_agent) !== false) { if (stripos($ua, $user_agent) !== false) {
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Blocking " . $_SERVER['REMOTE_ADDR'] . " '" . $user_agent . "' listed in block list", FILE_APPEND); file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Blocking " . $_SERVER['REMOTE_ADDR'] . " '" . $user_agent . "' listed in block list", FILE_APPEND);
$_SESSION['throttled'] = true; $_SESSION['throttled'] = true;
header("HTTP/1.0 403 Forbidden"); header("HTTP/1.0 403 Forbidden");
exit; exit();
} }
} }
} }
@ -2756,7 +2762,7 @@ function delete_message($messageid, $group = null, $overview_dbh = null)
$menulist = file($config_dir . "menu.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $menulist = file($config_dir . "menu.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($grouplist as $group) { foreach ($grouplist as $group) {
$config_name = get_section_by_group($group, true); $config_name = get_section_by_group($group, true);
if(!$config_name) { if (! $config_name) {
file_put_contents($logfile, "\n" . format_log_date() . " Group not found: " . $group, FILE_APPEND); file_put_contents($logfile, "\n" . format_log_date() . " Group not found: " . $group, FILE_APPEND);
continue; continue;
} }

View File

@ -308,7 +308,9 @@ function display_threads($threads, $oldest)
$style = 0; $style = 0;
$results = 0; $results = 0;
foreach ($nicole as $key => $value) { foreach ($nicole as $key => $value) {
$target_head = $this_overboard['msgids'][$key]; if (isset($this_overboard['msgids'][$key])) {
$target_head = $this_overboard['msgids'][$key];
}
if (! isset($target_head['msgid'])) { if (! isset($target_head['msgid'])) {
$target_head = get_data_from_msgid($key); $target_head = get_data_from_msgid($key);
} }
@ -333,7 +335,6 @@ function display_threads($threads, $oldest)
} }
} }
$results ++; $results ++;
$lone == '';
$skip = ''; $skip = '';
if ($nohead) { if ($nohead) {
if (($style % 2) == 0) { if (($style % 2) == 0) {