mirror of
https://github.com/moparisthebest/wallabag
synced 2024-12-23 15:58:55 -05:00
Important fixes for search engine (thx @mariroz)
So sorry for the mess... :( * search only in users' own articles * sanitized what is searched * display what is searched * pagination, sorting available when searching * use existing function to query db * bad encoding caracters fixed * link to JQuery into default theme, no longer in each theme * some spaces instead of tabs
This commit is contained in:
parent
22db488d21
commit
d967a1fa14
@ -389,12 +389,13 @@ class Database {
|
||||
return $this->getHandle()->lastInsertId($column);
|
||||
}
|
||||
|
||||
public function search($term){
|
||||
$search = '%'.$term.'%';
|
||||
$query = $this->getHandle()->prepare("SELECT * FROM entries WHERE content LIKE ? OR title LIKE ? OR url LIKE ?"); //searches in content, title and URL
|
||||
$query->execute(array($search,$search,$search));
|
||||
$entries = $query->fetchAll();
|
||||
return $entries;
|
||||
public function search($term,$id,$limit = ''){
|
||||
$search = '%'.$term.'%';
|
||||
$sql_action = ("SELECT * FROM entries WHERE user_id=? AND (content LIKE ? OR title LIKE ? OR url LIKE ?) "); //searches in content, title and URL
|
||||
$sql_action .= $this->getEntriesOrder().' ' . $limit;
|
||||
$params_action = array($id,$search,$search,$search);
|
||||
$query = $this->executeQuery($sql_action, $params_action);
|
||||
return $query->fetchAll();
|
||||
}
|
||||
|
||||
public function retrieveAllTags($user_id, $term = null) {
|
||||
|
@ -604,12 +604,18 @@ class Poche
|
||||
);
|
||||
break;
|
||||
|
||||
case 'search':
|
||||
if (isset($_GET['search'])){
|
||||
$search = $_GET['search'];
|
||||
$tpl_vars['entries'] = $this->store->search($search);
|
||||
$tpl_vars['nb_results'] = count($tpl_vars['entries']);
|
||||
}
|
||||
case 'search':
|
||||
if (isset($_GET['search'])){
|
||||
$search = filter_var($_GET['search'], FILTER_SANITIZE_STRING);
|
||||
$tpl_vars['entries'] = $this->store->search($search,$this->user->getId());
|
||||
$count = count($tpl_vars['entries']);
|
||||
$this->pagination->set_total($count);
|
||||
$page_links = str_replace(array('previous', 'next'), array(_('previous'), _('next')),
|
||||
$this->pagination->page_links('?view=' . $view . '?search=' . $search . '&sort=' . $_SESSION['sort'] . '&' ));
|
||||
$tpl_vars['page_links'] = $page_links;
|
||||
$tpl_vars['nb_results'] = $count;
|
||||
$tpl_vars['search_term'] = $search;
|
||||
}
|
||||
break;
|
||||
case 'view':
|
||||
$entry = $this->store->retrieveOneById($id, $this->user->getId());
|
||||
|
@ -24,7 +24,7 @@ if (isset($_GET['clean'])) {
|
||||
|
||||
if (isset($_POST['download'])) {
|
||||
if (!file_put_contents("cache/vendor.zip", fopen("http://static.wallabag.org/files/vendor.zip", 'r'))) {
|
||||
$errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually<∕a> and unzip it in your wallabag folder.';
|
||||
$errors[] = 'Impossible to download vendor.zip. Please <a href="http://wllbg.org/vendor">download it manually</a> and unzip it in your wallabag folder.';
|
||||
}
|
||||
else {
|
||||
if (extension_loaded('zip')) {
|
||||
@ -165,7 +165,7 @@ else if (isset($_POST['install'])) {
|
||||
<!--[if IE]>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=10">
|
||||
<![endif]-->
|
||||
<title>wallabag — installation</title>
|
||||
<title>wallabag - installation</title>
|
||||
<link rel="shortcut icon" type="image/x-icon" href="themes/baggy/img/favicon.ico" />
|
||||
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="themes/baggy/img/apple-touch-icon-144x144-precomposed.png">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="themes/baggy/img/apple-touch-icon-72x72-precomposed.png">
|
||||
@ -176,7 +176,7 @@ else if (isset($_POST['install'])) {
|
||||
<link rel="stylesheet" href="themes/baggy/css/main.css" media="all">
|
||||
<link rel="stylesheet" href="themes/baggy/css/messages.css" media="all">
|
||||
<link rel="stylesheet" href="themes/baggy/css/print.css" media="print">
|
||||
<script src="themes/baggy/js/jquery-2.0.3.min.js"></script>
|
||||
<script src="themes/default/js/jquery-2.0.3.min.js"></script>
|
||||
<script src="themes/baggy/js/init.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -25,9 +25,15 @@
|
||||
{% block pager %}
|
||||
{% if nb_results > 1 %}
|
||||
<div class="results">
|
||||
<div class="nb-results">{{ nb_results }} {% trans "results" %}</div>
|
||||
<div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div>
|
||||
{{ page_links | raw }}
|
||||
</div>
|
||||
{% elseif nb_results == 1 %}
|
||||
{% if search_term is defined %}
|
||||
<div class="results">
|
||||
<div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
<div id="list-entries" class="list-entries">
|
||||
|
@ -26,9 +26,15 @@
|
||||
{% block pager %}
|
||||
{% if nb_results > 1 %}
|
||||
<div class="results">
|
||||
<div class="nb-results">{{ nb_results }} {% trans "results" %}</div>
|
||||
<div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div>
|
||||
{{ page_links | raw }}
|
||||
</div>
|
||||
{% elseif nb_results == 1 %}
|
||||
{% if search_term is defined %}
|
||||
<div class="results">
|
||||
<div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% for entry in entries %}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{% if entries|length > 1 %}
|
||||
<ul id="sort">
|
||||
<li><a href="./?sort=ia&view={{ view }}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by date asc" %}" title="{% trans "by date asc" %}" /></a> {% trans "by date" %} <a href="./?sort=id&view={{ view }}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li>
|
||||
<li><a href="./?sort=ta&view={{ view }}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by title asc" %}" title="{% trans "by title asc" %}" /></a> {% trans "by title" %} <a href="./?sort=td&view={{ view }}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li>
|
||||
<li><a href="./?sort=ia&view={{ view }}{% if search_term is defined %}&search={{ search_term }}{% endif %}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by date asc" %}" title="{% trans "by date asc" %}" /></a> {% trans "by date" %} <a href="./?sort=id&view={{ view }}{% if search_term is defined %}&search={{ search_term }}{% endif %}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by date desc" %}" title="{% trans "by date desc" %}" /></a></li>
|
||||
<li><a href="./?sort=ta&view={{ view }}{% if search_term is defined %}&search={{ search_term }}{% endif %}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/top.png" alt="{% trans "by title asc" %}" title="{% trans "by title asc" %}" /></a> {% trans "by title" %} <a href="./?sort=td&view={{ view }}{% if search_term is defined %}&search={{ search_term }}{% endif %}&id={{ id }}"><img src="{{ poche_url }}themes/{{ theme }}/img/{{ theme }}/down.png" alt="{% trans "by title desc" %}" title="{% trans "by title desc" %}" /></a></li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
@ -26,9 +26,15 @@
|
||||
{% block pager %}
|
||||
{% if nb_results > 1 %}
|
||||
<div class="results">
|
||||
<div class="nb-results">{{ nb_results }} {% trans "results" %}</div>
|
||||
<div class="nb-results">{{ nb_results }} {% trans "results" %}{% if search_term is defined %}{% trans " found for « " %} {{ search_term }} »{% endif %}</div>
|
||||
{{ page_links | raw }}
|
||||
</div>
|
||||
{% elseif nb_results == 1 %}
|
||||
{% if search_term is defined %}
|
||||
<div class="results">
|
||||
<div class="nb-results">{% trans "Only one result found for " %} « {{ search_term }} »</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% for entry in entries %}
|
||||
|
Loading…
Reference in New Issue
Block a user