From 381f2d6ec29c08264a6fcf5066ff97cc32698595 Mon Sep 17 00:00:00 2001
From: Dan Untenzu <untenzu@webit.de>
Date: Tue, 17 Jan 2017 12:37:34 +0100
Subject: [PATCH] [FEATURE] Replace markers in templates

Add a function to allow a simple marker replacement,
eg. for the Terms of Service page.

Markers have the scheme "###MARKERNAME###".
---
 lib/functions.php | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lib/functions.php b/lib/functions.php
index 47fbc40..a89d8b8 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -1359,3 +1359,31 @@ jirafeau_alias_delete ($alias, $password)
     return 'Ok';
 }
 
+/**
+ * Replace markers in templates.
+ *
+ * Available markers have the scheme "###MARKERNAME###".
+ *
+ * @param $content string Template text with markers
+ * @param $htmllinebreaks boolean Convert linebreaks to BR-Tags
+ * @return Template with replaced markers
+ */
+function
+jirafeau_replace_markers ($content, $htmllinebreaks = false)
+{
+    $patterns = array(
+        '/###ORGANISATION###/',
+        '/###CONTACTPERSON###/'
+    );
+    $replacements = array(
+        '[ORGANISATION PROVIDING THIS WEBSITE]',
+        'contact@[THIS WEBSITE]'
+    );
+    $content = preg_replace($patterns, $replacements, $content);
+
+    if (true === $htmllinebreaks) {
+        $content = nl2br($content);
+    }
+
+    return $content;
+}
\ No newline at end of file
-- 
2.34.1