From 3940a174f133c54550f4c7f5c5479d83d1097218 Mon Sep 17 00:00:00 2001
From: Karl Hasselbring <karl@suma-ev.de>
Date: Fri, 3 Aug 2018 10:54:50 +0200
Subject: [PATCH] Tips.xml wird von quicktip server geladen

---
 app/Http/Controllers/MetaGerSearch.php  | 25 +++++++++++++++++++++++++
 resources/lang/de/sidebar.php           |  1 +
 resources/lang/de/tips.php              |  4 ++--
 resources/views/parts/sidebar.blade.php |  8 ++++----
 resources/views/tips.blade.php          | 18 +++++++++++-------
 5 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/app/Http/Controllers/MetaGerSearch.php b/app/Http/Controllers/MetaGerSearch.php
index 0def780b6..8859d691d 100644
--- a/app/Http/Controllers/MetaGerSearch.php
+++ b/app/Http/Controllers/MetaGerSearch.php
@@ -6,6 +6,9 @@ use App;
 use App\MetaGer;
 use Illuminate\Http\Request;
 
+#const TIP_SERVER = 'https://quicktips.metager3.de/tips.xml';
+const TIP_SERVER = 'http://localhost:63825/tips.xml';
+
 class MetaGerSearch extends Controller
 {
     public function search(Request $request, MetaGer $metager)
@@ -70,4 +73,26 @@ class MetaGerSearch extends Controller
         $length = strlen($needle);
         return (substr($haystack, 0, $length) === $needle);
     }
+
+    public function tips(Request $request)
+    {
+        $tips_text = file_get_contents(TIP_SERVER);
+        $tips = [];
+        try {
+            $tips_xml = simplexml_load_string($tips_text);
+
+            $tips_xml->registerXPathNamespace('mg', 'http://metager.de/tips/');
+            $tips_xml = $tips_xml->xpath('mg:tip');
+            foreach ($tips_xml as $tip_xml) {
+                $tips[] = $tip_xml->__toString();
+            }
+        } catch (\Exception $e) {
+            Log::error("A problem occurred loading tips from the tip server.");
+            Log::error($e->getMessage());
+            abort(500);
+        }
+        return view('tips')
+            ->with('title', trans('tips.title'))
+            ->with('tips', $tips);
+    }
 }
diff --git a/resources/lang/de/sidebar.php b/resources/lang/de/sidebar.php
index 0cafa120b..61dc1bc67 100644
--- a/resources/lang/de/sidebar.php
+++ b/resources/lang/de/sidebar.php
@@ -27,4 +27,5 @@ return [
     'nav25' => 'MetaGer App',
     'nav26' => 'MetaGer-Fanshop',
     'navigationToggle' => 'Navigation anzeigen',
+    'titles.tips' => 'Tips',
 ];
diff --git a/resources/lang/de/tips.php b/resources/lang/de/tips.php
index 30d9df554..cb2bed96c 100644
--- a/resources/lang/de/tips.php
+++ b/resources/lang/de/tips.php
@@ -1,6 +1,6 @@
 <?php
 
 return [
-    "title"	=>	"MetaGer Tipps, unsortiert - dies & das - wussten Sie schon?",
-    "shorttitle"	=>	"Wussten Sie schon?"
+    "title" => "MetaGer Tipps, unsortiert - wussten Sie schon?",
+    "shorttitle" => "Wussten Sie schon?",
 ];
diff --git a/resources/views/parts/sidebar.blade.php b/resources/views/parts/sidebar.blade.php
index 10fa20a7e..ed5e2fbf4 100644
--- a/resources/views/parts/sidebar.blade.php
+++ b/resources/views/parts/sidebar.blade.php
@@ -29,16 +29,16 @@
           <a class="inlink" href="https://metager.de/klassik/asso/" tabindex="228">{{ trans('sidebar.nav11') }}</a>
         </li>
         <li>
-          <a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/app/") }}" tabindex="230">@lang('sidebar.nav25')</a>
+          <a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/app/") }}" tabindex="229">@lang('sidebar.nav25')</a>
         </li>
         <li>
-          <a class="inlink" href="https://metager.to/" tabindex="231">{{ trans('sidebar.nav13') }}</a>
+          <a href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/tips/") }}" tabindex="230">{{ trans('sidebar.titles.tips') }}</a>
         </li>
         <li>
-          <a class="inlink" href="https://maps.metager.de" target="_blank" tabindex="232">Maps.MetaGer.de</a>
+          <a class="inlink" href="https://maps.metager.de" target="_blank" tabindex="231">Maps.MetaGer.de</a>
         </li>
         <li>
-          <a class="outlink" href="https://gitlab.metager3.de/open-source/MetaGer" tabindex="233">{{ trans('sidebar.nav24') }}</a>
+          <a class="outlink" href="https://gitlab.metager3.de/open-source/MetaGer" tabindex="232">{{ trans('sidebar.nav24') }}</a>
         </li>
         <li>
           <a class="outlink" href="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), "/tor/") }}" tabindex="234">{{ trans('sidebar.nav14') }}</a>
diff --git a/resources/views/tips.blade.php b/resources/views/tips.blade.php
index 85efd7c9c..1ed2edf7c 100644
--- a/resources/views/tips.blade.php
+++ b/resources/views/tips.blade.php
@@ -1,12 +1,16 @@
-@extends('layouts.staticPages')
+@extends('layouts.subPages')
 
 @section('title', $title )
 
+@section('navbarFocus.tips', 'class="active"')
+
 @section('content')
-	<h1>{!! trans('tips.title') !!}</h1>
-	<ol>
-		@foreach( $tips as $tip )
-			<li>{!! $tip !!}</li>
-		@endforeach
-	</ol>
+	<h1 class="page-title">{!! trans('tips.title') !!}</h1>
+	<div class="card-heavy">
+		<ol>
+			@foreach( $tips as $tip )
+				<li>{!! $tip !!}</li>
+			@endforeach
+		</ol>
+	</div>
 @endsection
-- 
GitLab