Provide ability to offer search suggestions in other (not 'en') languages.
This commit is contained in:
parent
933fe81371
commit
60b43050c2
|
@ -155,6 +155,12 @@ if (!isset($OVERRIDES['disable_msgid_search']) || $OVERRIDES['disable_msgid_sear
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For debugging purposes
|
||||||
|
if (isset($OVERRIDES['log_lang']) && $OVERRIDES['log_lang'] == true) {
|
||||||
|
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
||||||
|
file_put_contents($debug_log, "\n" . logging_prefix() . " Browser Lang: " . $lang, FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
// Soup...Uh, Message of the Day
|
// Soup...Uh, Message of the Day
|
||||||
if ($unread) {
|
if ($unread) {
|
||||||
$motd = '*** You have unread mail. <a href="../spoolnews/mail.php">Click Here</a> ***';
|
$motd = '*** You have unread mail. <a href="../spoolnews/mail.php">Click Here</a> ***';
|
||||||
|
|
|
@ -2443,6 +2443,7 @@ function throttle_hits($client_device = null)
|
||||||
function get_client_user_agent_info()
|
function get_client_user_agent_info()
|
||||||
{
|
{
|
||||||
global $config_dir, $logdir;
|
global $config_dir, $logdir;
|
||||||
|
|
||||||
// Try to get browser info to use for extra formatting of page
|
// Try to get browser info to use for extra formatting of page
|
||||||
$ua = strtolower($_SERVER["HTTP_USER_AGENT"]);
|
$ua = strtolower($_SERVER["HTTP_USER_AGENT"]);
|
||||||
$devices = array(
|
$devices = array(
|
||||||
|
@ -2838,7 +2839,7 @@ function insert_article_from_array($this_article, $check_duplicates = true)
|
||||||
$overview_sql = 'INSERT OR IGNORE INTO overview(newsgroup, number, msgid, date, datestring, name, subject, refs, bytes, lines, xref) VALUES(?,?,?,?,?,?,?,?,?,?,?)';
|
$overview_sql = 'INSERT OR IGNORE INTO overview(newsgroup, number, msgid, date, datestring, name, subject, refs, bytes, lines, xref) VALUES(?,?,?,?,?,?,?,?,?,?,?)';
|
||||||
$overview_stmt = $overview_dbh->prepare($overview_sql);
|
$overview_stmt = $overview_dbh->prepare($overview_sql);
|
||||||
|
|
||||||
if(!isset($this_article['references'])) {
|
if (!isset($this_article['references'])) {
|
||||||
$this_article['references'] = "";
|
$this_article['references'] = "";
|
||||||
}
|
}
|
||||||
// Overview
|
// Overview
|
||||||
|
|
|
@ -8,7 +8,7 @@ header("Pragma: cache");
|
||||||
include "config.inc.php";
|
include "config.inc.php";
|
||||||
include "newsportal.php";
|
include "newsportal.php";
|
||||||
|
|
||||||
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
$logfile = $logdir . '/search.log';
|
||||||
|
|
||||||
$snippet_size = 100;
|
$snippet_size = 100;
|
||||||
|
|
||||||
|
@ -142,25 +142,27 @@ if (isset($_POST['block_poster'])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
display_search_tools();
|
display_search_tools();
|
||||||
if ($lang == 'en') { // Display suggestions
|
|
||||||
if (isset($_REQUEST['searchpoint']) && $_REQUEST['searchpoint'] == 'body' && isset($_REQUEST['terms']) && trim($_REQUEST['terms']) != '') {
|
|
||||||
$suggestion = get_suggestion($_REQUEST['terms'], $lang);
|
|
||||||
if ($suggestion != false) {
|
|
||||||
echo '<form method="post" action="search.php" class="search_suggestion_inline">';
|
|
||||||
|
|
||||||
echo '<input type="hidden" name="group" value="' . $_REQUEST['group'] . '">';
|
// Display search suggestions
|
||||||
echo '<input type="hidden" name="terms" value="' . $suggestion . '">';
|
if (isset($_REQUEST['searchpoint']) && $_REQUEST['searchpoint'] == 'body' && isset($_REQUEST['terms']) && trim($_REQUEST['terms']) != '') {
|
||||||
echo '<input type="hidden" name="key" value="' . $_REQUEST['key'] . '">';
|
$suggestion = get_suggestion($_REQUEST['terms']);
|
||||||
echo '<input type="hidden" name="command" value="' . $_REQUEST['command'] . '">';
|
if ($suggestion != false) {
|
||||||
echo '<input type="hidden" name="searchpoint" value="' . $_REQUEST['searchpoint'] . '">';
|
echo '<form method="post" action="search.php" class="search_suggestion_inline">';
|
||||||
|
|
||||||
echo '<button type="submit" name="submit_param" value="submit_value" class="search_suggestion_link-button">';
|
echo '<input type="hidden" name="group" value="' . $_REQUEST['group'] . '">';
|
||||||
echo 'Did you mean: <b><i>' . htmlentities($suggestion) . '</i></b>';
|
echo '<input type="hidden" name="terms" value="' . $suggestion . '">';
|
||||||
echo '</button>';
|
echo '<input type="hidden" name="key" value="' . $_REQUEST['key'] . '">';
|
||||||
echo '</form>';
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<hr>";
|
echo "<hr>";
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -546,14 +548,19 @@ function display_search_tools($home = true)
|
||||||
echo '</tr></table></form>';
|
echo '</tr></table></form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_suggestion($word, $lang)
|
function get_suggestion($word)
|
||||||
{
|
{
|
||||||
if ($lang != 'en') {
|
global $OVERRIDES;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$pspell = pspell_new("en");
|
|
||||||
|
|
||||||
// Remove non alpha characters here
|
if (isset($OVERRIDES['lang_default'])) {
|
||||||
|
$lang = $OVERRIDES['lang_default'];
|
||||||
|
} else {
|
||||||
|
$lang = 'en';
|
||||||
|
}
|
||||||
|
|
||||||
|
$pspell = pspell_new($lang);
|
||||||
|
|
||||||
|
// Remove specific characters here
|
||||||
$word = preg_replace("/(\"\'\+\-\_)/", '', $word);
|
$word = preg_replace("/(\"\'\+\-\_)/", '', $word);
|
||||||
|
|
||||||
if (!preg_match("/ /", trim($word))) { // Just one word in search
|
if (!preg_match("/ /", trim($word))) { // Just one word in search
|
||||||
|
|
|
@ -143,6 +143,14 @@ return [
|
||||||
// Rate per second that a 'bot' may load pages
|
// Rate per second that a 'bot' may load pages
|
||||||
'throttle_hits_bot_loadrate' => '.1',
|
'throttle_hits_bot_loadrate' => '.1',
|
||||||
|
|
||||||
|
// Set 'log_lang' to true to log client browser language to debug.log
|
||||||
|
//'log_lang' => true,
|
||||||
|
|
||||||
|
// Set default language for search suggestions
|
||||||
|
// YOU MUST INSTALL aspell-xx for the language you wish to use
|
||||||
|
// Default is 'en' (english)
|
||||||
|
'lang_default' => 'en',
|
||||||
|
|
||||||
// Use this to create notices for things identified in msg body
|
// Use this to create notices for things identified in msg body
|
||||||
// 'regex' must be a full regex, including delimiters
|
// 'regex' must be a full regex, including delimiters
|
||||||
'display_notice_for_body_checks' => array(
|
'display_notice_for_body_checks' => array(
|
||||||
|
|
Loading…
Reference in New Issue