// create hyperlinks for http:// addresses
// there's a testcase for this in /build/testcases/urllinking.txt
- $replaceFrom = array(
- '/([^:\/\/\w]|^)((https:\/\/)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie',
- '/([^:\/\/\w]|^)((http:\/\/|www\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie',
- '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie',
- '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/ie'
+\r
+ $replace_from = array(\r
+ '/([^:\/\/\w]|^)((https:\/\/)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/i',\r
+ '/([^:\/\/\w]|^)((http:\/\/|www\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/i',\r
+ '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/i',\r
+ '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/i'\r
);
- $replaceTo = array(
- 'COMMENT::createLinkCode("\\1", "\\2","https")',
- 'COMMENT::createLinkCode("\\1", "\\2","http")',
- 'COMMENT::createLinkCode("\\1", "\\2","ftp")',
- 'COMMENT::createLinkCode("\\1", "\\3","mailto")'
- );
- $body = preg_replace($replaceFrom, $replaceTo, $body);
-
+
+ $body = preg_replace_callback($replace_from, array('self', 'prepareBody_cb'), $body);
+
return $body;
}
return $pre . '<a href="' . $linkedUrl . '" rel="nofollow">' . shorten($displayedUrl,30,'...') . '</a>' . $post;
}
+
+\r
+ /**\r
+ * This method is a callback for creating link codes\r
+ * @param array $match\r
+ * @return string\r
+ */\r
+ function prepareBody_cb($match)\r
+ {\r
+ if ( !preg_match('/^[a-z]+/i', $match[2], $protocol) )\r
+ {\r
+ return $match[0];\r
+ }\r
+\r
+ switch( strtolower($protocol[0]) )\r
+ {\r
+ case 'https':\r
+ return self::createLinkCode($match[1], $match[2], 'https');\r
+ break;\r
+\r
+ case 'ftp':\r
+ return self::createLinkCode($match[1], $match[2], 'ftp');\r
+ break;\r
+\r
+ case 'mailto':\r
+ return self::createLinkCode($match[1], $match[3], 'mailto');\r
+ break;\r
+\r
+ default:\r
+ return self::createLinkCode($match[1], $match[2], 'http');\r
+ break;\r
+ }\r
+ }
+
}
?>
\ No newline at end of file