Skip to content
Snippets Groups Projects
Commit e93616ea authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch '454-zitatsuche-uberfuhren' into 'development'

Zitatsuche funktioniert wieder korrekt

Closes #454

See merge request !763
parents 4148ebd1 dec3ed4b
No related branches found
No related tags found
2 merge requests!764Development,!763Zitatsuche funktioniert wieder korrekt
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ZitatController extends Controller
{
public function zitatSuche(Request $request)
{
$validResults = [];
if ($request->has("q")) {
# The user searched for something
$fileName = storage_path() . "/app/public/zitate.txt";
$fileContent = file_get_contents($fileName);
# Die Suchworte sind UND verknüpft, müssen aber nicht als gesamtes Wort vorkommen
$all = explode(PHP_EOL, $fileContent);
$words = preg_split("/\s+/", $request->input('q'));
# Loop through all
foreach ($all as $zitat) {
$valid = true;
# A Result isn't valid when it doesn't Contain every search word
foreach ($words as $word) {
if (stripos($zitat, $word) === false) {
$valid = false;
break;
}
}
if ($valid) {
# This Result is valid. We'll add it Sorted by author
if (preg_match("/^\"([^\"]+)\"\s(.*)$/", $zitat, $matches)) {
$quote = $matches[1];
$author = $matches[2];
if (isset($validResults[$author])) {
$validResults[$author][] = $quote;
} else {
$validResults[$author] = [$quote];
}
}
}
}
}
return view('zitatsuche')
->with('title', 'Zitatsuche MetaGer')
->with('navbarFocus', 'dienste')
->with('results', $validResults)
->with('q', $request->input('q', ''));
}
}
<?php
return [
'head.1' => 'MetaGer - Zitatsuche',
'p.1' => 'In dem unten stehenden Textfeld können Sie in unserer Datenbank nach Zitaten oder Autoren suchen.',
];
......@@ -141,7 +141,7 @@
<a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/widget/") }}">{{ trans('staticPages.nav10') }}</a>
</li>
<li>
<a href="https://metager.de/klassik/zitat-suche/" >{{ trans('staticPages.nav22') }}</a>
<a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/zitat-suche/") }}" >{{ trans('staticPages.nav22') }}</a>
</li>
<li>
<a href="https://metager.de/klassik/asso/" >{{ trans('staticPages.nav11') }}</a>
......
@extends('layouts.subPages')
@section('title', $title )
@section('content')
<h1>{{ trans('zitatsuche.head.1') }}</h1>
<p>{{ trans('zitatsuche.p.1') }}</p>
<form id="searchForm" class="form-inline" accept-charset="UTF-8">
<div class="form-group">
<label class="sr-only" for="q">Suchworte eingeben</label>
<div class="input-group">
<input type="text" class="form-control" id="q" name="q" placeholder="Suchworte" value="{{ $q }}">
<div class="input-group-addon"><button type="submit"><span class="glyphicon glyphicon-search"></span></button></div>
</div>
</div>
</form>
@if($q !== "")
<hr />
<h3>Ergebnisse für die Suche "{{$q}}":</h3>
@foreach($results as $author => $quotes)
<b>{{$author}}:</b>
<ul class="list-unstyled">
@foreach($quotes as $quote)
<li><quote>"{{ $quote }}"</quote></li>
@endforeach
</ul>
@endforeach
@endif
@endsection
......@@ -127,6 +127,8 @@ Route::group(
->with('navbarFocus', 'dienste');
});
Route::get('zitat-suche', 'ZitatController@zitatSuche');
Route::group(['middleware' => ['referer.check'], 'prefix' => 'admin'], function () {
Route::get('/', 'AdminInterface@index');
Route::get('count', 'AdminInterface@count');
......
source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment