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,13 +202,16 @@ function message_read($id, $bodynum = 0, $group = "")
}
if ($memcacheD) {
$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 ($message_data) {
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;
}
}
}
$message = new messageType();
if ((isset($cache_articles)) && ($cache_articles == true)) {
// Try to load a cached article

View File

@ -73,14 +73,17 @@ function thread_cache_load($group)
}
// Check memcache
if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
if ($headers = unserialize(gzuncompress($memcacheD->get($key)))) {
$memcache_key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
$message_data = $memcacheD->get($memcache_key);
if ($message_data) {
if ($headers = unserialize(gzuncompress($message_data))) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $key", FILE_APPEND);
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $memcache_key", FILE_APPEND);
}
return $headers;
}
}
}
$database = $spooldir . '/' . $group . '-data.db3';
$table = "threads";
@ -94,23 +97,21 @@ function thread_cache_load($group)
$dbh = null;
}
if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
$add_thread = gzcompress(serialize($headers), 9);
$thread_bytes = strlen($add_thread);
$too_big = false;
if ($thread_bytes < $memcache_maxitemsize) {
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl);
$nicole = $memcacheD->add($memcache_key, $add_thread, $memcache_ttl);
} else {
$nicole = false;
$too_big = true;
}
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) {
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);
@ -151,26 +152,26 @@ function thread_cache_save($headers, $group)
$dbh->commit();
$dbh = null;
if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
$del = $memcacheD->delete($key);
$memcache_key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
$del = $memcacheD->delete($memcache_key);
$add_thread = gzcompress(serialize($headers), 9);
$thread_bytes = strlen($add_thread);
$too_big = false;
if ($thread_bytes < $memcache_maxitemsize) {
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl);
$nicole = $memcacheD->add($memcache_key, $add_thread, $memcache_ttl);
} else {
$too_big = true;
$nicole = false;
}
if ($enable_memcache_logging) {
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) {
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) {
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,9 +640,11 @@ function groups_show($gruppen)
// Get last article info from article database
// First check memcache
if ($memcacheD) {
$lar_memcache = $memcache_key_prefix . '_' . 'lastarticleinfo-' . $g->name;
$memcache_key = $memcache_key_prefix . '_' . 'lastarticleinfo-' . $g->name;
$groupfile = $spooldir . '/' . $g->name . '-lastarticleinfo.dat';
if ($lastarticleinfo = unserialize($memcacheD->get($lar_memcache))) {
$lar = $memcacheD->get($memcache_key);
if ($lar) {
if ($lastarticleinfo = unserialize($lar)) {
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);
@ -653,6 +655,7 @@ function groups_show($gruppen)
}
}
}
}
if (! isset($lastarticleinfo['date'])) {
if ($CONFIG['article_database'] == '1') {
$database = $spooldir . '/' . $g->name . '-articles.db3';
@ -687,13 +690,13 @@ function groups_show($gruppen)
$lastarticleinfo = $row;
if ($memcacheD) {
touch($groupfile, $lastarticleinfo['date']);
$nicole = $memcacheD->delete($lar_memcache);
$memcacheD->add($lar_memcache, serialize($row), $memcache_ttl);
$nicole = $memcacheD->delete($memcache_key);
$memcacheD->add($memcache_key, serialize($row), $memcache_ttl);
if ($enable_memcache_logging) {
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 {
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);
}
}
}
@ -1623,14 +1626,16 @@ function get_newsgroups_by_msgid($msgid, $noarray = false)
include $config_dir . '/memcache.inc.php';
}
if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'get_newsgroups_by_msgid-' . $msgid;
if ($groups = $memcacheD->get($key)) {
$memcache_key = $memcache_key_prefix . '_' . 'get_newsgroups_by_msgid-' . $msgid;
if ($getgroups = $memcacheD->get($memcache_key)) {
if ($groups = unserialize($getgroups)) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $key", FILE_APPEND);
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';
$table = 'overview';
$overview_dbh = overview_db_open($database, $table);
@ -1649,9 +1654,9 @@ function get_newsgroups_by_msgid($msgid, $noarray = false)
}
$overview_dbh = null;
if ($groups && $memcacheD) {
$nicole = $memcacheD->add($key, $groups, $memcache_ttl);
$nicole = $memcacheD->add($memcache_key, serialize($groups), $memcache_ttl);
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);
}
}
}
@ -2094,14 +2099,15 @@ 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;
$logfile = $logdir . '/newsportal.log';
if (! $client_device) {
$client_device = get_client_user_agent_info();
}
$client_device = strtolower($client_device);
$useragent = strtolower($useragent);
$_SESSION['rsactive'] = true;
@ -2112,7 +2118,7 @@ function throttle_hits($client_device)
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;
header("HTTP/1.0 403 Forbidden");
exit;
exit();
}
}
}

View File

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