2020-11-29 01:55:31 +01:00
< ? php
2021-06-22 08:56:13 +02:00
session_start ();
2020-11-29 01:55:31 +01:00
/* rocksolid overboard - overboard for rslight
* Download : https :// news . novabbs . com / getrslight
*
* E - Mail : retroguy @ novabbs . com
* Web : https :// news . novabbs . com
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
?>
< ? php
include " config.inc.php " ;
include " auth.inc " ;
include " $file_newsportal " ;
2021-06-18 12:10:34 +02:00
throttle_hits ();
2022-02-09 06:51:20 +01:00
write_access_log ();
2022-01-12 00:19:54 +01:00
if ( isset ( $_COOKIE [ 'mail_name' ])) {
2022-01-20 05:05:06 +01:00
if ( $userdata = get_user_mail_auth_data ( $_COOKIE [ 'mail_name' ])) {
$userfile = $spooldir . '/' . strtolower ( $_COOKIE [ 'mail_name' ]) . '-articleviews.dat' ;
}
2022-01-12 00:19:54 +01:00
}
2020-11-29 01:55:31 +01:00
if ( isset ( $frames_on ) && $frames_on === true ) {
?>
< script >
var contentURL = window . location . pathname + window . location . search + window . location . hash ;
if ( window . self !== window . top ) {
/* Great! now we move along */
} else {
window . location . href = '../index.php?content=' + encodeURIComponent ( contentURL );
}
top . history . replaceState ({}, 'Title' , 'index.php?content=' + encodeURIComponent ( contentURL ));
</ script >
< ? php
}
if ( isset ( $_GET [ 'thisgroup' ])) {
$title .= " - " . _rawurldecode ( _rawurldecode ( $_GET [ 'thisgroup' ])) . " - latest messages " ;
} else {
$title .= " - " . $config_name . " - overboard " ;
}
include " head.inc " ;
$CONFIG = include ( $config_file );
2022-04-10 06:30:34 +02:00
$logfile = $logdir . '/overboard.log' ;
2020-11-29 01:55:31 +01:00
# How many days old should articles be displayed?
if ( isset ( $_GET [ 'thisgroup' ])) {
$article_age = 30 ;
} else {
2021-06-18 12:10:34 +02:00
$article_age = 30 ;
2020-11-29 01:55:31 +01:00
}
2022-04-10 06:30:34 +02:00
$version = 1.1 ;
2021-12-22 06:57:12 +01:00
# How long in seconds to cache results
$cachetime = 60 ;
2020-11-29 01:55:31 +01:00
# Maximum number of articles to show
2022-04-10 06:30:34 +02:00
$maxdisplay = 1000 ;
2020-11-29 01:55:31 +01:00
# How many characters of the body to display per article
$snippetlength = 240 ;
$spoolpath_regexp = '/' . preg_replace ( '/\//' , '\\/' , $spoolpath ) . '/' ;
$thissite = '.' ;
$groupconfig = $file_groups ;
2021-12-22 06:57:12 +01:00
$cachefile = $spooldir . " / " . $config_name . " -overboard.dat " ;
2020-11-29 01:55:31 +01:00
$oldest = ( time () - ( 86400 * $article_age ));
2022-04-10 06:30:34 +02:00
$prune = false ;
2020-11-29 01:55:31 +01:00
2022-01-26 03:01:59 +01:00
if ( isset ( $_GET [ 'time' ])) {
$user_time = $_GET [ 'time' ];
if ( is_numeric ( $user_time )) {
if (( $user_time > time ()) || ( $user_time < $oldest )) {
unset ( $user_time );
}
2022-04-10 06:30:34 +02:00
} else {
unset ( $user_time );
2022-01-26 03:01:59 +01:00
}
}
2020-11-29 01:55:31 +01:00
if ( isset ( $_GET [ 'thisgroup' ])) {
$grouplist = array ();
$grouplist [ 0 ] = _rawurldecode ( _rawurldecode ( $_GET [ 'thisgroup' ]));
2021-12-22 06:57:12 +01:00
$cachefile = $spooldir . " / " . $grouplist [ 0 ] . " -overboard.dat " ;
2022-01-20 09:00:49 +01:00
if ( $userdata ) {
2022-01-12 00:19:54 +01:00
$userdata [ $grouplist [ 0 ]] = time ();
file_put_contents ( $userfile , serialize ( $userdata ));
}
2020-11-29 01:55:31 +01:00
} else {
$grouplist = file ( $groupconfig , FILE_IGNORE_NEW_LINES );
}
2021-12-22 06:57:12 +01:00
show_overboard_header ( $grouplist );
$results = 0 ;
2022-04-10 06:30:34 +02:00
2020-11-29 01:55:31 +01:00
if ( is_file ( $cachefile )) {
$stats = stat ( $cachefile );
2022-04-10 06:30:34 +02:00
$this_overboard = unserialize ( file_get_contents ( $cachefile ));
$cachedate = ( $this_overboard [ 'lastmessage' ] - 86400 );
$oldest = $cachedate ;
} else {
$cachedate = ( $oldest - 86400 );
}
if ( $this_overboard [ 'version' ] !== $version ) {
unset ( $this_overboard );
unlink ( $cachefile );
$this_overboard [ 'version' ] = $version ;
$cachedate = ( $oldest - 86400 );
2020-11-29 01:55:31 +01:00
}
2022-04-10 06:30:34 +02:00
2020-11-29 01:55:31 +01:00
# Iterate through groups
2020-12-24 10:36:17 +01:00
$database = $spooldir . '/articles-overview.db3' ;
2020-12-12 05:16:13 +01:00
$table = 'overview' ;
$dbh = rslight_db_open ( $database , $table );
2022-04-10 06:30:34 +02:00
$query = $dbh -> prepare ( 'SELECT * FROM ' . $table . ' WHERE newsgroup=:findgroup AND date >= ' . $cachedate . ' ORDER BY date DESC LIMIT ' . $maxdisplay );
2020-11-29 01:55:31 +01:00
$articles = array ();
2021-01-20 23:54:47 +01:00
$db_articles = array ();
2020-11-29 01:55:31 +01:00
foreach ( $grouplist as $findgroup ) {
2020-12-12 05:16:13 +01:00
$groups = preg_split ( " /( \ | \t )/ " , $findgroup , 2 );
2020-11-29 01:55:31 +01:00
$findgroup = $groups [ 0 ];
$overboard_noshow = explode ( ' ' , $CONFIG [ 'overboard_noshow' ]);
foreach ( $overboard_noshow as $noshow ) {
if (( strpos ( $findgroup , $noshow ) !== false ) && ! isset ( $_GET [ 'thisgroup' ])) {
2020-12-17 07:41:06 +01:00
continue 2 ;
2020-11-29 01:55:31 +01:00
}
}
$thisgroup = preg_replace ( '/\./' , '/' , $findgroup );
2021-01-21 09:25:05 +01:00
if ( $dbh ) {
$query -> execute ([ 'findgroup' => $findgroup ]);
2021-05-23 02:09:45 +02:00
$i = 0 ;
2021-01-21 09:25:05 +01:00
while (( $overviewline = $query -> fetch ()) !== false ) {
2021-12-22 06:57:12 +01:00
$articles [] = $spoolpath . $thisgroup . '/' . $overviewline [ 'number' ];
2021-04-06 10:39:40 +02:00
$db_articles [] = $findgroup . ':' . $overviewline [ 'number' ] . ':' . $overviewline [ 'date' ] . ':' . $overviewline [ 'name' ];
2021-05-23 02:09:45 +02:00
$i ++ ;
if ( $i > $maxdisplay ) {
break ;
}
2021-01-21 09:25:05 +01:00
}
2020-12-12 05:16:13 +01:00
}
2020-11-29 01:55:31 +01:00
}
2020-12-12 05:16:13 +01:00
$dbh = null ;
2020-11-29 01:55:31 +01:00
$files = array ();
2021-01-20 23:54:47 +01:00
if ( $CONFIG [ 'article_database' ] == '1' ) {
foreach ( $db_articles as $article ) {
$order = explode ( ':' , $article );
$files [ $order [ 2 ]] = $article ;
}
} else {
foreach ( $articles as $article ) {
2020-11-29 01:55:31 +01:00
if ( is_dir ( $article )) {
continue ;
}
$files [ filemtime ( $article )] = $article ;
2021-01-20 23:54:47 +01:00
}
2020-11-29 01:55:31 +01:00
}
krsort ( $files );
2021-12-22 06:57:12 +01:00
2020-11-29 01:55:31 +01:00
foreach ( $files as $article ) {
2021-01-20 23:54:47 +01:00
if ( $CONFIG [ 'article_database' ] == '1' ) {
$data = explode ( ':' , $article );
$articledata = np_get_db_article ( $data [ 1 ], $data [ 0 ], 0 );
} else {
$articledata = file_get_contents ( $article );
}
2020-11-29 01:55:31 +01:00
$bodystart = strpos ( $articledata , $localeol );
$header = substr ( $articledata , 0 , $bodystart );
# Find group name and article number
2021-01-20 23:54:47 +01:00
if ( $CONFIG [ 'article_database' ] == '1' ) {
$group = $data [ 0 ];
$articlenumber = $data [ 1 ];
$groupname = $group ;
} else {
$group = preg_replace ( $spoolpath_regexp , '' , $article );
$group = preg_replace ( '/\//' , '.' , $group );
$findme = strrpos ( $group , '.' );
$groupname = substr ( $group , 0 , $findme );
$articlenumber = substr ( $group , $findme + 1 );
}
2021-12-16 03:21:43 +01:00
2021-12-23 04:30:59 +01:00
preg_match ( '/Message-ID:.*/i' , $header , $articleid );
$getid = explode ( " : " , $articleid [ 0 ]);
2022-04-10 06:30:34 +02:00
$thismsgid = $getid [ 1 ];
if ( isset ( $this_overboard [ 'msgids' ][ $thismsgid ])) {
continue ;
}
2021-12-31 10:41:53 +01:00
preg_match ( '/References:.*/i' , $header , $ref );
$getrefs = explode ( ': ' , $ref [ 0 ]);
$ref = preg_split ( " /[ \ s]+/ " , $getrefs [ 1 ]);
if ( $getrefs [ 1 ] && $refid = get_data_from_msgid ( $ref [ 0 ])) {
2022-01-03 23:01:42 +01:00
// Check that article to link is new enough for newsportal to display
2023-04-14 03:52:30 +02:00
$groupinfo = file ( $spooldir . '/' . $refid [ " newsgroup " ] . '-info.txt' );
2022-01-03 23:01:42 +01:00
$range = explode ( ' ' , $groupinfo [ 1 ]);
2023-04-14 03:52:30 +02:00
if ( $refid [ 'number' ] > ( intval ( $range [ 0 ]) - 1 )) {
2022-01-03 23:01:42 +01:00
$threadref = $ref [ 0 ];
} else {
$threadref = false ;
}
2021-12-31 10:41:53 +01:00
} else {
$threadref = false ;
}
2020-11-29 01:55:31 +01:00
2022-04-10 06:30:34 +02:00
$target = get_data_from_msgid ( $thismsgid );
if ( $target [ 'date' ] > time ()) {
continue ;
2020-11-29 01:55:31 +01:00
}
2022-04-10 06:30:34 +02:00
if ( $target [ 'date' ] > $this_overboard [ 'lastmessage' ]) {
$this_overboard [ 'lastmessage' ] = $target [ 'date' ];
2021-12-31 10:41:53 +01:00
}
2022-04-10 06:30:34 +02:00
if ( ! isset ( $this_overboard [ 'threads' ][ $target [ 'date' ]])) {
$this_overboard [ 'threads' ][ $target [ 'date' ]] = $thismsgid ;
$this_overboard [ 'msgids' ][ $thismsgid ] = $target ;
if ( $threadref ) {
$this_overboard [ 'threadlink' ][ $thismsgid ] = $threadref ;
}
if ( $results ++ > ( $maxdisplay - 2 )) {
break ;
}
2020-11-29 01:55:31 +01:00
}
2022-04-10 06:30:34 +02:00
}
2021-12-23 04:30:59 +01:00
2022-04-10 06:30:34 +02:00
file_put_contents ( $cachefile , serialize ( $this_overboard ));
if ( isset ( $user_time )) {
$oldest = ( $user_time - 900 );
} else {
$oldest = ( time () - ( 86400 * $article_age ));
2020-11-29 01:55:31 +01:00
}
2022-04-10 06:30:34 +02:00
$results = display_threads ( $this_overboard [ 'threads' ], $oldest );
show_overboard_footer ( null , $results , null );
echo '</body></html>' ;
expire_overboard ( $cachefile );
function expire_overboard ( $cachefile ) {
global $article_age , $logfile , $config_name , $prune , $this_overboard ;
if ( $this_overboard [ 'expire' ] < ( time () - 86400 )) {
$prune = true ;
foreach ( $this_overboard [ 'msgids' ] as $key => $value ) {
$target = $this_overboard [ 'msgids' ][ $key ];
if ( $target [ 'date' ] < ( time () - ( 86400 * $article_age ))) {
2022-04-17 07:47:48 +02:00
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Expiring: " . $target [ 'newsgroup' ] . " : " . $target [ 'number' ], FILE_APPEND );
2022-04-10 06:30:34 +02:00
unset ( $this_overboard [ 'threads' ][ $target [ 'date' ]]);
unset ( $this_overboard [ 'msgids' ][ $key ]);
unset ( $this_overboard [ 'threadlink' ][ $key ]);
}
2022-01-26 03:01:59 +01:00
}
2022-04-10 06:30:34 +02:00
$this_overboard [ 'expire' ] = time ();
2021-12-22 06:57:12 +01:00
}
2022-04-10 06:30:34 +02:00
if ( $prune ) {
file_put_contents ( $cachefile , serialize ( $this_overboard ));
2021-12-22 06:57:12 +01:00
}
2022-04-10 06:30:34 +02:00
}
function display_threads ( $threads , $oldest ) {
global $thissite , $logfile , $config_name , $snippetlength , $maxdisplay , $prune , $this_overboard ;
echo '<table cellspacing="0" width="100%" class="np_results_table">' ;
2023-04-14 03:52:30 +02:00
if ( ! isset ( $threads )) {
$threads = ( object )[];
}
2022-04-10 06:30:34 +02:00
krsort ( $threads );
$results = 0 ;
foreach ( $threads as $key => $value ) {
$target = $this_overboard [ 'msgids' ][ $value ];
if ( ! isset ( $target [ 'msgid' ])) {
$target = get_data_from_msgid ( $value );
2021-12-22 06:57:12 +01:00
}
2022-04-10 06:30:34 +02:00
if ( $target [ 'date' ] < $oldest ) {
continue ;
2022-01-26 03:01:59 +01:00
}
2022-04-10 06:30:34 +02:00
if ( $results > $maxdisplay ) {
$prune = true ;
unset ( $this_overboard [ 'threads' ][ $target [ 'date' ]]);
unset ( $this_overboard [ 'threadlink' ][ $value ]);
2022-04-17 07:47:48 +02:00
file_put_contents ( $logfile , " \n " . format_log_date () . " " . $config_name . " Pruning: " . $target [ 'newsgroup' ] . " : " . $target [ 'number' ], FILE_APPEND );
2022-04-10 06:30:34 +02:00
}
$article = get_db_data_from_msgid ( $target [ 'msgid' ], $target [ 'newsgroup' ], 1 );
$poster = get_poster_name ( mb_decode_mimeheader ( $target [ 'name' ]));
$groupurl = $thissite . " /thread.php?group= " . _rawurlencode ( $target [ 'newsgroup' ]);
if (( $results % 2 ) == 0 ){
echo '<tr class="np_result_line2"><td class="np_result_line2" style="word-wrap:break-word";>' ;
} else {
echo '<tr class="np_result_line1"><td class="np_result_line1" style="word-wrap:break-word";>' ;
}
$url = $thissite . " /article-flat.php?id= " . $target [ 'number' ] . " &group= " . _rawurlencode ( $target [ 'newsgroup' ]) . " # " . $target [ 'number' ];
echo '<p class=np_ob_subject>' ;
echo '<b><a href="' . $url . '"><span>' . mb_decode_mimeheader ( $target [ 'subject' ]) . '</span></a></b>' ;
if ( isset ( $this_overboard [ 'threadlink' ][ $value ])) {
$thread = get_data_from_msgid ( $this_overboard [ 'threadlink' ][ $value ]);
2023-04-14 03:52:30 +02:00
echo '<font class="np_ob_group"><a href="article-flat.php?id=' . $thread [ 'number' ] . '&group=' . rawurlencode ( $thread [ 'newsgroup' ]) . '#' . $thread [ 'number' ] . '"> (thread)</a></font>' ;
2022-04-10 06:30:34 +02:00
}
echo '</p>' ;
echo '</p><p class=np_ob_group>' ;
echo '<a href="' . $groupurl . '"><span class="visited">' . $target [ 'newsgroup' ] . '</span></a>' ;
echo '</p>' ;
echo '<p class=np_ob_posted_date>Posted: ' . get_date_interval ( date ( " D, j M Y H:i T " , $target [ 'date' ])) . ' by: ' . create_name_link ( $poster [ 'name' ], $poster [ 'from' ]) . '</p>' ;
echo htmlentities ( substr ( $article [ 'search_snippet' ], 0 , $snippetlength ));
$results ++ ;
2021-12-22 06:57:12 +01:00
}
2022-04-10 06:30:34 +02:00
echo " </table> " ;
return ( $results );
}
2020-11-29 01:55:31 +01:00
2021-12-22 06:57:12 +01:00
function show_overboard_header ( $grouplist ) {
2022-03-04 10:22:20 +01:00
global $text_thread , $text_article , $file_index , $file_thread , $user_time ;
2021-12-22 06:57:12 +01:00
if ( isset ( $_GET [ 'thisgroup' ])) {
echo '<h1 class="np_thread_headline">' ;
echo '<a href="' . $file_index . '" target=' . $frame [ 'menu' ] . '>' . basename ( getcwd ()) . '</a> / ' ;
2023-04-14 03:52:30 +02:00
echo '<a href="' . $file_thread . '?group=' . rawurlencode ( $grouplist [ 0 ]) . '" target=' . $frame [ " content " ] . '>' . htmlspecialchars ( group_displaY_name ( $grouplist [ 0 ])) . '</a> / ' ;
2022-03-04 10:22:20 +01:00
if ( isset ( $user_time )) {
echo ' new messages</h1>' ;
} else {
echo ' latest</h1>' ;
}
2021-12-22 06:57:12 +01:00
echo '<table cellpadding="0" cellspacing="0" class="np_buttonbar"><tr>' ;
// Refresh button
echo '<td>' ;
echo '<form action="overboard.php">' ;
echo '<input type="hidden" name="thisgroup" value="' . $_GET [ 'thisgroup' ] . '"/>' ;
2022-03-04 10:22:20 +01:00
if ( isset ( $user_time )) {
echo '<button class="np_button_link" type="submit">overboard</button>' ;
} else {
echo '<button class="np_button_link" type="submit">' . $text_article [ " refresh " ] . '</button>' ;
}
2021-12-22 06:57:12 +01:00
echo '</form>' ;
echo '</td>' ;
// Article List button
echo '<td>' ;
echo '<form action="' . $file_thread . '">' ;
echo '<input type="hidden" name="group" value="' . $grouplist [ 0 ] . '"/>' ;
echo '<button class="np_button_link" type="submit">' . htmlspecialchars ( group_display_name ( $grouplist [ 0 ])) . '</button>' ;
echo '</form>' ;
echo '</td>' ;
// Newsgroups button (hidden)
if ( isset ( $frames_on ) && $frames_on === true ) {
echo '<td>' ;
echo '<form action="' . $file_index . '">' ;
echo '<button class="np_button_hidden" type="submit">' . $text_thread [ " button_grouplist " ] . '</button>' ;
echo '</form>' ;
echo '</td>' ;
}
echo '<td width=100%></td></tr></table>' ;
} else {
echo '<h1 class="np_thread_headline">' ;
echo '<a href="' . $file_index . '" target=' . $frame [ 'menu' ] . '>' . basename ( getcwd ()) . '</a> / ' ;
echo 'latest messages</h1>' ;
echo '<table cellpadding="0" cellspacing="0" class="np_buttonbar"><tr>' ;
// Refresh button
echo '<td>' ;
echo '<form action="overboard.php">' ;
echo '<button class="np_button_link" type="submit">' . $text_article [ " refresh " ] . '</button>' ;
echo '</form>' ;
echo '</td>' ;
// Newsgroups button (hidden)
if ( isset ( $frames_on ) && $frames_on === true ) {
echo '<td>' ;
echo '<form action="' . $file_index . '">' ;
echo '<button class="np_button_hidden" type="submit">' . $text_thread [ " button_grouplist " ] . '</button>' ;
echo '</form>' ;
echo '</td>' ;
}
echo '<td width=100%></td></tr></table>' ;
}
}
2020-11-29 01:55:31 +01:00
2021-12-22 06:57:12 +01:00
function show_overboard_footer ( $stats , $results , $iscached ) {
2023-04-14 03:52:30 +02:00
global $user_time , $rslight_version ;
2022-01-26 03:01:59 +01:00
if ( isset ( $user_time )) {
$recent = 'new' ;
} else {
$recent = 'recent' ;
}
2022-01-28 05:17:01 +01:00
if ( $results == '1' ) {
$arts = 'article' ;
} else {
$arts = 'articles' ;
}
2021-12-22 06:57:12 +01:00
echo '</table>' ;
2022-01-28 05:17:01 +01:00
echo " <p class=np_ob_tail><b> " . $results . " </b> " . $recent . " " . $arts . " found.</p> \r \n " ;
2021-12-22 06:57:12 +01:00
#echo "<center><i>Rocksolid Overboard</i> version ".$version;
include " tail.inc " ;
if ( $iscached ) {
echo " <p class=np_ob_tail><font size='1em'>cached copy: " . date ( " D M j G:i:s T Y " , $stats [ 9 ]) . " </font></p> \r \n " ;
}
2020-11-29 01:55:31 +01:00
}
?>