From bb486431b0b8ee18007dc716897b4af736af672c Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Sun, 28 Apr 2024 03:05:02 -0700 Subject: [PATCH] Cleanup for overboard threads mod. --- Rocksolid_Light/common/themes/style.css | 10 +++ Rocksolid_Light/rocksolid/index.php | 13 +++ Rocksolid_Light/rocksolid/newsportal.php | 27 +++++- Rocksolid_Light/rocksolid/overboard.php | 103 +++++++++++++++++------ 4 files changed, 123 insertions(+), 30 deletions(-) diff --git a/Rocksolid_Light/common/themes/style.css b/Rocksolid_Light/common/themes/style.css index 764a25e..564417d 100644 --- a/Rocksolid_Light/common/themes/style.css +++ b/Rocksolid_Light/common/themes/style.css @@ -644,6 +644,16 @@ table.np_results_table { font-size: 0.5em; } +/* overboard style toggle */ +.np_ob_style_toggle { + margin-top: 0; + margin-bottom: 0; + text-decoration: none; + color: var(--color-highlight); + font-family: Arial, Helvetica, sans-serif; + font-size: 0.8em; +} + /* overboard posted_date */ .np_ob_posted_date { margin-top: 0; diff --git a/Rocksolid_Light/rocksolid/index.php b/Rocksolid_Light/rocksolid/index.php index 8b40840..14c725f 100644 --- a/Rocksolid_Light/rocksolid/index.php +++ b/Rocksolid_Light/rocksolid/index.php @@ -26,6 +26,19 @@ include "head.inc"; echo '

' . basename(getcwd()) . '

'; echo ''; +// If logged in: button for new only +if (isset($_COOKIE['mail_name'])) { + if ($userdata = get_user_mail_auth_data($_COOKIE['mail_name'])) { + if (isset($overboard) && ($overboard == true)) { + echo ''; + } + } +} // View Latest button if (isset($overboard) && ($overboard == true)) { echo ''; + echo ''; + echo '
'; + echo '
'; + echo ''; + echo ''; + echo '
'; + echo '
'; diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php index ce98d1c..3621796 100644 --- a/Rocksolid_Light/rocksolid/newsportal.php +++ b/Rocksolid_Light/rocksolid/newsportal.php @@ -113,7 +113,7 @@ function nntp2_open($nserver = 0, $nport = 0) $nport = $CONFIG['remote_ssl']; } $ns = fsockopen("ssl://" . $nserver, $nport, $error, $errorString, 30); - if(!$ns) { + if (! $ns) { return false; } } else { @@ -2049,7 +2049,7 @@ function is_moderated($newsgroups) } } } - if($CONFIG['remote_server'] == '') { + if ($CONFIG['remote_server'] == '') { return false; } $ns = nntp2_open(); @@ -2288,6 +2288,29 @@ function get_db_data_from_msgid($msgid, $group) } } +function get_group_array_from_msgid($msgid) +{ + global $spooldir; + $database = $spooldir . '/articles-overview.db3'; + $overview_dbh = overview_db_open($database); + $overview_query = $overview_dbh->prepare('SELECT * FROM overview WHERE msgid=:messageid'); + $overview_query->execute([ + 'messageid' => $msgid + ]); + $newsgroups = array(); + $found = false; + while ($row = $overview_query->fetch()) { + $newsgroups[] = $row['newsgroup']; + $found = true; + } + $dbh = null; + if ($found) { + return $newsgroups; + } else { + return false; + } +} + function get_data_from_msgid($msgid, $thisgroup = null) { global $spooldir; diff --git a/Rocksolid_Light/rocksolid/overboard.php b/Rocksolid_Light/rocksolid/overboard.php index 26e9b7e..0dbd223 100644 --- a/Rocksolid_Light/rocksolid/overboard.php +++ b/Rocksolid_Light/rocksolid/overboard.php @@ -119,11 +119,9 @@ if (isset($_GET['thisgroup'])) { $grouplist = file($groupconfig, FILE_IGNORE_NEW_LINES); } -show_overboard_header($grouplist); - // Determine default view style if (isset($_COOKIE['mail_name'])) { - if ($user_obstyle = get_config_value($config_dir . '/userconfig/' . strtolower($_COOKIE['mail_name']), 'obstyle')) { + if ($user_obstyle = get_config_file_value($config_dir . '/userconfig/' . strtolower($_COOKIE['mail_name']), 'obstyle')) { $_SESSION['obstyle'] = $user_obstyle; } } @@ -140,7 +138,7 @@ if (! isset($_SESSION['obstyle'])) { if (isset($_COOKIE['mail_name'])) { save_config_value($config_dir . '/userconfig/' . strtolower($_COOKIE['mail_name']), 'obstyle', $_SESSION['obstyle'], true); } -show_overboard_style_toggle(); +show_overboard_header($grouplist); $results = 0; @@ -259,7 +257,7 @@ function expire_overboard($cachefile) function display_threads($threads, $oldest) { - global $CONFIG, $OVERRIDES, $thissite, $logfile, $config_name, $spooldir, $config_dir, $snippetlength, $maxdisplay, $this_overboard, $article_age; + global $CONFIG, $OVERRIDES, $thissite, $logfile, $config_name, $spooldir, $config_dir, $snippetlength, $maxdisplay, $this_overboard, $article_age, $newonly; $expireme = time() - ($article_age * 86400); $display = ''; if (! isset($threads)) { @@ -268,9 +266,9 @@ function display_threads($threads, $oldest) krsort($threads); } // Get registered user settings + $newonly = false; if (isset($_COOKIE['mail_name'])) { if ($userdata = get_user_mail_auth_data($_COOKIE['mail_name'])) { - $userfile = $spooldir . '/' . strtolower($_COOKIE['mail_name']) . '-articleviews.dat'; $user_config = unserialize(file_get_contents($config_dir . '/userconfig/' . strtolower($_COOKIE['mail_name']) . '.config')); $userfile = $spooldir . '/' . strtolower($_COOKIE['mail_name']) . '-blocked_posters.dat'; if (file_exists($userfile)) { @@ -287,6 +285,10 @@ function display_threads($threads, $oldest) $user_config['hide_unsub'] = 'hide'; } } + // Show NEW in Section only + if (isset($_REQUEST['new']) && $_REQUEST['new'] == true) { + $newonly = true; + } } // Build display array @@ -302,7 +304,6 @@ function display_threads($threads, $oldest) $nicole[$this_overboard['threadlink'][$value]][$value] = $value; } } - $style = 0; $results = 0; foreach ($nicole as $key => $value) { @@ -310,6 +311,7 @@ function display_threads($threads, $oldest) if (! isset($target_head['msgid'])) { $target_head = get_data_from_msgid($key); } + // Skip if not in registered users sub list $checkgroup = $target_head['newsgroup']; if (! isset($userdata[$checkgroup])) { @@ -317,6 +319,20 @@ function display_threads($threads, $oldest) continue; } } + + // Check if only displaying new posts in section + if ($newonly) { + $allgroups = get_group_array_from_msgid($key); + foreach ($allgroups as $onegroup) { + if (isset($userdata[$onegroup])) { + $infofilename = $spooldir . "/" . $onegroup . "-lastarticleinfo.dat"; + $lastarticleinfo = unserialize(file_get_contents($infofilename)); + if ($userdata[$onegroup] > $lastarticleinfo['date']) { + continue 2; + } + } + } + } $nohead = true; $result_count = count($value); foreach ($value as $new) { @@ -327,6 +343,24 @@ function display_threads($threads, $oldest) if ($target['date'] < $oldest) { continue; } + // Skip if not in registered users sub list + $checkgroup = $target['newsgroup']; + if (! isset($userdata[$checkgroup])) { + if (isset($user_config['hide_unsub']) && $user_config['hide_unsub'] == 'hide') { + continue; + } + } + // Check if only displaying new posts in section + if ($newonly) { + $allgroups = get_group_array_from_msgid($new); + foreach ($allgroups as $onegroup) { + if (isset($userdata[$onegroup])) { + if ($userdata[$onegroup] > $target['date']) { + continue 2; + } + } + } + } $results ++; $lone == ''; $skip = ''; @@ -337,20 +371,12 @@ function display_threads($threads, $oldest) $display .= ''; // Newsgroups button (hidden) @@ -584,14 +625,21 @@ function show_overboard_header($grouplist) echo ''; echo ''; } - echo '
'; } $display .= '
'; - // Check user blocklist - $block = false; - foreach ($blocked_user_config as $key => $value) { - $blockme = '/' . addslashes($key) . '/'; - if (preg_match($blockme, $target_head['name'])) { - $block = true; - break; - } - } - if ($block) {} $url = $thissite . "/article-flat.php?id=" . $target_head['number'] . "&group=" . _rawurlencode($target_head['newsgroup']) . "#" . $target_head['number']; $display .= '

'; $display .= '' . headerDecode($target_head['subject']) . '

'; $display .= '' . $target_head['newsgroup'] . ''; + // RETRO - Determining whether to show snippet in each head may still have bugs + // meaning, it might show when it shouldn't or not when it should. Not sure yet. if ($result_count > 1 && isset($target_head['date'])) { $poster = get_poster_name(mb_decode_mimeheader($target_head['name'])); $block = false; @@ -427,7 +453,7 @@ function display_threads($threads, $oldest) function display_flat($threads, $oldest) { - global $CONFIG, $OVERRIDES, $thissite, $logfile, $spooldir, $config_name, $config_dir, $snippetlength, $maxdisplay, $this_overboard, $article_age; + global $CONFIG, $OVERRIDES, $thissite, $logfile, $spooldir, $config_name, $config_dir, $snippetlength, $maxdisplay, $this_overboard, $article_age, $newonly; $expireme = time() - ($article_age * 86400); $display = ''; if (! isset($threads)) { @@ -436,6 +462,7 @@ function display_flat($threads, $oldest) krsort($threads); } // Get registered user settings + $newonly = false; if (isset($_COOKIE['mail_name'])) { if ($userdata = get_user_mail_auth_data($_COOKIE['mail_name'])) { $userfile = $spooldir . '/' . strtolower($_COOKIE['mail_name']) . '-articleviews.dat'; @@ -455,6 +482,10 @@ function display_flat($threads, $oldest) $user_config['hide_unsub'] = 'hide'; } } + // Show NEW in Section only + if (isset($_REQUEST['new']) && $_REQUEST['new'] == true) { + $newonly = true; + } } $results = 0; foreach ($threads as $key => $value) { @@ -471,6 +502,17 @@ function display_flat($threads, $oldest) if ($target['date'] < $oldest) { continue; } + // Check if only displaying new posts in section + if ($newonly) { + $allgroups = get_group_array_from_msgid($value); + foreach ($allgroups as $onegroup) { + if (isset($userdata[$onegroup])) { + if ($userdata[$onegroup] > $target['date']) { + continue 2; + } + } + } + } if ($target['date'] < $expireme) { unset($this_overboard['threads'][$target['date']]); unset($this_overboard['threadlink'][$new]); @@ -500,7 +542,7 @@ function display_flat($threads, $oldest) $display .= '' . headerDecode($target['subject']) . ''; $display .= '

'; $display .= 'by: ' . create_name_link($poster['name'], $poster['from']) . ''; - + $display .= '

'; // link for (thread), if possible if (isset($this_overboard['threadlink'][$value])) { @@ -539,6 +581,7 @@ function show_overboard_header($grouplist) echo '
'; // Refresh button echo ''; + echo ''; // Article List button - echo ''; } - echo '
'; + echo '
'; echo '
'; echo ''; if (isset($user_time)) { @@ -548,9 +591,8 @@ function show_overboard_header($grouplist) } echo '
'; - echo '
'; echo '
'; echo ''; echo ''; @@ -564,7 +606,6 @@ function show_overboard_header($grouplist) echo '
'; echo '
'; } else { echo '

'; echo '' . basename(getcwd()) . ' / '; @@ -573,7 +614,7 @@ function show_overboard_header($grouplist) // Refresh button echo '

'; echo '
'; - echo ''; + echo ''; echo '
'; echo '
'; } + echo '
'; + + echo '
'; + + show_overboard_style_toggle(); + echo '
'; + echo '
'; } function show_overboard_style_toggle() { echo '
'; - echo '

'; echo 'Display as: '; if ($_SESSION['obstyle'] == 'threads') { echo 'Threads'; @@ -606,13 +654,12 @@ function show_overboard_style_toggle() } echo ''; echo '

'; - echo '

'; } function show_overboard_footer($stats, $results, $iscached) { - global $user_time, $rslight_version; - if (isset($user_time)) { + global $user_time, $rslight_version, $newonly; + if (isset($user_time) || $newonly) { $recent = 'new'; } else { $recent = 'recent';