From ead9cbe534d3c520957d72b543004c0fcce70c87 Mon Sep 17 00:00:00 2001
From: Pierre Rudloff <contact@rudloff.pro>
Date: Thu, 13 Apr 2017 02:24:27 +0200
Subject: [PATCH] Web app manifest (fixes #3317)

---
 mod/manifest.php                   | 26 ++++++++++++++++++++++++++
 view/templates/head.tpl            |  1 +
 view/templates/manifest.tpl        |  9 +++++++++
 view/theme/frio/templates/head.tpl |  1 +
 4 files changed, 37 insertions(+)
 create mode 100644 mod/manifest.php
 create mode 100644 view/templates/manifest.tpl

diff --git a/mod/manifest.php b/mod/manifest.php
new file mode 100644
index 0000000000..6dc0d10a21
--- /dev/null
+++ b/mod/manifest.php
@@ -0,0 +1,26 @@
+<?php
+    use Friendica\Core\Config;
+
+    function manifest_content(App $a) {
+
+		$tpl = get_markup_template('manifest.tpl');
+
+		header('Content-type: application/manifest+json');
+
+		$touch_icon = Config::get('system', 'touch_icon', 'images/friendica-128.png');
+		if ($touch_icon == '') {
+			$touch_icon = 'images/friendica-128.png';
+		}
+
+		$o = replace_macros($tpl, array(
+			'$baseurl' => App::get_baseurl(),
+			'$touch_icon' => $touch_icon,
+			'$title' => Config::get('config', 'sitename', 'Friendica'),
+		));
+
+		echo $o;
+
+		killme();
+
+	}
+?>
diff --git a/view/templates/head.tpl b/view/templates/head.tpl
index bfc5728ed2..e7df8a18cd 100644
--- a/view/templates/head.tpl
+++ b/view/templates/head.tpl
@@ -19,6 +19,7 @@
 <link rel="apple-touch-icon" href="{{$touch_icon}}"/>
 
 <meta name="apple-mobile-web-app-capable" content="yes" />
+<link rel="manifest" href="{{$baseurl}}/manifest" />
 <script>
 // Prevents links to switch to Safari in a home screen app - see https://gist.github.com/irae/1042167
 (function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(chref=d.href).replace(e.href,"").indexOf("#")&&(!/^[a-z\+\.\-]+:/i.test(chref)||chref.indexOf(e.protocol+"//"+e.host)===0)&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone");
diff --git a/view/templates/manifest.tpl b/view/templates/manifest.tpl
new file mode 100644
index 0000000000..6f9294774d
--- /dev/null
+++ b/view/templates/manifest.tpl
@@ -0,0 +1,9 @@
+{
+  "name": "{{$title}}",
+  "start_url": "{{$baseurl}}",
+  "display": "standalone",
+  "description": "A Decentralized Social Network",
+  "icons": [{
+    "src": "{{$baseurl}}/{{$touch_icon}}"
+  }]
+}
diff --git a/view/theme/frio/templates/head.tpl b/view/theme/frio/templates/head.tpl
index 32005417c8..882d2215cf 100644
--- a/view/theme/frio/templates/head.tpl
+++ b/view/theme/frio/templates/head.tpl
@@ -41,6 +41,7 @@
 <link rel="apple-touch-icon" href="{{$touch_icon}}"/>
 
 <meta name="apple-mobile-web-app-capable" content="yes" />
+<link rel="manifest" href="{{$baseurl}}/manifest" />
 <script>
 // Prevents links to switch to Safari in a home screen app - see https://gist.github.com/irae/1042167
 (function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(chref=d.href).replace(e.href,"").indexOf("#")&&(!/^[a-z\+\.\-]+:/i.test(chref)||chref.indexOf(e.protocol+"//"+e.host)===0)&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone");
-- 
2.39.5