Commit 0196c7a9 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 2bedea70
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App; use App;
use App\Http\Controllers\Controller;
use App\MetaGer; use App\MetaGer;
use Illuminate\Http\Request;
class MetaGerSearch extends Controller class MetaGerSearch extends Controller
{ {
...@@ -18,8 +17,8 @@ class MetaGerSearch extends Controller ...@@ -18,8 +17,8 @@ class MetaGerSearch extends Controller
$metager->parseFormData($request); $metager->parseFormData($request);
#if($metager->getFokus() !== "bilder" ) #if($metager->getFokus() !== "bilder" )
#{ #{
# Nach Spezialsuchen überprüfen: # Nach Spezialsuchen überprüfen:
$metager->checkSpecialSearches($request); $metager->checkSpecialSearches($request);
#} #}
# Alle Suchmaschinen erstellen # Alle Suchmaschinen erstellen
$metager->createSearchEngines($request); $metager->createSearchEngines($request);
...@@ -29,7 +28,7 @@ class MetaGerSearch extends Controller ...@@ -29,7 +28,7 @@ class MetaGerSearch extends Controller
# Ergebnisse der Suchmaschinen kombinieren: # Ergebnisse der Suchmaschinen kombinieren:
$metager->combineResults(); $metager->combineResults();
# Die Ausgabe erstellen: # Die Ausgabe erstellen:
return $metager->createView(); return $metager->createView();
} }
...@@ -40,97 +39,89 @@ class MetaGerSearch extends Controller ...@@ -40,97 +39,89 @@ class MetaGerSearch extends Controller
# Zunächst den Spruch # Zunächst den Spruch
$spruecheFile = storage_path() . "/app/public/sprueche.txt"; $spruecheFile = storage_path() . "/app/public/sprueche.txt";
if( file_exists($spruecheFile) && $request->has('sprueche') ) if (file_exists($spruecheFile) && $request->has('sprueche')) {
{
$sprueche = file($spruecheFile); $sprueche = file($spruecheFile);
$spruch = $sprueche[array_rand($sprueche)]; $spruch = $sprueche[array_rand($sprueche)];
}else } else {
{
$spruch = ""; $spruch = "";
} }
# Die manuellen Quicktips: # Die manuellen Quicktips:
$file = storage_path() . "/app/public/qtdata.csv"; $file = storage_path() . "/app/public/qtdata.csv";
$mquicktips = []; $mquicktips = [];
if( file_exists($file) && $q !== '') if (file_exists($file) && $q !== '') {
{
$file = fopen($file, 'r'); $file = fopen($file, 'r');
while (($line = fgetcsv($file)) !== FALSE) { while (($line = fgetcsv($file)) !== false) {
$words = array_slice($line,3); $words = array_slice($line, 3);
$isIn = FALSE; $isIn = false;
foreach($words as $word){ foreach ($words as $word) {
$word = strtolower($word); $word = strtolower($word);
if(strpos($q, $word) !== FALSE){ if (strpos($q, $word) !== false) {
$isIn = TRUE; $isIn = true;
break; break;
} }
} }
if($isIn === TRUE){ if ($isIn === true) {
$quicktip = array('QT_Type' => "MQT"); $quicktip = array('QT_Type' => "MQT");
$quicktip["URL"] = $line[0]; $quicktip["URL"] = $line[0];
$quicktip["title"] = $line[1]; $quicktip["title"] = $line[1];
$quicktip["descr"] = $line[2]; $quicktip["descr"] = $line[2];
$mquicktips[] = $quicktip; $mquicktips[] = $quicktip;
} }
} }
fclose($file); fclose($file);
} }
# Wikipedia Quicktip # Wikipedia Quicktip
$quicktips = []; $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); $decodedResponse = json_decode($this->get($url), true);
if( isset($decodedResponse["query"]["pages"]) ) if (isset($decodedResponse[1][0]) && isset($decodedResponse[2][0]) && isset($decodedResponse[3][0])) {
{ $quicktip = [];
foreach($decodedResponse["query"]["pages"] as $result) $quicktip["title"] = $decodedResponse[1][0];
{ $quicktip["URL"] = $decodedResponse[3][0];
if( isset($result['displaytitle']) && isset($result['fullurl']) && isset($result['extract']) ) $quicktip["descr"] = $decodedResponse[2][0];
{ $quicktip['gefVon'] = "aus <a href=\"https://de.wikipedia.org\" target=\"_blank\">Wikipedia, der freien Enzyklopädie</a>";
$quicktip = [];
$quicktip["title"] = $result['displaytitle']; $quicktips[] = $quicktip;
$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;
}
}
} }
$mquicktips = array_merge($mquicktips, $quicktips); $mquicktips = array_merge($mquicktips, $quicktips);
# Uns Natürlich das wussten Sie schon: # Uns Natürlich das wussten Sie schon:
$file = storage_path() . "/app/public/tips.txt"; $file = storage_path() . "/app/public/tips.txt";
if( file_exists($file) ) if (file_exists($file)) {
{
$tips = file($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: # Uns die Werbelinks:
$file = storage_path() . "/app/public/ads.txt"; $file = storage_path() . "/app/public/ads.txt";
if( file_exists($file) ) if (file_exists($file)) {
{
$ads = json_decode(file_get_contents($file), true); $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') return view('quicktip')
->with('spruch', $spruch) ->with('spruch', $spruch)
->with('mqs', $mquicktips); ->with('mqs', $mquicktips);
} }
public function tips() public function tips()
{ {
$file = storage_path() . "/app/public/tips.txt"; $file = storage_path() . "/app/public/tips.txt";
$tips = []; $tips = [];
if( file_exists($file) ) if (file_exists($file)) {
{
$tips = file($file); $tips = file($file);
} }
return view('tips') return view('tips')
...@@ -138,8 +129,9 @@ class MetaGerSearch extends Controller ...@@ -138,8 +129,9 @@ class MetaGerSearch extends Controller
->with('tips', $tips); ->with('tips', $tips);
} }
function get($url) { public function get($url)
{
return file_get_contents($url); return file_get_contents($url);
} }
} }
\ No newline at end of file
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
@if( $metager->showQuicktips() ) @if( $metager->showQuicktips() )
<div class="hidden-xs col-md-4" id="quicktips"> <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> </div>
@endif @endif
@endsection @endsection
...@@ -35,5 +35,5 @@ ...@@ -35,5 +35,5 @@
</nav> </nav>
</div> </div>
<div class="hidden-xs col-md-4" id="quicktips"> <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> </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