From b4b02316173c911f2b12d7c41b9729b28bc9c32c Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sun, 4 Sep 2016 15:56:46 +0200 Subject: [PATCH 1/3] [fix] links in new tabs without js ++ noopener bug fix - closes #674 --- searx/preferences.py | 3 ++- .../courgette/result_templates/code.html | 4 ++-- .../courgette/result_templates/default.html | 2 +- .../courgette/result_templates/images.html | 4 ++-- .../courgette/result_templates/map.html | 2 +- .../courgette/result_templates/torrent.html | 4 ++-- .../courgette/result_templates/videos.html | 4 ++-- searx/templates/default/infobox.html | 2 +- searx/templates/default/preferences.html | 9 +++++++++ .../templates/default/result_templates/code.html | 6 +++--- .../default/result_templates/default.html | 4 ++-- .../default/result_templates/images.html | 4 ++-- .../templates/default/result_templates/map.html | 4 ++-- .../default/result_templates/torrent.html | 4 ++-- .../default/result_templates/videos.html | 4 ++-- searx/templates/oscar/infobox.html | 3 ++- searx/templates/oscar/macros.html | 16 ++++++++++------ searx/templates/oscar/preferences.html | 9 +++++++++ searx/templates/oscar/result_templates/code.html | 2 +- .../oscar/result_templates/default.html | 2 +- .../templates/oscar/result_templates/images.html | 6 +++--- .../templates/oscar/result_templates/videos.html | 2 +- searx/webapp.py | 9 ++++++++- 23 files changed, 70 insertions(+), 39 deletions(-) diff --git a/searx/preferences.py b/searx/preferences.py index e19ae7502..ed7b6f6cd 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -227,7 +227,8 @@ class Preferences(object): 'safesearch': MapSetting(settings['search']['safe_search'], map={'0': 0, '1': 1, '2': 2}), - 'theme': EnumStringSetting(settings['ui']['default_theme'], choices=themes)} + 'theme': EnumStringSetting(settings['ui']['default_theme'], choices=themes), + 'results_on_new_tab': MapSetting(False, map={'0': False, '1': True})} self.engines = EnginesSetting('engines', choices=engines) self.plugins = PluginsSetting('plugins', choices=plugins) diff --git a/searx/templates/courgette/result_templates/code.html b/searx/templates/courgette/result_templates/code.html index 726f305cb..953617e84 100644 --- a/searx/templates/courgette/result_templates/code.html +++ b/searx/templates/courgette/result_templates/code.html @@ -1,8 +1,8 @@
-

{% if result['favicon'] %}{{result['favicon']}}{% endif %}{{ result.title|safe }}

+

{% if result['favicon'] %}{{result['favicon']}}{% endif %}{{ result.title|safe }}

{% if result.publishedDate %}{{ result.publishedDate }}{% endif %}

{% if result.img_src %}{% endif %}{% if result.content %}{{ result.content|safe }}
{% endif %}

- {% if result.repository %}

{{ result.repository }}

{% endif %} + {% if result.repository %}

{{ result.repository }}

{% endif %}
{{ result.codelines|code_highlighter(result.code_language)|safe }}
diff --git a/searx/templates/courgette/result_templates/default.html b/searx/templates/courgette/result_templates/default.html index 585ecf3f5..5f2ead63f 100644 --- a/searx/templates/courgette/result_templates/default.html +++ b/searx/templates/courgette/result_templates/default.html @@ -5,7 +5,7 @@ {% endif %}
-

{{ result.title|safe }}

+

{{ result.title|safe }}

{% if result.publishedDate %}{{ result.publishedDate }}{% endif %}

{% if result.content %}{{ result.content|safe }}
{% endif %}

{{ result.pretty_url }}‎

diff --git a/searx/templates/courgette/result_templates/images.html b/searx/templates/courgette/result_templates/images.html index 87fc7744c..49acb3b61 100644 --- a/searx/templates/courgette/result_templates/images.html +++ b/searx/templates/courgette/result_templates/images.html @@ -1,6 +1,6 @@ diff --git a/searx/templates/courgette/result_templates/map.html b/searx/templates/courgette/result_templates/map.html index 585ecf3f5..5f2ead63f 100644 --- a/searx/templates/courgette/result_templates/map.html +++ b/searx/templates/courgette/result_templates/map.html @@ -5,7 +5,7 @@ {% endif %}
-

{{ result.title|safe }}

+

{{ result.title|safe }}

{% if result.publishedDate %}{{ result.publishedDate }}{% endif %}

{% if result.content %}{{ result.content|safe }}
{% endif %}

{{ result.pretty_url }}‎

diff --git a/searx/templates/courgette/result_templates/torrent.html b/searx/templates/courgette/result_templates/torrent.html index 33b574244..2fd8395ad 100644 --- a/searx/templates/courgette/result_templates/torrent.html +++ b/searx/templates/courgette/result_templates/torrent.html @@ -2,12 +2,12 @@ {% if "icon_"~result.engine~".ico" in favicons %} {{result.engine}} {% endif %} -

{{ result.title|safe }}

+

{{ result.title|safe }}

{% if result.content %}{{ result.content|safe }}
{% endif %} {{ _('Seeder') }} : {{ result.seed }}, {{ _('Leecher') }} : {{ result.leech }}
{% if result.magnetlink %}{{ _('magnet link') }}{% endif %} - {% if result.torrentfile %}{{ _('torrent file') }}{% endif %} + {% if result.torrentfile %}{{ _('torrent file') }}{% endif %}

{{ result.pretty_url }}‎

diff --git a/searx/templates/courgette/result_templates/videos.html b/searx/templates/courgette/result_templates/videos.html index ceed8b28f..b3e19e024 100644 --- a/searx/templates/courgette/result_templates/videos.html +++ b/searx/templates/courgette/result_templates/videos.html @@ -3,8 +3,8 @@ {{result.engine}} {% endif %} -

{{ result.title|safe }}

+

{{ result.title|safe }}

{% if result.publishedDate %}{{ result.publishedDate }}
{% endif %} - {{ result.title|striptags }} + {{ result.title|striptags }}

{{ result.pretty_url }}‎

diff --git a/searx/templates/default/infobox.html b/searx/templates/default/infobox.html index ce26ac578..4dd25fabd 100644 --- a/searx/templates/default/infobox.html +++ b/searx/templates/default/infobox.html @@ -24,7 +24,7 @@
diff --git a/searx/templates/default/preferences.html b/searx/templates/default/preferences.html index a47dba458..1de9d2275 100644 --- a/searx/templates/default/preferences.html +++ b/searx/templates/default/preferences.html @@ -80,6 +80,15 @@

+
+ {{ _('Results on new tabs') }} +

+ +

+
{{ _('Currently used search engines') }} diff --git a/searx/templates/default/result_templates/code.html b/searx/templates/default/result_templates/code.html index ad1d97e9e..9e3ed20af 100644 --- a/searx/templates/default/result_templates/code.html +++ b/searx/templates/default/result_templates/code.html @@ -1,9 +1,9 @@
-

{% if result['favicon'] %}{{result['favicon']}}{% endif %}{{ result.title|safe }}

-

{{ result.pretty_url }}‎ {{ _('cached') }}

+

{% if result['favicon'] %}{{result['favicon']}}{% endif %}{{ result.title|safe }}

+

{{ result.pretty_url }}‎ {{ _('cached') }}

{% if result.publishedDate %}

{{ result.publishedDate }}

{% endif %}

{% if result.img_src %}{% endif %}{% if result.content %}{{ result.content|safe }}
{% endif %}

- {% if result.repository %}

{{ result.repository }}

{% endif %} + {% if result.repository %}

{{ result.repository }}

{% endif %}
{{ result.codelines|code_highlighter(result.code_language)|safe }} diff --git a/searx/templates/default/result_templates/default.html b/searx/templates/default/result_templates/default.html index 89091e280..da091174d 100644 --- a/searx/templates/default/result_templates/default.html +++ b/searx/templates/default/result_templates/default.html @@ -1,6 +1,6 @@
-

{% if "icon_"~result.engine~".ico" in favicons %}{{result.engine}}{% endif %}{{ result.title|safe }}

-

{{ result.pretty_url }}‎ {{ _('cached') }} +

{% if "icon_"~result.engine~".ico" in favicons %}{{result.engine}}{% endif %}{{ result.title|safe }}

+

{{ result.pretty_url }}‎ {{ _('cached') }} {% if result.publishedDate %}{{ result.publishedDate }}{% endif %}

{% if result.img_src %}{% endif %}{% if result.content %}{{ result.content|safe }}
{% endif %}

diff --git a/searx/templates/default/result_templates/images.html b/searx/templates/default/result_templates/images.html index d85f841ae..00f62abcc 100644 --- a/searx/templates/default/result_templates/images.html +++ b/searx/templates/default/result_templates/images.html @@ -1,6 +1,6 @@ diff --git a/searx/templates/default/result_templates/map.html b/searx/templates/default/result_templates/map.html index d413742e7..0200e0f6b 100644 --- a/searx/templates/default/result_templates/map.html +++ b/searx/templates/default/result_templates/map.html @@ -5,8 +5,8 @@ {% endif %}
-

{{ result.title|safe }}

-

{{ result.pretty_url }}‎ {{ _('cached') }} +

{{ result.title|safe }}

+

{{ result.pretty_url }}‎ {{ _('cached') }} {% if result.publishedDate %}{{ result.publishedDate }}{% endif %}

{% if result.img_src %}{% endif %}{% if result.content %}{{ result.content|safe }}
{% endif %}

diff --git a/searx/templates/default/result_templates/torrent.html b/searx/templates/default/result_templates/torrent.html index 4b2522ad0..67e058ae5 100644 --- a/searx/templates/default/result_templates/torrent.html +++ b/searx/templates/default/result_templates/torrent.html @@ -2,12 +2,12 @@ {% if "icon_"~result.engine~".ico" in favicons %} {{result.engine}} {% endif %} -

{{ result.title|safe }}

+

{{ result.title|safe }}

{{ result.pretty_url }}‎

{% if result.content %}

{{ result.content|safe }}

{% endif %}

{% if result.magnetlink %}{{ _('magnet link') }}{% endif %} - {% if result.torrentfile %}{{ _('torrent file') }}{% endif %} - + {% if result.torrentfile %}{{ _('torrent file') }}{% endif %} - {{ _('Seeder') }} : {{ result.seed }}, {{ _('Leecher') }} : {{ result.leech }}

diff --git a/searx/templates/default/result_templates/videos.html b/searx/templates/default/result_templates/videos.html index 5a377b70f..727f44c71 100644 --- a/searx/templates/default/result_templates/videos.html +++ b/searx/templates/default/result_templates/videos.html @@ -1,6 +1,6 @@
-

{% if "icon_"~result.engine~".ico" in favicons %}{{result.engine}}{% endif %}{{ result.title|safe }}

+

{% if "icon_"~result.engine~".ico" in favicons %}{{result.engine}}{% endif %}{{ result.title|safe }}

{% if result.publishedDate %}{{ result.publishedDate }}
{% endif %} - {{ result.title|striptags }} + {{ result.title|striptags }}

{{ result.url }}‎

diff --git a/searx/templates/oscar/infobox.html b/searx/templates/oscar/infobox.html index 70d12f2fb..c98fb0e63 100644 --- a/searx/templates/oscar/infobox.html +++ b/searx/templates/oscar/infobox.html @@ -1,3 +1,4 @@ +{% from 'oscar/macros.html' import result_link with context %}

{{ infobox.infobox }}

@@ -25,7 +26,7 @@
{% for url in infobox.urls %} -

{{ url.title }}

+

{{ result_link(url.url, url.title) }}

{% endfor %}
diff --git a/searx/templates/oscar/macros.html b/searx/templates/oscar/macros.html index bf51d5940..06881db02 100644 --- a/searx/templates/oscar/macros.html +++ b/searx/templates/oscar/macros.html @@ -9,16 +9,20 @@ {{ favicon }} {%- endmacro %} +{%- macro result_link(url, title, classes='') -%} +{{ title }} +{%- endmacro -%} + -{% macro result_header(result, favicons) -%} -

{% if result.engine~".png" in favicons %}{{ draw_favicon(result.engine) }} {% endif %}{{ result.title|safe }}

+{% macro result_header(result, favicons) -%} +

{% if result.engine~".png" in favicons %}{{ draw_favicon(result.engine) }} {% endif %}{{ result_link(result.url, result.title|safe) }}

