aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authornatec <natec@users.sourceforge.net>2001-03-21 07:26:10 +0000
committernatec <natec@users.sourceforge.net>2001-03-21 07:26:10 +0000
commit61a067434bc63c72306fd1a25009606615512d71 (patch)
tree27c110b16e16f1a459976395ab686c4db56c8ba1 /phpBB
parentbf7ec7c8f01d84c6ed93474c4ac898acf9af3e6e (diff)
downloadforums-61a067434bc63c72306fd1a25009606615512d71.tar
forums-61a067434bc63c72306fd1a25009606615512d71.tar.gz
forums-61a067434bc63c72306fd1a25009606615512d71.tar.bz2
forums-61a067434bc63c72306fd1a25009606615512d71.tar.xz
forums-61a067434bc63c72306fd1a25009606615512d71.zip
Added make_clickable()
git-svn-id: file:///svn/phpbb/trunk@115 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/functions/bbcode.php42
-rw-r--r--phpBB/viewtopic.php2
2 files changed, 44 insertions, 0 deletions
diff --git a/phpBB/functions/bbcode.php b/phpBB/functions/bbcode.php
index 48fd28c080..b1a6a794cc 100644
--- a/phpBB/functions/bbcode.php
+++ b/phpBB/functions/bbcode.php
@@ -396,7 +396,49 @@ function bbencode_second_pass_code($text, $uid)
} // bbencode_second_pass_code()
+/**
+ * Rewritten by Nathan Codding - Feb 6, 2001.
+ * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking
+ * to that URL
+ * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking
+ * to http://www.xxxx.yyyy[/zzzz]
+ * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking
+ * to that email address
+ * - Only matches these 2 patterns either after a space, or at the beginning of a line
+ *
+ * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe
+ * have it require something like xxxx@yyyy.zzzz or such. We'll see.
+ */
+function make_clickable($text)
+{
+
+ // pad it with a space so we can match things at the start of the 1st line.
+ $ret = " " . $text;
+
+ // matches an "xxxx://yyyy" URL at the start of a line, or after a space.
+ // xxxx can only be alpha characters.
+ // yyyy is anything up to the first space, newline, or comma.
+ $ret = preg_replace("#([\n ])([a-z]+?)://([^, \n\r]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", $ret);
+
+ // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
+ // Must contain at least 2 dots. xxxx contains either alphanum, or "-"
+ // yyyy contains either alphanum, "-", or "."
+ // zzzz is optional.. will contain everything up to the first space, newline, or comma.
+ // This is slightly restrictive - it's not going to match stuff like "forums.foo.com"
+ // This is to keep it from getting annoying and matching stuff that's not meant to be a link.
+ $ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^, \n\r]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $ret);
+
+ // matches an email@domain type address at the start of a line, or after a space.
+ // Note: before the @ sign, the only valid characters are the alphanums and "-", "_", or ".".
+ // After the @ sign, we accept anything up to the first space, linebreak, or comma.
+ $ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([^, \n\r]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
+
+ // Remove our padding..
+ $ret = substr($ret, 1);
+
+ return($ret);
+}
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index a56c0288bf..e20edb015d 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -159,6 +159,8 @@ for($x = 0; $x < $total_posts; $x++)
$message = bbencode_second_pass($message, $bbcode_uid);
}
+ $message = make_clickable($message);
+
$message = str_replace("\n", "<BR>", $message);
if(!($x % 2))