post search: internationalize and use config values
This commit is contained in:
parent
472b518165
commit
629d616de5
31
search.php
31
search.php
@ -1,11 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
require 'inc/functions.php';
|
require 'inc/functions.php';
|
||||||
|
|
||||||
$queries_per_minutes = Array(15, 2);
|
if (!$config['search']['enable']) {
|
||||||
$queries_per_minutes_all = Array(50, 2);
|
die(_("Post search is disabled"));
|
||||||
$search_limit = 100;
|
}
|
||||||
|
|
||||||
$boards = Array('new', 'r9k', 'v', 'edu', 'azn', 'h', 'meta');
|
$queries_per_minutes = $config['search']['queries_per_minutes'];
|
||||||
|
$queries_per_minutes_all = $config['search']['queries_per_minutes_all'];
|
||||||
|
$search_limit = $config['search']['search_limit'];
|
||||||
|
|
||||||
|
$boards = $config['search']['boards'];
|
||||||
|
|
||||||
$body = Element('search_form.html', Array('boards' => $boards, 'board' => isset($_POST['board']) ? $_POST['board'] : false, 'search' => isset($_POST['search']) ? str_replace('"', '"', utf8tohtml($_POST['search'])) : false));
|
$body = Element('search_form.html', Array('boards' => $boards, 'board' => isset($_POST['board']) ? $_POST['board'] : false, 'search' => isset($_POST['search']) ? str_replace('"', '"', utf8tohtml($_POST['search'])) : false));
|
||||||
|
|
||||||
@ -18,13 +22,13 @@
|
|||||||
$query->bindValue(':time', time() - ($queries_per_minutes[1] * 60));
|
$query->bindValue(':time', time() - ($queries_per_minutes[1] * 60));
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
if($query->fetchColumn() > $queries_per_minutes[0])
|
if($query->fetchColumn() > $queries_per_minutes[0])
|
||||||
error('Wait a while before searching again, please.');
|
error(_('Wait a while before searching again, please.'));
|
||||||
|
|
||||||
$query = prepare("SELECT COUNT(*) FROM `search_queries` WHERE `time` > :time");
|
$query = prepare("SELECT COUNT(*) FROM `search_queries` WHERE `time` > :time");
|
||||||
$query->bindValue(':time', time() - ($queries_per_minutes_all[1] * 60));
|
$query->bindValue(':time', time() - ($queries_per_minutes_all[1] * 60));
|
||||||
$query->execute() or error(db_error($query));
|
$query->execute() or error(db_error($query));
|
||||||
if($query->fetchColumn() > $queries_per_minutes_all[0])
|
if($query->fetchColumn() > $queries_per_minutes_all[0])
|
||||||
error('Wait a while before searching again, please.');
|
error(_('Wait a while before searching again, please.'));
|
||||||
|
|
||||||
|
|
||||||
$query = prepare("INSERT INTO `search_queries` VALUES (:ip, :time, :query)");
|
$query = prepare("INSERT INTO `search_queries` VALUES (:ip, :time, :query)");
|
||||||
@ -35,6 +39,11 @@
|
|||||||
|
|
||||||
_syslog(LOG_NOTICE, 'Searched /' . $_POST['board'] . '/ for "' . $phrase . '"');
|
_syslog(LOG_NOTICE, 'Searched /' . $_POST['board'] . '/ for "' . $phrase . '"');
|
||||||
|
|
||||||
|
// Cleanup search queries table
|
||||||
|
$query = prepare("DELETE FROM `search_queries` WHERE `time` <= :time");
|
||||||
|
$query->bindValue(':time', time() - ($queries_per_minutes_all[1] * 60));
|
||||||
|
$query->execute() or error(db_error($query));
|
||||||
|
|
||||||
openBoard($_POST['board']);
|
openBoard($_POST['board']);
|
||||||
|
|
||||||
$filters = Array();
|
$filters = Array();
|
||||||
@ -44,7 +53,7 @@
|
|||||||
$name = $m[2];
|
$name = $m[2];
|
||||||
$value = isset($m[4]) ? $m[4] : $m[3];
|
$value = isset($m[4]) ? $m[4] : $m[3];
|
||||||
|
|
||||||
if(!in_array($name, Array('id', 'thread', 'subject', 'name'))) {
|
if(!in_array($name, array('id', 'thread', 'subject', 'name'))) {
|
||||||
// unknown filter
|
// unknown filter
|
||||||
return $m[0];
|
return $m[0];
|
||||||
}
|
}
|
||||||
@ -116,7 +125,7 @@
|
|||||||
|
|
||||||
if($query->rowCount() == $search_limit) {
|
if($query->rowCount() == $search_limit) {
|
||||||
_syslog(LOG_WARNING, 'Query too broad.');
|
_syslog(LOG_WARNING, 'Query too broad.');
|
||||||
$body .= '<p class="unimportant" style="text-align:center">(Query too broad.)</p>';
|
$body .= '<p class="unimportant" style="text-align:center">('._('Query too broad.').')</p>';
|
||||||
echo Element('page.html', Array(
|
echo Element('page.html', Array(
|
||||||
'config'=>$config,
|
'config'=>$config,
|
||||||
'title'=>'Search',
|
'title'=>'Search',
|
||||||
@ -136,7 +145,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($temp))
|
if(!empty($temp))
|
||||||
$_body .= '<fieldset><legend>' . $query->rowCount() . ' result' . ($query->rowCount() != 1 ? 's' : '') . ' in <a href="/' .
|
$_body .= '<fieldset><legend>' . $query->rowCount() .
|
||||||
|
sprintf(ngettext('%d result in', '%d results in', $query->rowCount()),
|
||||||
|
$query->rowCount) . ' <a href="/' .
|
||||||
sprintf($config['board_path'], $board['uri']) . $config['file_index'] .
|
sprintf($config['board_path'], $board['uri']) . $config['file_index'] .
|
||||||
'">' .
|
'">' .
|
||||||
sprintf($config['board_abbreviation'], $board['uri']) . ' - ' . $board['title'] .
|
sprintf($config['board_abbreviation'], $board['uri']) . ' - ' . $board['title'] .
|
||||||
@ -146,7 +157,7 @@
|
|||||||
if(!empty($_body))
|
if(!empty($_body))
|
||||||
$body .= $_body;
|
$body .= $_body;
|
||||||
else
|
else
|
||||||
$body .= '<p style="text-align:center" class="unimportant">(No results.)</p>';
|
$body .= '<p style="text-align:center" class="unimportant">('._('No results.').')</p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo Element('page.html', Array(
|
echo Element('page.html', Array(
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<div class="ban">
|
<div class="ban">
|
||||||
<h2>Search</h2>
|
<h2>{% trans %}Search{% endtrans %}</h2>
|
||||||
<form style="display:inline" action="" method="post">
|
<form style="display:inline" action="" method="post">
|
||||||
<p>
|
<p>
|
||||||
<label style="display:inline" for="search">Phrase:</label>
|
<label style="display:inline" for="search">{% trans %}Phrase:{% endtrans %}</label>
|
||||||
<input id="search" name="search" type="text" size="55" value="{{ search }}">
|
<input id="search" name="search" type="text" size="55" value="{{ search }}">
|
||||||
<select name="board">
|
<select name="board">
|
||||||
<option value="none">Select board…</option>
|
<option value="none">{% trans %}Select board{% endtrans %}…</option>
|
||||||
{% for b in boards %}
|
{% for b in boards %}
|
||||||
<option value="{{ b }}"{% if b == board %} selected{% endif %}>/{{ b }}/</option>
|
<option value="{{ b }}"{% if b == board %} selected{% endif %}>/{{ b }}/</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -14,6 +14,6 @@
|
|||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
<p style="font-size:8pt;margin:5px">
|
<p style="font-size:8pt;margin:5px">
|
||||||
Search is case-insensitive and based on keywords. To match exact phrases, use "quotes". Use an asterisk (*) for wildcard.</p><p style="font-size:8pt;margin:5px">You may apply the following filters to your searches: <strong>id</strong>, <strong>thread</strong>, <strong>subject</strong>, and <strong>name</strong>. To apply a filter, simply add to your query, for example, <em>name:Anonymous</em> or <em>subject:"Some Thread"</em>. Wildcards cannot be used in filters.
|
{% trans %}Search is case-insensitive and based on keywords. To match exact phrases, use "quotes". Use an asterisk (*) for wildcard.</p><p style="font-size:8pt;margin:5px">You may apply the following filters to your searches: <strong>id</strong>, <strong>thread</strong>, <strong>subject</strong>, and <strong>name</strong>. To apply a filter, simply add to your query, for example, <em>name:Anonymous</em> or <em>subject:"Some Thread"</em>. Wildcards cannot be used in filters.{% endtrans %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user