2020-11-29 01:55:31 +01:00
< ? php
2020-12-25 01:18:35 +01:00
session_cache_limiter ( 'public' );
2023-09-22 12:33:24 +02:00
header ( " Expires: " . gmdate ( " D, d M Y H:i:s " , time () + ( 120 )) . " GMT " );
header ( " Cache-Control: max-age=120 " );
2023-08-09 16:12:32 +02:00
header ( " Pragma: cache " );
2020-12-12 05:16:13 +01:00
include " config.inc.php " ;
include " newsportal.php " ;
2024-12-14 14:27:36 +01:00
$logfile = $logdir . '/search.log' ;
2024-12-13 18:15:38 +01:00
2021-03-17 09:39:45 +01:00
$snippet_size = 100 ;
2022-02-24 06:58:21 +01:00
2024-01-07 23:52:50 +01:00
if ( isset ( $_REQUEST [ 'group' ])) {
$search_group = urldecode ( $_REQUEST [ 'group' ]);
} else {
$search_group = null ;
2023-12-29 01:39:02 +01:00
}
2023-08-20 00:33:05 +02:00
if ( isset ( $_REQUEST [ 'data' ]) && $_REQUEST [ 'data' ] == '' ) {
unset ( $_REQUEST [ 'data' ]);
2022-02-24 06:58:21 +01:00
}
2024-10-28 16:35:27 +01:00
2023-08-20 00:33:05 +02:00
if (( ! isset ( $_POST [ 'key' ]) || ! password_verify ( $CONFIG [ 'thissitekey' ], $_POST [ 'key' ])) || (( strlen ( trim ( $_REQUEST [ 'terms' ])) < 2 ) && ! $_REQUEST [ 'data' ])) {
include " head.inc " ;
2023-09-04 15:06:43 +02:00
if ( disable_page_by_user_agent ( $client_device , " bot " , " Search " )) {
echo " <center>Page Disabled</center> " ;
include " tail.inc " ;
exit ();
}
2024-10-16 13:24:38 +02:00
// Display search tools
display_search_tools ();
2024-04-05 14:41:44 +02:00
// Block poster
if ( isset ( $_COOKIE [ 'mail_name' ])) {
if ( isset ( $_REQUEST [ 'data' ])) {
2024-10-31 18:06:16 +01:00
echo '<br>' ;
echo '<form name="blockform" method="post" action="search.php">' ;
echo '<table width=100% border="0" class="search_hide_posts">' ;
2024-04-05 14:41:44 +02:00
echo '<tr>' ;
2024-10-31 18:06:16 +01:00
echo '<td>Hide posts by <strong>' . $_GET [ 'terms' ] . '</strong></td>' ;
2024-04-05 14:41:44 +02:00
echo '</tr>' ;
2024-10-31 18:06:16 +01:00
echo '<input name="command" type="hidden" id="command" value="Search">' ;
2024-04-05 14:41:44 +02:00
echo '<input type="hidden" name="key" value="' . password_hash ( $CONFIG [ 'thissitekey' ], PASSWORD_DEFAULT ) . '">' ;
if ( isset ( $_GET [ 'data' ])) {
echo '<input type="hidden" name="data" value="' . $_GET [ 'data' ] . '">' ;
}
echo '<input type="hidden" name="username" value="' . $_COOKIE [ 'mail_name' ] . '">' ;
// Password confirmation
echo '<tr>' ;
echo '<td style="word-wrap:break-word";>Enter your password: ' ;
echo '<input name="password" type="password" id="password" maxlength="40"></td>' ;
echo '<input name="block_poster" type="hidden" id="block_poster" value="' . $_GET [ 'terms' ] . '"></td>' ;
echo '</tr>' ;
echo '<td><input type="submit" name="Submit" value="Add poster to my block list"></td>' ;
echo '</tr></table></td></form>' ;
}
}
// END Block poster
2023-08-20 00:33:05 +02:00
exit ( 0 );
2024-07-04 10:52:05 +02:00
} else {
// Determine default view style
if ( isset ( $_COOKIE [ 'mail_name' ])) {
if ( $user_searchsort = get_config_file_value ( $config_dir . '/userconfig/' . strtolower ( $_COOKIE [ 'mail_name' ]), 'searchsort' )) {
$_SESSION [ 'searchsort' ] = $user_searchsort ;
}
}
if ( isset ( $_POST [ 'searchsort' ])) {
$_SESSION [ 'searchsort' ] = $_POST [ 'searchsort' ];
}
if ( ! isset ( $_SESSION [ 'searchsort' ])) {
if ( isset ( $OVERRIDES [ 'search_default_sort' ])) {
$_SESSION [ 'searchsort' ] = $OVERRIDES [ 'search_default_sort' ];
} else {
$_SESSION [ 'searchsort' ] = 'relevance' ;
}
}
if ( isset ( $_COOKIE [ 'mail_name' ])) {
save_config_value ( $config_dir . '/userconfig/' . strtolower ( $_COOKIE [ 'mail_name' ]), 'searchsort' , $_SESSION [ 'searchsort' ], true );
}
2021-03-12 05:34:53 +01:00
}
2023-08-20 00:33:05 +02:00
if ( isset ( $frames_on ) && $frames_on === true ) {
2024-10-16 13:24:38 +02:00
?>
< 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 >
2020-12-12 05:16:13 +01:00
< ? php
}
# Maximum number of articles to show
$maxdisplay = 1000 ;
$thissite = '.' ;
2023-08-20 00:33:05 +02:00
$groupconfig = $config_path . " /groups.txt " ;
2020-12-12 05:16:13 +01:00
2023-08-20 00:33:05 +02:00
$title .= ' - search results for: ' . $_POST [ 'terms' ];
2020-12-12 05:16:13 +01:00
include " head.inc " ;
2024-04-05 14:41:44 +02:00
// Handle Block poster
2024-07-21 15:19:35 +02:00
$post_username = trim ( strtolower ( $_POST [ 'username' ]));
2024-04-05 14:41:44 +02:00
if ( isset ( $_POST [ 'block_poster' ])) {
2024-07-21 15:19:35 +02:00
if (( password_verify ( $post_username . $keys [ 0 ] . get_user_config ( $post_username , 'encryptionkey' ), $_COOKIE [ 'mail_auth' ])) || ( password_verify ( $post_username . $keys [ 1 ] . get_user_config ( $post_username , 'encryptionkey' ), $_COOKIE [ 'mail_auth' ]))) {
2024-04-05 14:41:44 +02:00
$logged_in = true ;
} else {
2024-07-21 15:19:35 +02:00
if ( check_bbs_auth ( $post_username , $_POST [ 'password' ])) {
2024-04-05 14:41:44 +02:00
if ( $ip_pass ) {
$_SESSION [ 'pass' ] = true ;
}
2024-07-21 15:19:35 +02:00
set_user_logged_in_cookies ( $post_username , $keys );
2024-04-05 14:41:44 +02:00
$logged_in = true ;
}
}
if ( $logged_in == true ) {
if ( $userdata = get_user_mail_auth_data ( $_COOKIE [ 'mail_name' ])) {
$blockfile = $spooldir . '/' . strtolower ( $_COOKIE [ 'mail_name' ]) . '-blocked_posters.dat' ;
if ( file_exists ( $blockfile )) {
$blocked_user_config = unserialize ( file_get_contents ( $blockfile ));
} else {
$blocked_user_config = array ();
}
$blocked_user_config [ base64_decode ( urldecode ( $_REQUEST [ 'data' ]))] = $_POST [ 'block_poster' ];
file_put_contents ( $blockfile , serialize ( $blocked_user_config ));
}
2024-07-04 10:52:05 +02:00
echo " <center><b>' " . $_POST [ 'block_poster' ] . " '</b> successfully added to your blocklist " ;
2024-04-05 14:41:44 +02:00
echo '<br>You may edit your blocklist on your <a href="/spoolnews/user.php?command=Configuration">Configuration Page</a></center>' ;
2024-04-15 12:11:00 +02:00
echo '<center><br><i>(Articles may still appear on Cached Pages)</i></center>' ;
2024-04-05 14:41:44 +02:00
} else {
echo '<center>Password Incorrect.<br>Click Back to try again</center>' ;
}
exit ( 0 );
}
2024-10-16 13:24:38 +02:00
display_search_tools ();
2024-12-14 14:27:36 +01:00
// Display search suggestions
if ( isset ( $_REQUEST [ 'searchpoint' ]) && $_REQUEST [ 'searchpoint' ] == 'body' && isset ( $_REQUEST [ 'terms' ]) && trim ( $_REQUEST [ 'terms' ]) != '' ) {
$suggestion = get_suggestion ( $_REQUEST [ 'terms' ]);
if ( $suggestion != false ) {
echo '<form method="post" action="search.php" class="search_suggestion_inline">' ;
echo '<input type="hidden" name="group" value="' . $_REQUEST [ 'group' ] . '">' ;
echo '<input type="hidden" name="terms" value="' . $suggestion . '">' ;
echo '<input type="hidden" name="key" value="' . $_REQUEST [ 'key' ] . '">' ;
echo '<input type="hidden" name="command" value="' . $_REQUEST [ 'command' ] . '">' ;
echo '<input type="hidden" name="searchpoint" value="' . $_REQUEST [ 'searchpoint' ] . '">' ;
echo '<button type="submit" name="submit_param" value="submit_value" class="search_suggestion_link-button">' ;
echo 'Did you mean: <b><i>' . htmlentities ( $suggestion ) . '</i></b>' ;
echo '</button>' ;
echo '</form>' ;
file_put_contents ( $logfile , " \n " . logging_prefix () . " SEARCH: " . $_REQUEST [ 'terms' ] . " SUGGESTING: " . $suggestion , FILE_APPEND );
2024-12-15 10:47:16 +01:00
} else {
file_put_contents ( $logfile , " \n " . logging_prefix () . " SEARCH: " . $_REQUEST [ 'terms' ], FILE_APPEND );
2024-12-13 18:15:38 +01:00
}
}
2024-12-14 14:27:36 +01:00
2024-10-16 13:24:38 +02:00
echo " <hr> " ;
2020-12-12 05:16:13 +01:00
ob_start ();
2024-01-07 23:52:50 +01:00
if ( isset ( $search_group )) {
echo '<h1 class="np_thread_headline">' ;
echo '<a href="' . $file_index . '" target=' . $frame [ 'menu' ] . '>' . basename ( getcwd ()) . '</a> / ' ;
echo '<a href="' . $file_thread . '?group=' . urlencode ( $search_group ) . '" target=' . $frame [ 'menu' ] . '>' . $search_group . '</a> / ' ;
echo 'search results for: ' . $_POST [ 'terms' ] . '</h1>' ;
2023-08-20 00:33:05 +02:00
} else {
2020-12-12 05:16:13 +01:00
echo '<h1 class="np_thread_headline">' ;
2023-08-20 00:33:05 +02:00
echo '<a href="' . $file_index . '" target=' . $frame [ 'menu' ] . '>' . basename ( getcwd ()) . '</a> / ' ;
echo 'search results for: ' . $_POST [ 'terms' ] . '</h1>' ;
2020-12-12 05:16:13 +01:00
}
2024-10-31 18:06:16 +01:00
echo '<table class="np_buttonbar"><tr>' ;
2024-11-19 17:46:14 +01:00
echo '<td class="search_sort_toggle">' ;
2024-07-04 10:52:05 +02:00
echo '<div style="float:right;">' ;
if ( $_REQUEST [ 'searchpoint' ] == 'body' ) {
show_search_sort_toggle ();
}
echo '</div>' ;
echo '</td>' ;
echo '</tr></table>' ;
2024-11-19 17:46:14 +01:00
echo '<table class="search_results_table">' ;
2020-12-12 05:16:13 +01:00
# Iterate through groups
2023-08-20 00:33:05 +02:00
$results = 0 ;
if ( isset ( $_COOKIE [ 'tzo' ])) {
$offset = $_COOKIE [ 'tzo' ];
} else {
$offset = $CONFIG [ 'timezone' ];
}
$overview = array ();
if ( $_POST [ 'searchpoint' ] == 'body' ) {
2023-12-29 01:39:02 +01:00
$overview = get_body_search ( $search_group , $_POST [ 'terms' ]);
2023-08-20 00:33:05 +02:00
} else {
if ( isset ( $_REQUEST [ 'data' ])) {
2023-12-29 01:39:02 +01:00
$overview = get_header_search ( $search_group , base64_decode ( urldecode ( $_REQUEST [ 'data' ])));
2022-02-21 05:15:38 +01:00
} else {
2023-12-29 01:39:02 +01:00
$overview = get_header_search ( $search_group , $_POST [ 'terms' ]);
2022-02-21 05:15:38 +01:00
}
2023-08-20 00:33:05 +02:00
}
2024-07-04 10:52:05 +02:00
2023-08-20 00:33:05 +02:00
foreach ( $overview as $overviewline ) {
/* Find section for links */
2024-10-17 15:13:09 +02:00
$menulist = get_section_menu_array ();
2023-08-20 00:33:05 +02:00
foreach ( $menulist as $menu ) {
$menuitem = explode ( ':' , $menu );
$glfp = fopen ( $config_dir . $menuitem [ 0 ] . " /groups.txt " , 'r' );
$section = " " ;
while ( $gl = fgets ( $glfp )) {
$group_name = preg_split ( " /( | \t )/ " , $gl , 2 );
if ( stripos ( trim ( $overviewline [ 'newsgroup' ]), trim ( $group_name [ 0 ])) !== false ) {
$section = $menuitem [ 0 ];
break 2 ;
}
2020-12-24 10:36:17 +01:00
}
}
2021-03-11 07:55:01 +01:00
fclose ( $glfp );
2023-08-20 00:33:05 +02:00
# Generate link
2023-12-30 13:08:14 +01:00
$url = " ../ " . $section . " /article-flat.php?id= " . $overviewline [ 'number' ] . " &group= " . urlencode ( $overviewline [ 'newsgroup' ]) . " # " . $overviewline [ 'number' ];
$groupurl = " ../ " . $section . " /thread.php?group= " . urlencode ( $overviewline [ 'newsgroup' ]);
2023-08-20 00:33:05 +02:00
$fromoutput = explode ( " < " , html_entity_decode ( $overviewline [ 'name' ]));
// Use local timezone if possible
$ts = new DateTime ( date ( $text_header [ " date_format " ], $overviewline [ 'date' ]), new DateTimeZone ( 'UTC' ));
$ts -> add ( DateInterval :: createFromDateString ( $offset . ' minutes' ));
if ( $offset != 0 ) {
$newdate = $ts -> format ( 'D, j M Y H:i' );
} else {
$newdate = $ts -> format ( $text_header [ " date_format " ]);
}
unset ( $ts );
$fromline = address_decode ( headerDecode ( $overviewline [ 'name' ]), " nowhere " );
if ( ! isset ( $fromline [ 0 ][ " personal " ])) {
2024-10-16 13:24:38 +02:00
$lastname = $fromline [ 0 ][ " mailbox " ];;
2023-08-20 00:33:05 +02:00
} else {
$lastname = $fromline [ 0 ][ " personal " ];
}
if (( $results % 2 ) != 0 ) {
2024-11-19 17:46:14 +01:00
echo '<tr class="search_result_line1"><td class="search_result_line1">' ;
2023-08-20 00:33:05 +02:00
} else {
2024-11-19 17:46:14 +01:00
echo '<tr class="search_result_line2"><td class="search_result_line2">' ;
2023-08-20 00:33:05 +02:00
}
2024-11-19 17:46:14 +01:00
echo '<p class="search_subject">' ;
2024-01-17 17:53:36 +01:00
echo '<b><a href="' . $url . '">' . htmlspecialchars ( headerDecode ( $overviewline [ 'subject' ])) . " </a></b> \r \n " ;
2024-11-19 17:46:14 +01:00
echo '</p><p class="search_group">' ;
2023-08-20 00:33:05 +02:00
echo '<a href="' . $groupurl . '">' . $overviewline [ 'newsgroup' ] . '</a>' ;
echo '</p>' ;
$fromline = address_decode ( $overviewline [ 'name' ], " nowhere " );
if ( ! isset ( $fromline [ 0 ][ " host " ]))
$fromline [ 0 ][ " host " ] = " " ;
$name_from = $fromline [ 0 ][ " mailbox " ] . " @ " . $fromline [ 0 ][ " host " ];
$name_username = $fromline [ 0 ][ " mailbox " ];
if ( ! isset ( $fromline [ 0 ][ " personal " ])) {
$poster_name = $fromline [ 0 ][ " mailbox " ];
} else {
$poster_name = $fromline [ 0 ][ " personal " ];
}
if ( trim ( $poster_name ) == '' ) {
$fromoutput = explode ( " < " , html_entity_decode ( $c -> name ));
if ( strlen ( $fromoutput [ 0 ]) < 1 ) {
$poster_name = $fromoutput [ 1 ];
} else {
$poster_name = $fromoutput [ 0 ];
}
}
$poster_name = trim ( mb_decode_mimeheader ( $poster_name ), " \n \r \t \ v \0 \" " );
2024-11-19 17:46:14 +01:00
echo '<p class="search_posted_date">Posted: ' . $newdate . ' by: ' . create_name_link ( $poster_name , $name_from ) . '</p>' ;
2023-08-20 00:33:05 +02:00
if ( $_POST [ 'searchpoint' ] == 'body' ) {
$snip = strip_tags ( quoted_printable_decode ( $overviewline [ 'snippet' ]), '<strong><font><i>' );
} else {
$snip = strip_tags ( quoted_printable_decode ( $overviewline [ 'search_snippet' ]), '<strong><font><i>' );
$snip = substr ( $snip , 0 , $snippet_size );
}
2024-11-19 17:46:14 +01:00
echo '<div class="search_snippet">' ;
2023-08-20 00:33:05 +02:00
echo $snip ;
2024-11-19 17:46:14 +01:00
echo '</div>' ;
2023-08-20 00:33:05 +02:00
echo '</td></tr>' ;
2024-10-16 13:24:38 +02:00
if ( $results ++ > ( $maxdisplay - 2 ))
2023-08-20 00:33:05 +02:00
break ;
2020-12-12 05:16:13 +01:00
}
echo '</table>' ;
2023-08-20 00:33:05 +02:00
echo " <p class=np_ob_tail><b> " . $results . " </b> matching articles found.</p> \r \n " ;
# echo "<center><i>Rocksolid Overboard</i> version ".$version;
2020-12-12 05:16:13 +01:00
include " tail.inc " ;
$thispage = ob_get_contents ();
ob_end_clean ();
echo $thispage ;
2023-08-20 00:33:05 +02:00
function get_body_search ( $group , $terms )
{
2024-10-16 13:24:38 +02:00
global $CONFIG , $config_name , $config_dir , $debug_log , $spooldir , $snippet_size ;
2024-10-28 16:35:27 +01:00
$terms = preg_replace ( " /'/ " , ' ' , urldecode ( $terms ));
2023-08-20 00:33:05 +02:00
$terms = trim ( $terms );
2024-10-16 13:24:38 +02:00
if ( $terms [ 0 ] !== '"' || substr ( $terms , - 1 ) !== '"' ) {
2023-08-20 00:33:05 +02:00
$terms = preg_replace ( '/"/' , '' , $terms );
$terms = preg_replace ( " / \ / " , '" "' , $terms );
$terms = preg_replace ( '/"NEAR"/' , 'NEAR' , $terms );
$terms = preg_replace ( '/"AND"/' , 'AND' , $terms );
$terms = preg_replace ( '/"OR"/' , 'OR' , $terms );
$terms = preg_replace ( '/"NOT"/' , 'NOT' , $terms );
$terms = '"' . $terms . '"' ;
}
2023-12-29 01:39:02 +01:00
if ( $group != '' ) {
$grouplist [ 0 ] = $group ;
2021-03-12 08:56:35 +01:00
} else {
2024-10-08 20:08:17 +02:00
$local_groupfile = $config_dir . " / " . $config_name . " /groups.txt " ;
2023-08-20 00:33:05 +02:00
$grouplist = file ( $local_groupfile , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
2021-03-12 08:56:35 +01:00
}
2023-08-20 00:33:05 +02:00
foreach ( $grouplist as $thisgroup ) {
2024-10-08 20:08:17 +02:00
$name = preg_split ( " /( | \t )/ " , $thisgroup , 2 );
2023-08-20 00:33:05 +02:00
$group = $name [ 0 ];
$database = $spooldir . '/' . $group . '-articles.db3' ;
if ( ! is_file ( $database )) {
continue ;
}
$dbh = article_db_open ( $database );
2024-10-16 13:24:38 +02:00
if ( ! $dbh ) {
2024-10-08 20:08:17 +02:00
file_put_contents ( $debug_log , " \n " . format_log_date () . " " . $config_name . " Failed to open database: " . $database . " in search.php " , FILE_APPEND );
continue ;
}
2023-08-20 00:33:05 +02:00
$stmt = $dbh -> prepare ( " SELECT snippet(search_fts, 6, '<strong><font class=search_result><i>', '</i></font></strong>', '...', $snippet_size ) as snippet, newsgroup, number, name, date, subject, rank FROM search_fts WHERE search_fts MATCH 'search_snippet: $terms ' ORDER BY rank " );
$stmt -> execute ();
while ( $row = $stmt -> fetch ()) {
$overview [] = $row ;
}
$dbh = null ;
2021-03-11 07:55:01 +01:00
}
2023-07-06 05:07:45 +02:00
// do not perform a usort of an empty search result
2024-07-20 17:01:24 +02:00
if ( $overview != null ) {
if ( $_SESSION [ 'searchsort' ] != 'date' ) {
2024-07-04 10:52:05 +02:00
usort ( $overview , function ( $a , $b ) {
return $a [ 'rank' ] <=> $b [ 'rank' ];
});
2024-07-20 17:01:24 +02:00
} else {
2024-07-04 10:52:05 +02:00
usort ( $overview , function ( $a , $b ) {
return $b [ 'date' ] <=> $a [ 'date' ];
});
}
2023-07-06 05:07:45 +02:00
}
2023-08-20 00:33:05 +02:00
return $overview ;
2021-03-11 07:55:01 +01:00
}
2024-07-04 10:52:05 +02:00
function show_search_sort_toggle ()
{
echo '<form method="post" action="' . $_SERVER [ 'REQUEST_URI' ] . '">' ;
echo 'Sort by: ' ;
if ( $_SESSION [ 'searchsort' ] == 'date' ) {
echo '<input type="radio" name="searchsort" value="date" checked>Date' ;
echo ' ' ;
echo '<input type="radio" name="searchsort" value="relevance">Relevance' ;
echo ' ' ;
} else {
echo '<input type="radio" name="searchsort" value="date">Date' ;
echo ' ' ;
echo '<input type="radio" name="searchsort" value="relevance" checked>Relevance' ;
echo ' ' ;
}
echo '<input type="hidden" name="group" value="' . $_REQUEST [ 'group' ] . '">' ;
echo '<input type="hidden" name="data" value="' . $_REQUEST [ 'data' ] . '">' ;
echo '<input type="hidden" name="terms" value="' . $_REQUEST [ 'terms' ] . '">' ;
echo '<input type="hidden" name="key" value="' . $_REQUEST [ 'key' ] . '">' ;
echo '<input type="hidden" name="command" value="' . $_REQUEST [ 'command' ] . '">' ;
echo '<input type="hidden" name="searchpoint" value="' . $_REQUEST [ 'searchpoint' ] . '">' ;
echo '<input class="np_button_link" type="submit" value="Reload" name="reload">' ;
echo '</form >' ;
}
2023-08-20 00:33:05 +02:00
function get_header_search ( $group , $terms )
{
2024-10-16 13:24:38 +02:00
global $CONFIG , $config_name , $config_dir , $spooldir , $debug_log , $snippet_size ;
2024-10-28 16:35:27 +01:00
$terms = preg_replace ( '/\%/' , '\%' , urldecode ( $terms ));
2023-08-20 00:33:05 +02:00
$searchterms = " % " . $terms . " % " ;
2024-07-04 10:52:05 +02:00
2024-04-10 16:07:58 +02:00
if ( isset ( $group )) {
2024-03-23 13:22:05 +01:00
$grouplist [ 0 ] = $group ;
2021-03-17 10:43:31 +01:00
} else {
2024-10-08 20:08:17 +02:00
$local_groupfile = $config_dir . " / " . $config_name . " /groups.txt " ;
2021-12-18 23:30:47 +01:00
$grouplist = file ( $local_groupfile , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
2021-03-17 10:43:31 +01:00
}
2024-04-10 16:07:58 +02:00
2021-03-23 11:16:50 +01:00
# Prepare search database
2023-08-20 00:33:05 +02:00
$database = $spooldir . '/articles-overview.db3' ;
2021-03-23 11:16:50 +01:00
$table = 'overview' ;
2023-08-13 19:00:48 +02:00
$dbh = overview_db_open ( $database , $table );
2021-03-23 11:16:50 +01:00
$overview = array ();
2023-08-20 00:33:05 +02:00
foreach ( $grouplist as $thisgroup ) {
2024-10-08 20:08:17 +02:00
$name = preg_split ( " /( | \t )/ " , $thisgroup , 2 );
2023-08-20 00:33:05 +02:00
$group = $name [ 0 ];
$article_database = $spooldir . '/' . $group . '-articles.db3' ;
if ( ! is_file ( $article_database )) {
2021-11-17 07:34:52 +01:00
continue ;
2023-08-20 00:33:05 +02:00
}
$article_dbh = article_db_open ( $article_database );
2024-10-16 13:24:38 +02:00
if ( ! $article_dbh ) {
2024-10-08 20:08:17 +02:00
file_put_contents ( $debug_log , " \n " . format_log_date () . " " . $config_name . " Failed to open database: " . $article_database . " in search.php " , FILE_APPEND );
continue ;
}
2023-08-20 00:33:05 +02:00
$article_stmt = $article_dbh -> prepare ( " SELECT * FROM articles WHERE number=:number " );
2024-08-10 18:49:51 +02:00
if ( ! isset ( $_POST [ 'data' ]) && is_multibyte ( $_POST [ 'terms' ])) {
2021-03-25 03:10:49 +01:00
$stmt = $dbh -> prepare ( " SELECT * FROM $table WHERE newsgroup=:group " );
$stmt -> bindParam ( ':group' , $group );
$stmt -> execute ();
2023-08-20 00:33:05 +02:00
while ( $found = $stmt -> fetch ()) {
if ( stripos ( mb_decode_mimeheader ( $found [ $_POST [ 'searchpoint' ]]), $_POST [ 'terms' ]) !== false ) {
$article_stmt -> bindParam ( ':number' , $found [ 'number' ]);
$article_stmt -> execute ();
$found_snip = $article_stmt -> fetch ();
$found [ 'search_snippet' ] = $found_snip [ 'search_snippet' ];
$found [ 'sort_date' ] = $found_snip [ 'date' ];
$overview [] = $found ;
}
2021-03-11 07:55:01 +01:00
}
2023-08-20 00:33:05 +02:00
} else {
$stmt = $dbh -> prepare ( " SELECT * FROM $table WHERE newsgroup=:group AND " . $_POST [ 'searchpoint' ] . " like :terms ESCAPE ' \ ' ORDER BY date DESC " );
$stmt -> bindParam ( ':group' , $group );
2021-03-11 07:55:01 +01:00
$stmt -> bindParam ( ':terms' , $searchterms );
2023-08-20 00:33:05 +02:00
$check = " /([a-z]|[0-9]| \ !|#| \$ | \ %| \ &| \ '| \ *| \ +| \ -| \ /| \ =| \ ?| \ ^| \ _| \" | \ `| \ { | \ || \ }| \ ~| \ ;) " . trim ( $searchterms , '\%' ) . " /i " ;
2021-03-11 07:55:01 +01:00
$stmt -> execute ();
2023-08-20 00:33:05 +02:00
while ( $found = $stmt -> fetch ()) {
if ( isset ( $_REQUEST [ 'data' ]) && ( $_REQUEST [ 'searchpoint' ] == 'name' )) {
if ( preg_match ( $check , $found [ 'name' ])) {
continue ;
}
2022-03-04 10:22:20 +01:00
}
2023-08-20 00:33:05 +02:00
$article_stmt -> bindParam ( ':number' , $found [ 'number' ]);
$article_stmt -> execute ();
$found_snip = $article_stmt -> fetch ();
$found [ 'search_snippet' ] = $found_snip [ 'search_snippet' ];
$found [ 'sort_date' ] = $found_snip [ 'date' ];
$overview [] = $found ;
2021-03-11 07:55:01 +01:00
}
2023-08-20 00:33:05 +02:00
}
$article_dbh = null ;
2021-03-17 10:43:31 +01:00
}
2023-08-20 00:33:05 +02:00
$dbh = null ;
usort ( $overview , function ( $b , $a ) {
return $a [ 'sort_date' ] <=> $b [ 'sort_date' ];
});
return $overview ;
2021-03-11 07:55:01 +01:00
}
2024-10-16 13:24:38 +02:00
function display_search_tools ( $home = true )
{
2024-12-13 18:15:38 +01:00
global $CONFIG , $config_name , $search_group , $file_index , $frame , $file_thread , $suggestion ;
2024-10-16 13:24:38 +02:00
echo '<h1 class="np_thread_headline">' ;
echo '<a href="' . $file_index . '" target=' . $frame [ 'menu' ] . '>' . basename ( getcwd ()) . '</a> / ' ;
if ( $search_group ) {
echo '<a href="' . $file_thread . '?group=' . urlencode ( $search_group ) . '" target=' . $frame [ 'menu' ] . '>' . $search_group . '</a> / ' ;
}
echo 'search</h1>' ;
2024-10-31 18:06:16 +01:00
echo '<form name="form1" method="post" action="search.php">' ;
2024-11-20 12:18:19 +01:00
echo '<table class="search_form_table"><tr>' ;
2024-10-16 13:24:38 +02:00
if ( isset ( $search_group )) {
$searching = $search_group ;
} else {
$searching = $config_name ;
}
2024-10-31 18:06:16 +01:00
echo '<td>Searching <strong>' . $searching . '</strong></td>' ;
2024-10-16 13:24:38 +02:00
echo '</tr>' ;
echo '<tr>' ;
if ( ! isset ( $_REQUEST [ 'data' ])) {
2024-10-31 16:59:19 +01:00
echo '<td>Search Terms: ' ;
2024-10-16 13:24:38 +02:00
} else {
2024-10-31 16:59:19 +01:00
echo '<td>Search Poster: ' ;
2024-10-16 13:24:38 +02:00
}
if ( isset ( $_REQUEST [ 'terms' ])) {
2024-12-13 18:15:38 +01:00
echo '<input name="terms" type="text" id="terms" value="' . htmlentities ( $_REQUEST [ 'terms' ]) . '"></td>' ;
2024-10-16 13:24:38 +02:00
} else {
echo '<input name="terms" type="text" id="terms"></td>' ;
}
echo '</tr><tr><td>' ;
// Create radio buttons (prefilled if available)
if ( isset ( $_REQUEST [ 'searchpoint' ])) {
if ( $_REQUEST [ 'searchpoint' ] == 'Poster' || $_REQUEST [ 'searchpoint' ] == 'name' ) {
if ( $CONFIG [ 'article_database' ] == '1' ) {
2024-10-31 16:59:19 +01:00
echo '<input type="radio" name="searchpoint" value="body">Body ' ;
2024-10-16 13:24:38 +02:00
}
2024-10-31 16:59:19 +01:00
echo '<input type="radio" name="searchpoint" value="subject">Subject ' ;
echo '<input type="radio" name="searchpoint" value="name" checked="checked">Poster ' ;
echo '<input type="radio" name="searchpoint" value="msgid">Message-ID' ;
2024-10-16 13:24:38 +02:00
} elseif ( $_REQUEST [ 'searchpoint' ] == 'subject' ) {
if ( $CONFIG [ 'article_database' ] == '1' ) {
2024-10-31 16:59:19 +01:00
echo ' <input type="radio" name="searchpoint" value="body">Body ' ;
2024-10-16 13:24:38 +02:00
}
2024-10-31 16:59:19 +01:00
echo '<input type="radio" name="searchpoint" value="subject" checked="checked">Subject ' ;
echo '<input type="radio" name="searchpoint" value="name">Poster ' ;
echo '<input type="radio" name="searchpoint" value="msgid">Message-ID' ;
2024-10-16 13:24:38 +02:00
} elseif ( $_REQUEST [ 'searchpoint' ] == 'msgid' ) {
if ( $CONFIG [ 'article_database' ] == '1' ) {
2024-10-31 16:59:19 +01:00
echo ' <input type="radio" name="searchpoint" value="body">Body ' ;
2024-10-16 13:24:38 +02:00
}
2024-10-31 16:59:19 +01:00
echo '<input type="radio" name="searchpoint" value="subject">Subject ' ;
echo '<input type="radio" name="searchpoint" value="name">Poster ' ;
echo '<input type="radio" name="searchpoint" value="msgid" checked="checked">Message-ID' ;
2024-10-16 13:24:38 +02:00
} else {
if ( $CONFIG [ 'article_database' ] == '1' ) {
2024-10-31 16:59:19 +01:00
echo ' <input type="radio" name="searchpoint" value="body" checked="checked">Body ' ;
2024-10-16 13:24:38 +02:00
}
2024-10-31 16:59:19 +01:00
echo '<input type="radio" name="searchpoint" value="subject">Subject ' ;
echo '<input type="radio" name="searchpoint" value="name">Poster ' ;
echo '<input type="radio" name="searchpoint" value="msgid">Message-ID' ;
2024-10-16 13:24:38 +02:00
}
} else {
if ( $CONFIG [ 'article_database' ] == '1' ) {
2024-10-31 16:59:19 +01:00
echo ' <input type="radio" name="searchpoint" value="body" checked="checked">Body ' ;
2024-10-16 13:24:38 +02:00
}
2024-10-31 16:59:19 +01:00
echo '<input type="radio" name="searchpoint" value="subject">Subject ' ;
echo '<input type="radio" name="searchpoint" value="name">Poster ' ;
echo '<input type="radio" name="searchpoint" value="msgid">Message-ID' ;
2024-10-16 13:24:38 +02:00
}
2024-10-31 18:06:16 +01:00
echo '<input name="command" type="hidden" id="command" value="Search" >' ;
2024-10-16 13:24:38 +02:00
if ( isset ( $search_group )) {
echo '<input type="hidden" name="group" value="' . urlencode ( $search_group ) . '">' ;
}
echo '<input type="hidden" name="key" value="' . password_hash ( $CONFIG [ 'thissitekey' ], PASSWORD_DEFAULT ) . '">' ;
if ( isset ( $_REQUEST [ 'data' ])) {
echo '<input type="hidden" name="data" value="' . $_REQUEST [ 'data' ] . '">' ;
}
2024-10-31 18:06:16 +01:00
echo '</td></tr>' ;
echo '<tr>' ;
2024-10-16 13:24:38 +02:00
echo '<td><input type="submit" name="Submit" value="Search"></td>' ;
2024-12-13 18:15:38 +01:00
echo '<form method="post" action="some_page" class="inline">' ;
2024-10-31 18:06:16 +01:00
echo '</tr></table></form>' ;
2024-10-16 13:24:38 +02:00
}
2024-12-14 14:27:36 +01:00
function get_suggestion ( $word )
2024-12-13 18:15:38 +01:00
{
2024-12-17 15:22:02 +01:00
global $OVERRIDES , $logfile , $debug_log ;
if ( ! function_exists ( 'pspell_new' )) {
file_put_contents ( $debug_log , " \n " . logging_prefix () . " PSPELL Missing: php-pspell support unavailable " , FILE_APPEND );
return false ;
}
2024-12-14 14:27:36 +01:00
if ( isset ( $OVERRIDES [ 'lang_default' ])) {
$lang = $OVERRIDES [ 'lang_default' ];
} else {
$lang = 'en' ;
2024-12-13 18:15:38 +01:00
}
2024-12-17 15:22:02 +01:00
if (( $pspell = pspell_new ( $lang )) == false ) {
2024-12-15 10:47:16 +01:00
file_put_contents ( $logfile , " \n " . logging_prefix () . " SEARCH: " . $lang . " dictionary not found " , FILE_APPEND );
return false ;
}
2024-12-14 14:27:36 +01:00
// Remove specific characters here
2024-12-15 10:47:16 +01:00
$word = preg_replace ( " /( \" | \ '| \ (| \ )| \ -| \ +| \ _)/ " , '' , $word );
2024-12-13 18:15:38 +01:00
if ( ! preg_match ( " / / " , trim ( $word ))) { // Just one word in search
if ( ! pspell_check ( $pspell , $word )) {
$suggestions = pspell_suggest ( $pspell , $word );
if ( isset ( $suggestions [ 0 ])) {
if ( strtolower ( $word ) == strtolower ( $suggestions [ 0 ])) {
return false ;
} else {
return $suggestions [ 0 ];
}
} else {
return false ;
}
}
} else { // Multiple words in search
$return_string = '' ;
$words = explode ( " " , $word );
foreach ( $words as $one_word ) {
2024-12-17 15:22:02 +01:00
if ( preg_match ( " /^(AND|OR|NOT| \ +) $ /i " , $one_word )) {
2024-12-15 10:47:16 +01:00
$return_string .= $one_word . " " ;
continue ;
}
2024-12-13 18:15:38 +01:00
if ( ! pspell_check ( $pspell , $one_word )) {
$suggestions = pspell_suggest ( $pspell , $one_word );
if ( isset ( $suggestions [ 0 ])) {
$return_string .= $suggestions [ 0 ] . " " ;
} else {
$return_string .= $one_word . " " ;
}
} else {
$return_string .= $one_word . " " ;
}
}
if ( trim ( strtolower ( $return_string )) != trim ( strtolower ( $word ))) {
2024-12-15 10:47:16 +01:00
return trim ( $return_string );
2024-12-13 18:15:38 +01:00
} else {
return false ;
}
}
}
2023-08-20 00:33:05 +02:00
function highlightStr ( $haystack , $needle )
{
2020-12-12 05:16:13 +01:00
preg_match_all ( " / $needle +/i " , $haystack , $matches );
if ( is_array ( $matches [ 0 ]) && count ( $matches [ 0 ]) >= 1 ) {
2023-08-20 00:33:05 +02:00
foreach ( $matches [ 0 ] as $match ) {
$haystack = str_replace ( $match , '<b>' . $match . '</b>' , $haystack );
}
2020-12-12 05:16:13 +01:00
}
return $haystack ;
}
?>
</ body >
2024-10-16 13:24:38 +02:00
</ html >