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 @@
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
{
......@@ -40,12 +39,10 @@ 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
{
} else {
$spruch = "";
}
......@@ -53,20 +50,19 @@ class MetaGerSearch extends Controller
$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){
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;
if (strpos($q, $word) !== false) {
$isIn = true;
break;
}
}
if($isIn === TRUE){
if ($isIn === true) {
$quicktip = array('QT_Type' => "MQT");
$quicktip["URL"] = $line[0];
$quicktip["title"] = $line[1];
......@@ -79,30 +75,28 @@ class MetaGerSearch extends Controller
# 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']) )
{
if (isset($decodedResponse[1][0]) && isset($decodedResponse[2][0]) && isset($decodedResponse[3][0])) {
$quicktip = [];
$quicktip["title"] = $result['displaytitle'];
$quicktip["URL"] = $result['fullurl'];
$quicktip["descr"] = strip_tags($result['extract']);
$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)];
......@@ -111,8 +105,7 @@ class MetaGerSearch extends Controller
# 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)];
......@@ -122,15 +115,13 @@ class MetaGerSearch extends Controller
->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,7 +129,8 @@ class MetaGerSearch extends Controller
->with('tips', $tips);
}
function get($url) {
public function get($url)
{
return file_get_contents($url);
}
......
......@@ -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