Commit 1b7f97a1 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Die Quicktips werden nun auch in der angegebenen Localization abgerufen.

Wikipedia Quciktips werden nun über die Opensearch Api abgerufen (https://www.mediawiki.org/wiki/API:Opensearch)
Dies liefert wesentlich bessere Ergebnisse.
parent 46f465fe
......@@ -2,11 +2,10 @@
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App;
use App\Http\Controllers\Controller;
use App\MetaGer;
use Illuminate\Http\Request;
class MetaGerSearch extends Controller
{
......@@ -18,8 +17,8 @@ class MetaGerSearch extends Controller
$metager->parseFormData($request);
#if($metager->getFokus() !== "bilder" )
#{
# Nach Spezialsuchen überprüfen:
$metager->checkSpecialSearches($request);
# Nach Spezialsuchen überprüfen:
$metager->checkSpecialSearches($request);
#}
# Alle Suchmaschinen erstellen
$metager->createSearchEngines($request);
......@@ -29,7 +28,7 @@ class MetaGerSearch extends Controller
# Ergebnisse der Suchmaschinen kombinieren:
$metager->combineResults();
# Die Ausgabe erstellen:
return $metager->createView();
}
......@@ -40,97 +39,89 @@ class MetaGerSearch extends Controller
# Zunächst den Spruch
$spruecheFile = storage_path() . "/app/public/sprueche.txt";
if( file_exists($spruecheFile) && $request->has('sprueche') )
{
if (file_exists($spruecheFile) && $request->has('sprueche')) {
$sprueche = file($spruecheFile);
$spruch = $sprueche[array_rand($sprueche)];
}else
{
$spruch = $sprueche[array_rand($sprueche)];
} else {
$spruch = "";
}
# Die manuellen Quicktips:
$file = storage_path() . "/app/public/qtdata.csv";
$mquicktips = [];
if( file_exists($file) && $q !== '')
{
if (file_exists($file) && $q !== '') {
$file = fopen($file, 'r');
while (($line = fgetcsv($file)) !== FALSE) {
$words = array_slice($line,3);
$isIn = FALSE;
foreach($words as $word){
$word = strtolower($word);
if(strpos($q, $word) !== FALSE){
$isIn = TRUE;
break;
}
while (($line = fgetcsv($file)) !== false) {
$words = array_slice($line, 3);
$isIn = false;
foreach ($words as $word) {
$word = strtolower($word);
if (strpos($q, $word) !== false) {
$isIn = true;
break;
}
}
if($isIn === TRUE){
$quicktip = array('QT_Type' => "MQT");
$quicktip["URL"] = $line[0];
$quicktip["title"] = $line[1];
$quicktip["descr"] = $line[2];
$mquicktips[] = $quicktip;
if ($isIn === true) {
$quicktip = array('QT_Type' => "MQT");
$quicktip["URL"] = $line[0];
$quicktip["title"] = $line[1];
$quicktip["descr"] = $line[2];
$mquicktips[] = $quicktip;
}
}
fclose($file);
}
fclose($file);
}
# Wikipedia Quicktip
$quicktips = [];
$url = "http://de.wikipedia.org/w/api.php?action=query&titles=".urlencode(implode("_",array_diff(explode(" ",$q),array("wikipedia"))))."&prop=info|extracts|categories&inprop=url|displaytitle&exintro&exsentences=3&format=json";
if (App::isLocale('en')) {
$url = "https://en.wikipedia.org/w/api.php?action=opensearch&search=" . urlencode($q) . "&limit=1&namespace=0&format=json";
} else {
$url = "https://de.wikipedia.org/w/api.php?action=opensearch&search=" . urlencode($q) . "&limit=1&namespace=0&format=json";
}
$decodedResponse = json_decode($this->get($url), true);
if( isset($decodedResponse["query"]["pages"]) )
{
foreach($decodedResponse["query"]["pages"] as $result)
{
if( isset($result['displaytitle']) && isset($result['fullurl']) && isset($result['extract']) )
{
$quicktip = [];
$quicktip["title"] = $result['displaytitle'];
$quicktip["URL"] = $result['fullurl'];
$quicktip["descr"] = strip_tags($result['extract']);
$quicktip['gefVon'] = "aus <a href=\"https://de.wikipedia.org\" target=\"_blank\">Wikipedia, der freien Enzyklopädie</a>";
$quicktips[] = $quicktip;
}
}
if (isset($decodedResponse[1][0]) && isset($decodedResponse[2][0]) && isset($decodedResponse[3][0])) {
$quicktip = [];
$quicktip["title"] = $decodedResponse[1][0];
$quicktip["URL"] = $decodedResponse[3][0];
$quicktip["descr"] = $decodedResponse[2][0];
$quicktip['gefVon'] = "aus <a href=\"https://de.wikipedia.org\" target=\"_blank\">Wikipedia, der freien Enzyklopädie</a>";
$quicktips[] = $quicktip;
}
$mquicktips = array_merge($mquicktips, $quicktips);
# Uns Natürlich das wussten Sie schon:
$file = storage_path() . "/app/public/tips.txt";
if( file_exists($file) )
{
if (file_exists($file)) {
$tips = file($file);
$tip = $tips[array_rand($tips)];
$tip = $tips[array_rand($tips)];
$mquicktips[] = ['title' => 'Wussten Sie schon?', 'descr' => $tip, 'URL' => '/tips'];
}
$mquicktips[] = ['title' => 'Wussten Sie schon?', 'descr' => $tip, 'URL' => '/tips'];
}
# Uns die Werbelinks:
$file = storage_path() . "/app/public/ads.txt";
if( file_exists($file) )
{
if (file_exists($file)) {
$ads = json_decode(file_get_contents($file), true);
$ad = $ads[array_rand($ads)];
$ad = $ads[array_rand($ads)];
$mquicktips[] = ['title' => $ad['title'], 'descr' => $ad['descr'], 'URL' => $ad['URL']];
}
$mquicktips[] = ['title' => $ad['title'], 'descr' => $ad['descr'], 'URL' => $ad['URL']];
}
return view('quicktip')
->with('spruch', $spruch)
->with('mqs', $mquicktips);
}
public function tips()
{
$file = storage_path() . "/app/public/tips.txt";
$tips = [];
if( file_exists($file) )
{
if (file_exists($file)) {
$tips = file($file);
}
return view('tips')
......@@ -138,8 +129,9 @@ class MetaGerSearch extends Controller
->with('tips', $tips);
}
function get($url) {
public function get($url)
{
return file_get_contents($url);
}
}
}
\ No newline at end of file
}
......@@ -44,7 +44,7 @@
@if( $metager->showQuicktips() )
<div class="hidden-xs col-md-4" id="quicktips">
<iframe class="col-mod-4 hidden-xs hidden-sm" src="/qt?q={{ $metager->getQ() }}&sprueche={{ $metager->getSprueche() }}"></iframe>
<iframe class="col-mod-4 hidden-xs hidden-sm" src="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/qt") }}?q={{ $metager->getQ() }}&sprueche={{ $metager->getSprueche() }}"></iframe>
</div>
@endif
@endsection
......@@ -35,5 +35,5 @@
</nav>
</div>
<div class="hidden-xs col-md-4" id="quicktips">
<iframe class="col-mod-4 hidden-xs hidden-sm" src="/qt?q={{ $metager->getQ() }}&sprueche={{ $metager->getSprueche() }}"></iframe>
<iframe class="col-mod-4 hidden-xs hidden-sm" src="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/qt") }}?q={{ $metager->getQ() }}&sprueche={{ $metager->getSprueche() }}"></iframe>
</div>
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