{%- endmacro %} {% macro result_sub_header(result) -%} {% if result.publishedDate %}{% endif %} - {% if result.magnetlink %}{{ icon('magnet') }} {{ _('magnet link') }}{% endif %} - {% if result.torrentfile %}{{ icon('download-alt') }} {{ _('torrent file') }}{% endif %} + {% if result.magnetlink %} • {{ result_link(result.magnetlink, icon('magnet') + _('magnet link'), "magnetlink") }}{% endif %} + {% if result.torrentfile %} • {{ result_link(result.torrentfile, icon('download-alt') + _('torrent file'), "torrentfile") }}{% endif %} {%- endmacro %} @@ -28,7 +32,7 @@ {% for engine in result.engines %} {{ engine }} {% endfor %} - {{ icon('link') }} {{ _('cached') }} + {{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}
{{ result.pretty_url }}
{%- endmacro %} @@ -39,7 +43,7 @@ {% for engine in result.engines %} {{ engine }} {% endfor %} - {{ icon('link') }} {{ _('cached') }} + {{ result_link("https://web.archive.org/web/" + result.url, icon('link') + _('cached'), "text-info") }}
{{ result.pretty_url }}
{%- endmacro %} diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index 0e3848b7c..283b7ba88 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -117,6 +117,15 @@ {{ preferences_item_footer(_('Choose style for this theme'), _('Style'), rtl) }} + + {% set label = _('Results on new tabs') %} + {% set info = _('Open result links on new browser tabs') %} + {{ preferences_item_header(info, label, rtl) }} + + {{ preferences_item_footer(info, label, rtl) }}
diff --git a/searx/templates/oscar/result_templates/code.html b/searx/templates/oscar/result_templates/code.html index 582a2149c..ba74d0333 100644 --- a/searx/templates/oscar/result_templates/code.html +++ b/searx/templates/oscar/result_templates/code.html @@ -5,7 +5,7 @@ {% if result.content %}

{{ result.content|safe }}

{% endif %} -{% if result.repository %}

{{ icon('file') }} {{ result.repository }}

{% endif %} +{% if result.repository %}

{{ icon('file') }} {{ result.repository }}

{% endif %}
{{ result.codelines|code_highlighter(result.code_language)|safe }} diff --git a/searx/templates/oscar/result_templates/default.html b/searx/templates/oscar/result_templates/default.html index f283693c3..3ed0f3122 100644 --- a/searx/templates/oscar/result_templates/default.html +++ b/searx/templates/oscar/result_templates/default.html @@ -1,4 +1,4 @@ -{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, result_footer_rtl, icon %} +{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, result_footer_rtl, icon with context %} {{ result_header(result, favicons) }} {{ result_sub_header(result) }} diff --git a/searx/templates/oscar/result_templates/images.html b/searx/templates/oscar/result_templates/images.html index 1bfff0a1a..2d94ea6a5 100644 --- a/searx/templates/oscar/result_templates/images.html +++ b/searx/templates/oscar/result_templates/images.html @@ -1,6 +1,6 @@ {% from 'oscar/macros.html' import draw_favicon %} - + {{ result.title|striptags }} @@ -20,8 +20,8 @@ {{ result.engine }}

{{ result.pretty_url }}

- {{ _('Get image') }} - {{ _('View source') }} + {{ _('Get image') }} + {{ _('View source') }}
diff --git a/searx/templates/oscar/result_templates/videos.html b/searx/templates/oscar/result_templates/videos.html index af4841453..36fb26240 100644 --- a/searx/templates/oscar/result_templates/videos.html +++ b/searx/templates/oscar/result_templates/videos.html @@ -15,7 +15,7 @@
- {{ result.title|striptags }} {{ result.engine }} + {{ result.title|striptags }} {{ result.engine }} {% if result.content %}

{{ result.content|safe }}

{% endif %}
diff --git a/searx/webapp.py b/searx/webapp.py index e118fee2b..800bde004 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -320,6 +320,8 @@ def render(template_name, override_theme=None, **kwargs): kwargs['instance_name'] = settings['general']['instance_name'] + kwargs['results_on_new_tab'] = request.preferences.get_value('results_on_new_tab') + kwargs['scripts'] = set() for plugin in request.user_plugins: for script in plugin.js_dependencies: @@ -338,7 +340,11 @@ def render(template_name, override_theme=None, **kwargs): def pre_request(): # merge GET, POST vars preferences = Preferences(themes, categories.keys(), engines, plugins) - preferences.parse_cookies(request.cookies) + try: + preferences.parse_cookies(request.cookies) + except: + # TODO throw error message to the user + logger.warning('Invalid config') request.preferences = preferences request.form = dict(request.form.items()) @@ -553,6 +559,7 @@ def preferences(): lang = request.preferences.get_value('language') disabled_engines = request.preferences.engines.get_disabled() allowed_plugins = request.preferences.plugins.get_enabled() + results_on_new_tab = request.preferences.get_value('results_on_new_tab') # stats for preferences page stats = {} From c2f4d4449ddba0a3899a5d4098e2c5e451c83ac8 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sun, 4 Sep 2016 18:38:25 +0200 Subject: [PATCH 2/3] [fix] 404 page localization --- searx/templates/courgette/404.html | 4 +++- searx/templates/default/404.html | 4 +++- searx/templates/oscar/404.html | 4 +++- searx/templates/pix-art/404.html | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/searx/templates/courgette/404.html b/searx/templates/courgette/404.html index 465039e3a..7a317f023 100644 --- a/searx/templates/courgette/404.html +++ b/searx/templates/courgette/404.html @@ -2,6 +2,8 @@ {% block content %}

{{ _('Page not found') }}

-

{{ _('Go to search page.') }}

+ {% autoescape false %} +

{{ _('Go to %(search_page)s.', search_page='{}'.format(url_for('index'), _('search page'))) }}

+ {% endautoescape %}
{% endblock %} diff --git a/searx/templates/default/404.html b/searx/templates/default/404.html index 18012f2ac..dc968a109 100644 --- a/searx/templates/default/404.html +++ b/searx/templates/default/404.html @@ -2,6 +2,8 @@ {% block content %}

{{ _('Page not found') }}

-

{{ _('Go to search page.') }}

+ {% autoescape false %} +

{{ _('Go to %(search_page)s.', search_page='{}'.format(url_for('index'), _('search page'))) }}

+ {% endautoescape %}
{% endblock %} diff --git a/searx/templates/oscar/404.html b/searx/templates/oscar/404.html index 39836ce0e..cdb31db73 100644 --- a/searx/templates/oscar/404.html +++ b/searx/templates/oscar/404.html @@ -2,6 +2,8 @@ {% block content %}

{{ _('Page not found') }}

-

{{ _('Go to search page.') }}

+ {% autoescape false %} +

{{ _('Go to %(search_page)s.', search_page='{}'.format(url_for('index'), _('search page'))) }}

+ {% endautoescape %}
{% endblock %} diff --git a/searx/templates/pix-art/404.html b/searx/templates/pix-art/404.html index 27e89ae02..27a614084 100644 --- a/searx/templates/pix-art/404.html +++ b/searx/templates/pix-art/404.html @@ -2,6 +2,8 @@ {% block content %}

{{ _('Page not found') }}

-

{{ _('Go to search page.') }}

+ {% autoescape false %} +

{{ _('Go to %(search_page)s.', search_page='{}'.format(url_for('index'), _('search page'))) }}

+ {% endautoescape %}
{% endblock %} From 465d47283fa934eb08efab897cb9fcdcf29b21c5 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sun, 4 Sep 2016 19:07:07 +0200 Subject: [PATCH 3/3] [fix] 404 page localization #2 --- searx/templates/courgette/404.html | 2 +- searx/templates/default/404.html | 2 +- searx/templates/oscar/404.html | 2 +- searx/templates/pix-art/404.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/searx/templates/courgette/404.html b/searx/templates/courgette/404.html index 7a317f023..77f1287ab 100644 --- a/searx/templates/courgette/404.html +++ b/searx/templates/courgette/404.html @@ -3,7 +3,7 @@

{{ _('Page not found') }}

{% autoescape false %} -

{{ _('Go to %(search_page)s.', search_page='{}'.format(url_for('index'), _('search page'))) }}

+

{{ _('Go to %(search_page)s.', search_page='{}'.decode('utf-8').format(url_for('index'), _('search page'))) }}

{% endautoescape %}
{% endblock %} diff --git a/searx/templates/default/404.html b/searx/templates/default/404.html index dc968a109..1d88f86c4 100644 --- a/searx/templates/default/404.html +++ b/searx/templates/default/404.html @@ -3,7 +3,7 @@

{{ _('Page not found') }}

{% autoescape false %} -

{{ _('Go to %(search_page)s.', search_page='{}'.format(url_for('index'), _('search page'))) }}

+

{{ _('Go to %(search_page)s.', search_page='{}'.decode('utf-8').format(url_for('index'), _('search page'))) }}

{% endautoescape %}
{% endblock %} diff --git a/searx/templates/oscar/404.html b/searx/templates/oscar/404.html index cdb31db73..11d789564 100644 --- a/searx/templates/oscar/404.html +++ b/searx/templates/oscar/404.html @@ -3,7 +3,7 @@

{{ _('Page not found') }}

{% autoescape false %} -

{{ _('Go to %(search_page)s.', search_page='{}'.format(url_for('index'), _('search page'))) }}

+

{{ _('Go to %(search_page)s.', search_page='{}'.decode('utf-8').format(url_for('index'), _('search page'))) }}

{% endautoescape %}
{% endblock %} diff --git a/searx/templates/pix-art/404.html b/searx/templates/pix-art/404.html index 27a614084..592e8610f 100644 --- a/searx/templates/pix-art/404.html +++ b/searx/templates/pix-art/404.html @@ -3,7 +3,7 @@

{{ _('Page not found') }}

{% autoescape false %} -

{{ _('Go to %(search_page)s.', search_page='{}'.format(url_for('index'), _('search page'))) }}

+

{{ _('Go to %(search_page)s.', search_page='{}'.decode('utf-8').format(url_for('index'), _('search page'))) }}

{% endautoescape %}
{% endblock %}