Commit 939a2d19 authored by Phil Höfer's avatar Phil Höfer

Merge remote-tracking branch 'origin/development' into 799-metager-in-docker

parents d2c91461 eded8940
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use LaravelLocalization;
class Assoziator extends Controller
{
public function asso(Request $request){
$eingabe = $request->input('q', '');
if(empty($eingabe)){
return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), '/asso'));
}
$url = "https://metager.de/meta/meta.ger3?eingabe=" . urlencode($eingabe) . "&out=atom10";
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => $_SERVER["AGENT"],
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_MAXCONNECTS => 500,
CURLOPT_LOW_SPEED_LIMIT => 500,
CURLOPT_LOW_SPEED_TIME => 5,
CURLOPT_TIMEOUT => 10,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER, array(
"X_FORWARDED_FOR: " . $request->ip()
)
));
$response = curl_exec($ch);
$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($responseCode !== 200)
abort(500, "Server currently not available");
$response = preg_replace("/^<\?.*\?>/s", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", $response);
$content = simplexml_load_string($response);
$words = [];
foreach($content->entry as $entry){
#
$title = $entry->title->__toString();
$content = $entry->content->__toString();
$n_words = preg_match_all('/([a-zA-Z]|\xC3[\x80-\x96\x98-\xB6\xB8-\xBF]|\xC5[\x92\x93\xA0\xA1\xB8\xBD\xBE]){2,}/', $title, $match_arr);
$wordsTmp = $match_arr[0];
$n_words = preg_match_all('/([a-zA-Z]|\xC3[\x80-\x96\x98-\xB6\xB8-\xBF]|\xC5[\x92\x93\xA0\xA1\xB8\xBD\xBE]){2,}/', $content, $match_arr);
$wordsTmp = array_merge($wordsTmp, $match_arr[0]);
#
foreach($wordsTmp as $word){
if(isset($words[$word])){
$words[$word]++;
}else if(isset($words[ucfirst($word)])){
$words[ucfirst($word)]++;
}else if(isset($words[strtolower($word)])){
$words[strtolower($word)]++;
}else{
$words[$word] = 1;
}
}
}
arsort($words);
$eingabeWords = explode(" ", $eingabe);
foreach($eingabeWords as $eingabeWord){
unset($words[$eingabeWord]);
unset($words[strtolower($eingabeWord)]);
unset($words[ucfirst($eingabeWord)]);
unset($words[strtoupper($eingabeWord)]);
}
unset($words["de"]);
unset($words["com"]);
unset($words["wiki"]);
unset($words["Wiki"]);
// Remove Stopwords
$stopWords = file(storage_path('app/public/stopwords.txt'));
foreach($stopWords as $stopWord){
$stopWord = trim($stopWord);
unset($words[$stopWord]);
unset($words[strtolower($stopWord)]);
unset($words[ucfirst($stopWord)]);
}
$wordCount = 0;
$i = 1;
$max = 60;
foreach($words as $key => $value){
if($i > $max)
unset($words[$key]);
$wordCount += $value;
$i++;
}
return view('assoziator.asso')
->with('title', trans('titles.asso'))
->with('navbarFocus', 'dienste')
->with('words', $words)
->with('keywords', $eingabe)
->with('wordCount', $wordCount);
die(var_dump($words));
}
}
......@@ -7,6 +7,8 @@ use Illuminate\Http\Request;
use Jenssegers\Agent\Agent;
use LaravelLocalization;
use Response;
use DB;
use Log;
class StartpageController extends Controller
{
......@@ -41,6 +43,14 @@ class StartpageController extends Controller
if ($lang === 'de' || $lang === "en") {
$lang = 'all';
}
# Sponsorenlinks
$sponsors = [];
try{
$sponsors = DB::table('sponsorenlinks')->where('langcode', 'de')->orderByRaw('LENGTH(linktext)', 'ASC')->get();
} catch(\Illuminate\Database\QueryException $e){
Log::info($e);
}
return view('index')
->with('title', trans('titles.index'))
......@@ -52,6 +62,7 @@ class StartpageController extends Controller
->with('request', $request->input('request', 'GET'))
->with('option_values', $option_values)
->with('autocomplete', $autocomplete)
->with('sponsors', $sponsors)
->with('pluginmodal', $request->input('plugin-modal', 'off'));
}
......
......@@ -126,7 +126,8 @@ class HumanVerification
} catch (\Illuminate\Database\QueryException $e) {
// Failure in contacting metager3.de
}
$request->request->add(['verification_id' => $uid, 'verification_count' => $unusedResultPages]);
if(isset($uid) && isset($unusedResultPages))
$request->request->add(['verification_id' => $uid, 'verification_count' => $unusedResultPages]);
return $next($request);
}
}
......@@ -4366,6 +4366,7 @@
"version": "0.0.9",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"inherits": "~2.0.0"
}
......@@ -4390,7 +4391,8 @@
"buffer-shims": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"caseless": {
"version": "0.12.0",
......@@ -4407,12 +4409,14 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"combined-stream": {
"version": "1.0.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"delayed-stream": "~1.0.0"
}
......@@ -4425,17 +4429,20 @@
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"cryptiles": {
"version": "2.0.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"boom": "2.x.x"
}
......@@ -4475,7 +4482,8 @@
"delayed-stream": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"delegates": {
"version": "1.0.0",
......@@ -4507,7 +4515,8 @@
"extsprintf": {
"version": "1.0.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"forever-agent": {
"version": "0.6.1",
......@@ -4630,6 +4639,7 @@
"version": "3.1.3",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"boom": "2.x.x",
"cryptiles": "2.x.x",
......@@ -4677,6 +4687,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "1.0.1"
}
......@@ -4690,7 +4701,8 @@
"isarray": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"isstream": {
"version": "0.1.2",
......@@ -4763,12 +4775,14 @@
"mime-db": {
"version": "1.27.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"mime-types": {
"version": "2.1.15",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"mime-db": "1.27.0"
}
......@@ -4844,7 +4858,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"oauth-sign": {
"version": "0.8.2",
......@@ -4902,7 +4917,8 @@
"process-nextick-args": {
"version": "1.0.7",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"punycode": {
"version": "1.4.1",
......@@ -4940,6 +4956,7 @@
"version": "2.2.9",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"buffer-shims": "~1.0.0",
"core-util-is": "~1.0.0",
......@@ -4991,7 +5008,8 @@
"safe-buffer": {
"version": "5.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"semver": {
"version": "5.3.0",
......@@ -5015,6 +5033,7 @@
"version": "1.0.9",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"hoek": "2.x.x"
}
......@@ -5048,6 +5067,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......@@ -5058,6 +5078,7 @@
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.0.1"
}
......@@ -5086,6 +5107,7 @@
"version": "2.2.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"block-stream": "*",
"fstream": "^1.0.2",
......@@ -5141,7 +5163,8 @@
"util-deprecate": {
"version": "1.0.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"uuid": {
"version": "3.0.1",
......
/* Default Font */
* {
body {
font-family: Liberation Sans, sans-serif;
}
......@@ -82,7 +82,7 @@ p {
.first-last-child-margin-fix;
}
* {
body {
font-size: @default-font-size;
.first-last-child-margin-fix;
}
......
<?php
return [
'head.1' => 'MetaGer Assoziator',
'1.1' => 'Wenn Sie mit Ihren Suchwörtern nicht weiter kommen: Vielleicht fehlen Ihnen die richtigen? Fragen Sie unseren Assoziator: Geben Sie hier einfach ein oder mehrere Wörter ein, zu denen Sie neue oder bessere Begriffe suchen. Versuchen Sie mit den dann gefundenen Wörtern eine neue Suche indem Sie das neue Wort in der Ausgabeseite anklicken. Es gilt unsere',
'1.2' => 'Datenschutzerklärung',
'reasso.title' => 'Diesen Begriff assoziieren',
'searchasso.title' => 'MetaGer Suche nach diesem Begriff durchführen',
];
\ No newline at end of file
......@@ -22,4 +22,5 @@ return [
'faktencheck' => 'Fakten-Prüfung contra Fake-News',
'jugendschutz' => 'Jugendschutz',
'ad-info' => 'Werbung bei MetaGer',
'asso' => 'Assoziator - MetaGer',
];
@extends('layouts.subPages')
@section('title', $title )
@section('content')
<style>
form div.input-group-addon button {
padding: 9px;
}
.reasso {
color: rgb(0, 102, 204);
}
.reasso:hover {
color: red;
}
td.association {
display: flex;
}
.asso-search-link {
margin-right: 10px;
}
</style>
<h1 class="page-title">{{ trans('asso.head.1') }}</h1>
<div class="card-heavy">
<p>{{ trans('asso.1.1') }} <a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), '/') }}" target="_blank">{{ trans('asso.1.2') }}</a>.</p>
<form method="post">
<div class="input-group">
<input type="text" class="form-control" placeholder="Zu assoziierender Begriff" @if(isset($keywords)) value="{{$keywords}}" @endif name="q" required autofocus/>
<div class="input-group-addon"><button type="submit"><i class="fa fa-search" aria-hidden="true"></i></button></div>
</div>
</form>
</div>
@if(isset($words))
<div class="card-heavy">
<div class="table-responsive">
<table class="table">
<caption>Assoziationen für "{{ $keywords }}"</caption>
<thead>
<tr>
<th>#</th>
<th>Assoziation</th>
<th>Relevanz</th>
</tr>
</thead>
<tbody>
@php $i = 1; @endphp
@foreach($words as $key => $value)
<tr>
<td>{{ $i }}</td>
<td class="association">
<a class="asso-search-link" href="{{ action('MetaGerSearch@search', ['eingabe' => $key]) }}" title="{{ trans('asso.searchasso.title') }}"><i class="fa fa-search" aria-hidden="true"></i></a>
<form method="POST">
<button name="q" value="{{ $key }}" class="reasso" type="submit" title="{{ trans('asso.reasso.title') }}">{{ $key }}</button>
</form>
</td>
<td>{{ round(($value / $wordCount) * 100, 2) }}%</td>
@php $i++; @endphp
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
@endsection
......@@ -25,13 +25,11 @@
<div id="sponsors">
<h2>{{ trans('index.sponsors.head.2') }}</h2>
<ul class="startpage">
@if (getenv('DB_CONNECTION')==='mysql')
@foreach(DB::table('sponsorenlinks')->where('langcode', 'de')->orderByRaw('LENGTH(linktext)', 'ASC')->get() as $link)
<li class="sponsor">
<a href="{{ $link->link }}" target="_blank" rel="noopener"><p>{{ $link->linktext }}</p> <i class="fa fa-external-link"></i></a>
</li>
@endforeach
@endif
@foreach($sponsors as $link)
<li class="sponsor">
<a href="{{ $link->link }}" target="_blank" rel="noopener"><p>{{ $link->linktext }}</p> <i class="fa fa-external-link"></i></a>
</li>
@endforeach
</ul>
</div>
</div>
......
......@@ -26,7 +26,7 @@
<a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/zitat-suche/") }}" tabindex="227">{{ trans('sidebar.nav22') }}</a>
</li>
<li>
<a class="inlink" href="https://metager.de/klassik/asso/" tabindex="228">{{ trans('sidebar.nav11') }}</a>
<a href="{{ action('Assoziator@asso') }}" tabindex="228">{{ trans('sidebar.nav11') }}</a>
</li>
<li>
<a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/app/") }}" tabindex="229">@lang('sidebar.nav25')</a>
......
......@@ -20,6 +20,13 @@ Route::group(
Route::get('/', 'StartpageController@loadStartPage');
Route::get('asso', function(){
return view('assoziator.asso')
->with('title', trans('titles.asso'))
->with('navbarFocus', 'dienste');
});
Route::post('asso', 'Assoziator@asso');
Route::get('img/piwik.png', 'ImageController@generateImage');
Route::get('impressum', function () {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment