]> git.mxchange.org Git - friendica.git/commitdiff
Better design for links in Mastodon posts
authorMichael <heluecht@pirati.ca>
Mon, 8 May 2017 12:18:30 +0000 (12:18 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 8 May 2017 12:18:30 +0000 (12:18 +0000)
include/bbcode.php

index d891f23dae4c07f5c4c8091e0a2a5e898130d544..8969b35e1134568919d2d6b9a11907e071574992 100644 (file)
@@ -170,6 +170,36 @@ function cleancss($input) {
        return $cleaned;
 }
 
+function bb_style_url($match) {
+        $url = $match[1];
+
+        $parts = parse_url($url);
+        if (!isset($parts['scheme'])) {
+                return $url;
+        }
+
+        $styled_url = $url;
+
+        $scheme = $parts['scheme'].'://';
+        $styled_url = str_replace($scheme, '', $styled_url);
+
+        $html = '<a href="%s" rel="nofollow noopener" target="_blank">'.
+                 '<span class="invisible">%s</span>';
+
+        if (strlen($styled_url) > 30) {
+                $html .= '<span class="ellipsis">%s</span>'.
+                        '<span class="invisible">%s</span></a>';
+
+                $ellipsis = substr($styled_url, 0, 30);
+                $rest = substr($styled_url, 30);
+                return sprintf($html, $url, $scheme, $ellipsis, $rest);
+        } else {
+                $html .= '%s</a>';
+                return sprintf($html, $url, $scheme, $styled_url);
+        }
+}
+
+
 function stripcode_br_cb($s) {
        return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]';
 }
@@ -956,6 +986,10 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        $Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
                                '$1<a href="$2" class="tag" title="$3">$3</a>', $Text);
 
+       if ($simplehtml == 7) {
+               $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text);
+       }
+
        $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$1</a>', $Text);
        $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
        //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);