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

Deutsche Quicktips aus nicht-deutschen Ergebnisseiten entfernt.

parent 0f5023cb
No related branches found
No related tags found
1 merge request!795Development
...@@ -49,83 +49,85 @@ class MetaGerSearch extends Controller ...@@ -49,83 +49,85 @@ class MetaGerSearch extends Controller
{ {
$q = $request->input('q', ''); $q = $request->input('q', '');
# Spruch if(APP::getLocale() === "de"){
$spruecheFile = storage_path() . "/app/public/sprueche.txt"; # Spruch
if (file_exists($spruecheFile) && $request->has('sprueche')) { $spruecheFile = storage_path() . "/app/public/sprueche.txt";
$sprueche = file($spruecheFile); if (file_exists($spruecheFile) && $request->has('sprueche')) {
$spruch = $sprueche[array_rand($sprueche)]; $sprueche = file($spruecheFile);
} else { $spruch = $sprueche[array_rand($sprueche)];
$spruch = ""; } else {
} $spruch = "";
}
# manuelle Quicktips:
$file = storage_path() . "/app/public/qtdata.csv"; # manuelle Quicktips:
$file = storage_path() . "/app/public/qtdata.csv";
$mquicktips = [];
if (file_exists($file) && $q !== '') { $mquicktips = [];
$file = fopen($file, 'r'); if (file_exists($file) && $q !== '') {
while (($line = fgetcsv($file)) !== false) { $file = fopen($file, 'r');
$words = array_slice($line, 3); while (($line = fgetcsv($file)) !== false) {
$isIn = false; $words = array_slice($line, 3);
foreach ($words as $word) { $isIn = false;
$word = strtolower($word); foreach ($words as $word) {
if (strpos($q, $word) !== false) { $word = strtolower($word);
$isIn = true; if (strpos($q, $word) !== false) {
break; $isIn = true;
break;
}
}
if ($isIn === true) {
$quicktip = array('QT_Type' => "MQT");
$quicktip["URL"] = $line[0];
$quicktip["title"] = $line[1];
$quicktip["summary"] = $line[2];
$mquicktips[] = $quicktip;
} }
} }
if ($isIn === true) { fclose($file);
$quicktip = array('QT_Type' => "MQT");
$quicktip["URL"] = $line[0];
$quicktip["title"] = $line[1];
$quicktip["summary"] = $line[2];
$mquicktips[] = $quicktip;
}
} }
fclose($file);
} $quicktips = [];
$quicktips = []; # Wetter
try {
# Wetter $url = "http://api.openweathermap.org/data/2.5/weather?type=accurate&units=metric&lang=" . APP::getLocale() . "&q=" . urlencode($q) . "&APPID=" . getenv("openweathermap");
try {
$url = "http://api.openweathermap.org/data/2.5/weather?type=accurate&units=metric&lang=" . APP::getLocale() . "&q=" . urlencode($q) . "&APPID=" . getenv("openweathermap"); $result = json_decode($this->get($url), true);
$result = json_decode($this->get($url), true); $searchWords = explode(' ', $q);
$within = false;
$searchWords = explode(' ', $q); foreach ($searchWords as $word) {
$within = false; if (stripos($result["name"], $word) !== false) {
foreach ($searchWords as $word) { $within = true;
if (stripos($result["name"], $word) !== false) { }
$within = true;
} }
} if ($within) {
if ($within) { $weather = [];
$weather = []; $weather["title"] = "Wetter in " . $result["name"];
$weather["title"] = "Wetter in " . $result["name"]; $weather["URL"] = "http://openweathermap.org/city/" . $result["id"];
$weather["URL"] = "http://openweathermap.org/city/" . $result["id"];
$summary = '<b class="detail-short">' . $result["main"]["temp"] . " °C, " . $result["weather"][0]["description"] . "</b>";
$summary = '<b class="detail-short">' . $result["main"]["temp"] . " °C, " . $result["weather"][0]["description"] . "</b>"; $details = '<table class="table table-condensed"><tr><td>Temperatur</td><td>' . $result["main"]["temp_min"] . " bis " . $result["main"]["temp_max"] . " °C</td></tr>";
$details = '<table class="table table-condensed"><tr><td>Temperatur</td><td>' . $result["main"]["temp_min"] . " bis " . $result["main"]["temp_max"] . " °C</td></tr>"; $details .= "<tr><td>Druck</td><td>" . $result["main"]["pressure"] . " hPa</td></tr>";
$details .= "<tr><td>Druck</td><td>" . $result["main"]["pressure"] . " hPa</td></tr>"; $details .= "<tr><td>Luftfeuchtigkeit</td><td>" . $result["main"]["humidity"] . " %</td></tr>";
$details .= "<tr><td>Luftfeuchtigkeit</td><td>" . $result["main"]["humidity"] . " %</td></tr>"; $details .= "<tr><td>Wind</td><td>" . $result["wind"]["speed"] . " m/s, " . $result["wind"]["deg"] . "°</td></tr>";
$details .= "<tr><td>Wind</td><td>" . $result["wind"]["speed"] . " m/s, " . $result["wind"]["deg"] . "°</td></tr>"; $details .= "<tr><td>Bewölkung</td><td>" . $result["clouds"]["all"] . " %</td></tr>";
$details .= "<tr><td>Bewölkung</td><td>" . $result["clouds"]["all"] . " %</td></tr>"; if (isset($result->rain)) {
if (isset($result->rain)) { $details .= " | Regen letzte drei Stunden: " . $result["rain"]["3h"] . " h";
$details .= " | Regen letzte drei Stunden: " . $result["rain"]["3h"] . " h"; }
$details .= "</table>";
$weather["summary"] = $summary;
$weather["details"] = $details;
$weather["gefVon"] = "von <a href = \"https://openweathermap.org\" target=\"_blank\" rel=\"noopener\">Openweathermap</a>";
$requestData = [];
$requestData["url"] = "http://openweathermap.org/img/w/";
$weather["image"] = action('Pictureproxy@get', $requestData) . $result["weather"][0]["icon"] . ".png";
$weather["image-alt"] = $result["weather"][0]["main"];
$mquicktips[] = $weather;
} }
$details .= "</table>"; } catch (\ErrorException $e) {
$weather["summary"] = $summary;
$weather["details"] = $details;
$weather["gefVon"] = "von <a href = \"https://openweathermap.org\" target=\"_blank\" rel=\"noopener\">Openweathermap</a>";
$requestData = [];
$requestData["url"] = "http://openweathermap.org/img/w/";
$weather["image"] = action('Pictureproxy@get', $requestData) . $result["weather"][0]["icon"] . ".png";
$weather["image-alt"] = $result["weather"][0]["main"];
$mquicktips[] = $weather;
} }
} catch (\ErrorException $e) {
} }
# Wikipedia Quicktip # Wikipedia Quicktip
...@@ -157,49 +159,48 @@ class MetaGerSearch extends Controller ...@@ -157,49 +159,48 @@ class MetaGerSearch extends Controller
} }
$mquicktips = array_merge($mquicktips, $quicktips); $mquicktips = array_merge($mquicktips, $quicktips);
# Dict.cc Quicktip if(APP::getLocale() === "de"){
if (count(explode(' ', $q)) < 3) { # Dict.cc Quicktip
$url = "http://www.dict.cc/metager.php?s=" . urlencode($q); if (count(explode(' ', $q)) < 3) {
$decodedResponse = json_decode($this->get($url), true); $url = "http://www.dict.cc/metager.php?s=" . urlencode($q);
if ($decodedResponse["headline"] != "" && $decodedResponse["link"] != "") { $decodedResponse = json_decode($this->get($url), true);
$quicktip = []; if ($decodedResponse["headline"] != "" && $decodedResponse["link"] != "") {
$quicktip["title"] = $decodedResponse["headline"]; $quicktip = [];
$quicktip["URL"] = $decodedResponse["link"]; $quicktip["title"] = $decodedResponse["headline"];
$quicktip["summary"] = implode(", ", $decodedResponse["translations"]); $quicktip["URL"] = $decodedResponse["link"];
$quicktip['gefVon'] = trans('metaGerSearch.quicktips.dictcc.adress'); $quicktip["summary"] = implode(", ", $decodedResponse["translations"]);
$quicktip['gefVon'] = trans('metaGerSearch.quicktips.dictcc.adress');
if (App::isLocale('de')) {
array_unshift($mquicktips, $quicktip); if (App::isLocale('de')) {
} else { array_unshift($mquicktips, $quicktip);
$mquicktips[] = $quicktip; } else {
$mquicktips[] = $quicktip;
}
} }
} }
}
# wussten Sie schon
# 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' => trans('metaGerSearch.quicktips.tips.title'), 'summary' => $tip, 'URL' => '/tips'];
$mquicktips[] = ['title' => trans('metaGerSearch.quicktips.tips.title'), 'summary' => $tip, 'URL' => '/tips']; }
}
# Werbelinks
# 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)]; if (isset($ads['details'])) {
if (isset($ads['details'])) { $mquicktips[] = ['title' => $ad['title'], 'summary' => $ad['summary'], 'details' => $ad['details'], 'URL' => $ad['URL']];
$mquicktips[] = ['title' => $ad['title'], 'summary' => $ad['summary'], 'details' => $ad['details'], 'URL' => $ad['URL']]; } else {
} else { $mquicktips[] = ['title' => $ad['title'], 'summary' => $ad['summary'], 'URL' => $ad['URL']];
$mquicktips[] = ['title' => $ad['title'], 'summary' => $ad['summary'], 'URL' => $ad['URL']]; }
} }
} }
# Spendenaufruf:
//$mquicktips[] = ['title' => trans('quicktip.spende.title'), 'summary' => trans('quicktip.spende.descr'), 'URL' => LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "spendenaufruf")];
return view('quicktip') return view('quicktip')
->with('spruch', $spruch) ->with('spruch', $spruch)
->with('mqs', $mquicktips); ->with('mqs', $mquicktips);
......
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