diff --git a/app/Http/Controllers/MetaGerSearch.php b/app/Http/Controllers/MetaGerSearch.php index 9d2de525c9cd57c6bbaaf92e4476ebadd8b67912..ae0b4d9c162e37f4c0e451d187f7654b54b2411f 100644 --- a/app/Http/Controllers/MetaGerSearch.php +++ b/app/Http/Controllers/MetaGerSearch.php @@ -67,12 +67,6 @@ class MetaGerSearch extends Controller return response($responseContent); } - # Die Quicktips als Job erstellen - $quicktips = $metager->createQuicktips(); - if (!empty($timings)) { - $timings["createQuicktips"] = microtime(true) - $time; - } - # Suche für alle zu verwendenden Suchmaschinen als Job erstellen, # auf Ergebnisse warten und die Ergebnisse laden $metager->createSearchEngines($request, $timings); @@ -89,12 +83,6 @@ class MetaGerSearch extends Controller $timings["retrieveResults"] = microtime(true) - $time; } - # Versuchen die Ergebnisse der Quicktips zu laden - $quicktipResults = $quicktips->loadResults(); - if (!empty($timings)) { - $timings["loadResults"] = microtime(true) - $time; - } - # Alle Ergebnisse vor der Zusammenführung ranken: $metager->rankAll(); if (!empty($timings)) { @@ -121,7 +109,7 @@ class MetaGerSearch extends Controller } # Die Ausgabe erstellen: - $resultpage = $metager->createView($quicktipResults); + $resultpage = $metager->createView(); if ($spamEntry !== null) { Cache::put('spam.' . $metager->getFokus() . "." . md5($spamEntry), $resultpage->render(), 604800); } @@ -278,4 +266,12 @@ class MetaGerSearch extends Controller ->with('title', trans('tips.title')) ->with('tips', $tips); } + + public function quicktips($search) + { + $quicktips = new \App\Models\Quicktips\Quicktips($search); + return view('quicktips') + ->with('quicktips', $quicktips->getResults()) + ->with('search', $search); + } } diff --git a/app/MetaGer.php b/app/MetaGer.php index 495ce417e5c820cd36a2978957d764bc623e369a..ccfcd3520884c2dff6fb34dc14f9f2bbd77ac5a3 100644 --- a/app/MetaGer.php +++ b/app/MetaGer.php @@ -131,7 +131,7 @@ class MetaGer } # Erstellt aus den gesammelten Ergebnissen den View - public function createView($quicktipResults = []) + public function createView() { # Hiermit werden die evtl. ausgewählten SuMas extrahiert, damit die Input-Boxen richtig gesetzt werden können $focusPages = []; @@ -171,7 +171,7 @@ class MetaGer ->with('apiAuthorized', $this->apiAuthorized) ->with('metager', $this) ->with('browser', (new Agent())->browser()) - ->with('quicktips', $quicktipResults) + ->with('quicktips', action('MetaGerSearch@quicktips', ["search" => $this->eingabe])) ->with('focus', $this->fokus) ->with('resultcount', count($this->results)); } @@ -244,7 +244,7 @@ class MetaGer ->with('apiAuthorized', $this->apiAuthorized) ->with('metager', $this) ->with('browser', (new Agent())->browser()) - ->with('quicktips', $quicktipResults) + ->with('quicktips', action('MetaGerSearch@quicktips', ["search" => $this->eingabe])) ->with('resultcount', count($this->results)) ->with('focus', $this->fokus); break; @@ -464,13 +464,6 @@ class MetaGer } } - public function createQuicktips() - { - # Die quicktips werden als job erstellt und zur Abarbeitung freigegeben - $quicktips = new \App\Models\Quicktips\Quicktips($this->q, LaravelLocalization::getCurrentLocale(), $this->getTime()); - return $quicktips; - } - /* * Die Erstellung der Suchmaschinen bis die Ergebnisse da sind mit Unterfunktionen */ diff --git a/app/Models/Quicktips/Quicktips.php b/app/Models/Quicktips/Quicktips.php index 06306dcde031b42f5b8b3f9cfd208d8e7a0f7680..1088e82cd777f49dd400e08e44f0dab80996ce8d 100644 --- a/app/Models/Quicktips/Quicktips.php +++ b/app/Models/Quicktips/Quicktips.php @@ -3,51 +3,42 @@ namespace App\Models\Quicktips; use Cache; -use Illuminate\Foundation\Bus\DispatchesJobs; -use Illuminate\Support\Facades\Redis; +use LaravelLocalization; use Log; class Quicktips { - use DispatchesJobs; private $quicktipUrl = "/1.1/quicktips.xml"; + private $results = []; const QUICKTIP_NAME = "quicktips"; const CACHE_DURATION = 60; private $hash; - public function __construct($search, $locale, $max_time) + public function __construct($search/*, $locale, $max_time*/) { + $locale = LaravelLocalization::getCurrentLocale(); if (env("APP_ENV") === "production") { $this->quicktipUrl = "https://quicktips.metager.de" . $this->quicktipUrl; } else { $this->quicktipUrl = "https://dev.quicktips.metager.de" . $this->quicktipUrl; } - $this->startSearch($search, $locale, $max_time); + $this->startSearch($search, $locale); } - public function startSearch($search, $locale, $max_time) + public function startSearch($search, $locale) { $url = $this->quicktipUrl . "?search=" . $this->normalize_search($search) . "&locale=" . $locale; $this->hash = md5($url); if (!Cache::has($this->hash)) { - - // Queue this search - $mission = [ - "resulthash" => $this->hash, - "url" => $url, - "username" => null, - "password" => null, - "headers" => [], - "cacheDuration" => self::CACHE_DURATION, - ]; - - $mission = json_encode($mission); - - Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission); + $results = file_get_contents($url); + Cache::put($this->hash, $results, Quicktips::CACHE_DURATION); + } else { + $results = Cache::get($this->hash); } + $this->results = $this->loadResults($results); } /** @@ -56,9 +47,8 @@ class Quicktips * 2. Parse the results * Returns an empty array if no results are found */ - public function loadResults() + public function loadResults($resultsRaw) { - $resultsRaw = $this->retrieveResults($this->hash); if ($resultsRaw) { $results = $this->parseResults($resultsRaw); return $results; @@ -175,4 +165,9 @@ class Quicktips { return urlencode($search); } + + public function getResults() + { + return $this->results; + } } diff --git a/resources/js/result-saver.js b/resources/js/result-saver.js index 50706213d8f0945ac32dbf99b7721163360a4cdc..c4c6e113ecfe36e63953f26b1774aeedff24d47e 100644 --- a/resources/js/result-saver.js +++ b/resources/js/result-saver.js @@ -16,7 +16,7 @@ $(document).ready(function () { * Load all saved results and sort them * @param {String} sort The type of sorting function to call for these results */ -function Results () { +function Results() { if (!localStorage) return; this.prefix = 'result_'; this.sort = 'chronological'; @@ -29,8 +29,8 @@ function Results () { */ Results.prototype.addResult = function (result) { if (this.results.every(function (val) { - return val.hash !== result.hash; - })) { + return val.hash !== result.hash; + })) { this.results.push(result); } }; @@ -120,7 +120,7 @@ Results.prototype.updateResultPageInterface = function () { <h1>' + t('result-saver.title') + '</h1>\ </div>\ '); - $('#additions-container').append(tabPanel); + $('#additions-container').prepend(tabPanel); } else { // If there already is a savedFoki element, get it $('#savedFoki').html(''); @@ -178,7 +178,7 @@ Results.prototype.addToContainer = function (container) { if (html.toLowerCase().indexOf(search.toLowerCase()) === -1) { // hide entire result block $(value).parent().addClass('hidden'); - }else { + } else { // show entire result block $(value).parent().removeClass('hidden'); } @@ -218,7 +218,7 @@ Results.prototype.addToContainer = function (container) { * @param {int} rank The rank of this result * @param {int} hash The hash value for this result */ -function Result (title, link, hosterName, hosterLink, anzeigeLink, description, anonym, index, hash) { +function Result(title, link, hosterName, hosterLink, anzeigeLink, description, anonym, index, hash) { // Set prefix for localstorage this.prefix = 'result_'; @@ -313,7 +313,7 @@ Result.prototype.save = function () { * Convert a string into base64 format * @param {String} str The string to convert */ -function b64EncodeUnicode (str) { +function b64EncodeUnicode(str) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { return String.fromCharCode('0x' + p1); })); @@ -323,7 +323,7 @@ function b64EncodeUnicode (str) { * Convert a base64 string into normal format * @param {String} str The string to convert */ -function b64DecodeUnicode (str) { +function b64DecodeUnicode(str) { return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); @@ -389,7 +389,7 @@ Result.prototype.toHtml = function () { </div>'); // Add a click listener to the remover, that removes the result on click - $(result).find('.remover').click({caller: this}, function (event) { + $(result).find('.remover').click({ caller: this }, function (event) { event.data.caller.remove(); }); @@ -400,7 +400,7 @@ Result.prototype.toHtml = function () { * Saves the result at the given index * @param {int} index The index of the result to save */ -function resultSaver (index) { +function resultSaver(index) { // Remember the original result element var original = $('.result[data-count=' + index + ']'); @@ -428,6 +428,6 @@ function resultSaver (index) { // Animate the result transfer to the saved results var transferTarget = $('.saved-result[data-count=' + index + ']'); if (original.length > 0 && transferTarget.length > 0) { - $(original).transfer({to: transferTarget, duration: 1000}); + $(original).transfer({ to: transferTarget, duration: 1000 }); } } diff --git a/resources/less/metager/pages/resultpage.less b/resources/less/metager/pages/resultpage.less index 90d190d8194ef13de6a44adfa4e7298318eb3968..a2a703ea1965582827ae6a5a7ecdf2f0dc31a7ca 100644 --- a/resources/less/metager/pages/resultpage.less +++ b/resources/less/metager/pages/resultpage.less @@ -1,6 +1,5 @@ @import "./resultpage/result-page.less"; @import "./resultpage/result.less"; @import "./resultpage/product.less"; -@import "./resultpage/quicktips.less"; @import "./resultpage/result-saver.less"; @import "./resultpage/keyboard-nav.less"; \ No newline at end of file diff --git a/resources/less/metager/pages/resultpage/quicktips.less b/resources/less/metager/pages/resultpage/quicktips.less index ff37db3800cb78e9755bc19513f8deff44643409..e8d5b918eb83ecb24ebd68ad8028a3f5a9c24072 100644 --- a/resources/less/metager/pages/resultpage/quicktips.less +++ b/resources/less/metager/pages/resultpage/quicktips.less @@ -1,11 +1,21 @@ /* Quicktips */ - +@import "../../variables.less"; +@import "../../general/cards.less"; +@import "../../general/general.less"; @quicktip-font-large: @result-font-large; @quicktip-font-medium: @result-font-medium; @quicktip-font-small: @result-font-small; #quicktips { display: flex; flex-direction: column; + margin: 0 8px; + background-color: inherit; + a { + text-decoration: none; + &:hover { + text-decoration: underline; + } + } .quicktip { .card-light; position: relative; @@ -15,7 +25,6 @@ } margin: 10px 0px; padding: 10px 10px 10px 10px; - width: 100%; border: 1px solid #ccc; background-color: white; details:not([open=""]) { @@ -24,6 +33,32 @@ } } .quicktip-summary { + display: block; + .btn { + display: inline-block; + margin-bottom: 0; + font-weight: 400; + text-align: center; + vertical-align: middle; + -ms-touch-action: manipulation; + touch-action: manipulation; + cursor: pointer; + background-image: none; + border: 1px solid transparent; + white-space: nowrap; + padding: 6px 12px; + font-size: 14px; + line-height: 1.42857143; + border-radius: 4px; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + text-decoration: none; + &:hover { + text-decoration: underline; + } + } .quicktip-headline { width: 100%; display: flex; diff --git a/resources/less/metager/pages/resultpage/result-page.less b/resources/less/metager/pages/resultpage/result-page.less index 4a60c0fefdbb49728a9aaa68b07fb9a1580aafa7..2c3f9045edb9169c454a4189cae12fe0adce9eab 100644 --- a/resources/less/metager/pages/resultpage/result-page.less +++ b/resources/less/metager/pages/resultpage/result-page.less @@ -1,26 +1,5 @@ /* Variables */ -// Background color -@resultpage-background-color: @background-color; -// Margin to the left of the results -@results-margin-left: 16px; -// Min and max widths of the 2 resultpage columns -@results-width-min: 500px; -@results-width-max: 800px; -@additions-width-min: 500px; -@additions-width-max: 500px; -// Breakpoints for the 2 resultpage columns -@resultpage-breakpoint-max: (@results-width-max + @additions-width-max + @padding-small-default * 2 + @padding-small-default * 4 + 6); -@resultpage-breakpoint-min: (@results-width-min + @additions-width-min + @padding-small-default * 4); -@product-shop-color: green; -// The point upon which a .screen-large logo is displayed -@logo-size-breakpoint: (@results-width-min + @padding-small-default * 2); -// The point upon which the sidebar opener switches place -@sidebar-opener-breakpoint: (@results-width-max + @padding-small-default * 2 + 60px); -// Quicktip background color -@quicktip-background-color: @color-white; -// Color of the Spruch author -@spruch-author-color: @color-strong-grey; /* Styles */ #header-logo { @@ -400,6 +379,13 @@ a { #search-settings { display: none; } + #quicktips { + height: 100%; + iframe{ + height: 100%; + width: 100%; + } + } } footer { grid-area: footer; diff --git a/resources/less/metager/pages/resultpage/result.less b/resources/less/metager/pages/resultpage/result.less index 242f6f01320886a92118161cc72b19b1d428fa8f..eb42ae189ace4967a48dd030462389303458de84 100644 --- a/resources/less/metager/pages/resultpage/result.less +++ b/resources/less/metager/pages/resultpage/result.less @@ -1,9 +1,3 @@ -@result-font-large: 18px; -@result-font-medium: 16px; -@result-font-url: 14px; -@result-font-small: 12px; -@result-description-color: @color-black; -@result-image-border-color: @color-almost-white; .result { // Remove the margin from the first result because it already has margin from the grid ruleset diff --git a/resources/less/metager/variables.less b/resources/less/metager/variables.less index 11522db7220581b0c458ba9201ae4ed0a66dd955..2dc72d81cbf45c9c1b0acd986a092bdd592306d2 100644 --- a/resources/less/metager/variables.less +++ b/resources/less/metager/variables.less @@ -1,5 +1,5 @@ // MetaGer Brand Color -@metager-orange: #FF8000; +@metager-orange: #FF8000; // Shades of Gray @color-white: white; @color-almost-white: mix(@color-white, @color-black, 90%); @@ -27,4 +27,33 @@ sans-serif; // Screen sizes @screen-mobile: 760px; @screen-small: 1000px; -@screen-medium: 1200px; \ No newline at end of file +@screen-medium: 1200px; + +@result-font-large: 18px; +@result-font-medium: 16px; +@result-font-url: 14px; +@result-font-small: 12px; +@result-description-color: @color-black; +@result-image-border-color: @color-almost-white; + +// Background color +@resultpage-background-color: @background-color; +// Margin to the left of the results +@results-margin-left: 16px; +// Min and max widths of the 2 resultpage columns +@results-width-min: 500px; +@results-width-max: 800px; +@additions-width-min: 500px; +@additions-width-max: 500px; +// Breakpoints for the 2 resultpage columns +@resultpage-breakpoint-max: (@results-width-max + @additions-width-max + @padding-small-default * 2 + @padding-small-default * 4 + 6); +@resultpage-breakpoint-min: (@results-width-min + @additions-width-min + @padding-small-default * 4); +@product-shop-color: green; +// The point upon which a .screen-large logo is displayed +@logo-size-breakpoint: (@results-width-min + @padding-small-default * 2); +// The point upon which the sidebar opener switches place +@sidebar-opener-breakpoint: (@results-width-max + @padding-small-default * 2 + 60px); +// Quicktip background color +@quicktip-background-color: @color-white; +// Color of the Spruch author +@spruch-author-color: @color-strong-grey; \ No newline at end of file diff --git a/resources/views/layouts/researchandtabs.blade.php b/resources/views/layouts/researchandtabs.blade.php index 8ec665cc5eea2909a517208e0ef11b78c3e7694e..9e9596e0cc281bb673cf0a82750fbd6df5e41859 100644 --- a/resources/views/layouts/researchandtabs.blade.php +++ b/resources/views/layouts/researchandtabs.blade.php @@ -36,7 +36,7 @@ @include('layouts.keyboardNavBox') @if( $metager->showQuicktips() ) <div id="quicktips"> - @include('quicktips', ['quicktips', $quicktips]) + <iframe src="{{ $quicktips }}" frameborder="0"></iframe> </div> @endif </div> diff --git a/resources/views/quicktips.blade.php b/resources/views/quicktips.blade.php index f354bda8b7ff7dadefffc7704e3bf4325b39b28b..6fa679cf65fd25ab3e02af788260f55783900250 100644 --- a/resources/views/quicktips.blade.php +++ b/resources/views/quicktips.blade.php @@ -1,5 +1,19 @@ +<!DOCTYPE html> +<html lang="{{ LaravelLocalization::getCurrentLocale() }}"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>{{ $search }} - MetaGer Quicktips</title> + <link type="text/css" rel="stylesheet" href="{{ mix('css/quicktips.css') }}" /> + <link href="/fonts/liberationsans/stylesheet.css" rel="stylesheet"> + <link type="text/css" rel="stylesheet" href="{{ mix('css/fontawesome.css') }}" /> + <link type="text/css" rel="stylesheet" href="{{ mix('css/fontawesome-solid.css') }}" /> +</head> +<body id="quicktips"> @foreach($quicktips as $quicktip) <div class="quicktip" type="{{ $quicktip->type }}"> @include('parts.quicktip', ['quicktip' => $quicktip]) </div> -@endforeach \ No newline at end of file +@endforeach +</body> +</html> diff --git a/routes/web.php b/routes/web.php index 16b658253b881a5d38385eea7c4137c440d95e78..7f6093e491b6413cc4604a2ddaa2f24f81126fb5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -196,7 +196,7 @@ Route::group( Route::get('pluginClose', 'LogController@pluginClose'); Route::get('pluginInstall', 'LogController@pluginInstall'); - Route::get('qt', 'MetaGerSearch@quicktips'); + Route::get('qt/{eingabe}', 'MetaGerSearch@quicktips'); Route::get('tips', 'MetaGerSearch@tips'); Route::get('/plugins/opensearch.xml', 'StartpageController@loadPlugin'); Route::get('owi', function () { diff --git a/webpack.mix.js b/webpack.mix.js index 573059346677b6f5738dc299cbc260fa310a51df..882de714d88b6a8ccde46693c544762dd324ada1 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -22,6 +22,9 @@ mix .less("resources/less/metager/metager.less", "public/css/themes/metager.css", { strictMath: true }) + .less("resources/less/metager/pages/resultpage/quicktips.less", "public/css/quicktips.css", { + strictMath: true + }) .less("resources/less/font-awesome/fontawesome.less", "public/css/fontawesome.css", { strictMath: true }) @@ -34,8 +37,8 @@ mix .less( "resources/less/metager/pages/key.less", "public/css/key.css", { - strictMath: true - } + strictMath: true + } ) .less("resources/less/utility.less", "public/css/utility.css", { strictMath: true