From ee4e4b034562d1c54b790d39495c482528b491e8 Mon Sep 17 00:00:00 2001
From: coderkun
Date: Mon, 21 Apr 2014 13:59:58 +0200
Subject: [PATCH] add rudimental support for formatting links and tables to
class TextFormatter
---
app/TextFormatter.inc | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/app/TextFormatter.inc b/app/TextFormatter.inc
index 38fea174..e226c7e5 100644
--- a/app/TextFormatter.inc
+++ b/app/TextFormatter.inc
@@ -57,8 +57,22 @@
*/
public function t($string)
{
- // Remove chars and replace linefeeds
- $string = nl2br(htmlspecialchars($string));
+ // Remove chars
+ $string = htmlspecialchars($string, ENT_NOQUOTES);
+
+ // Create tables
+ $string = str_replace('[table]', '
', $string);
+ $string = str_replace('[/table]', '
', $string);
+ $string = str_replace('[tr]', '
', $string);
+ $string = str_replace('[/tr]', '
', $string);
+ $string = str_replace('[th]', '', $string);
+ $string = str_replace('[/th]', ' | ', $string);
+ $string = str_replace('[td]', '', $string);
+ $string = str_replace('[/td]', ' | ', $string);
+
+ // Create links
+ $string = preg_replace('!(^|\s)"([^"]+)":(https?://[^\s]+)(\s|$)!i', '$1$2$4', $string);
+ $string = preg_replace('!(^|\s)(https?://[^\s]+)(\s|$)!i', '$1$2$4', $string);
// Handle Seminarymedia
$seminarymedia = array();
@@ -89,7 +103,7 @@
// Return processed string
- return $string;
+ return nl2br($string);
}