summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorfisharebest <fisharebest@gmail.com>2013-10-22 13:19:01 +0100
committerfisharebest <fisharebest@gmail.com>2013-10-22 13:19:31 +0100
commitf0a555c029d14a0cecf97dde5d1ee92afd32bdbb (patch)
tree7a16ddec95acf928b0bcd70047a950cd518a52ed /library
parent4c3550ab962551ce850a75e43eb8b96d2e8f9438 (diff)
downloadwebtrees-f0a555c029d14a0cecf97dde5d1ee92afd32bdbb.tar.gz
webtrees-f0a555c029d14a0cecf97dde5d1ee92afd32bdbb.tar.bz2
webtrees-f0a555c029d14a0cecf97dde5d1ee92afd32bdbb.zip
Two busg: #1237452 - New user/New registration mails - Family Tree Title with ' - dev; #1237458 - Webtrees messages with odd texts - dev
Diffstat (limited to 'library')
-rw-r--r--library/WT/Filter.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/library/WT/Filter.php b/library/WT/Filter.php
index b3572daf2c..80536b17cf 100644
--- a/library/WT/Filter.php
+++ b/library/WT/Filter.php
@@ -24,6 +24,14 @@ if (!defined('WT_WEBTREES')) {
}
class WT_Filter {
+ // REGEX to match a URL
+ // Some versions of RFC3987 have an appendix B which gives the following regex
+ // (([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
+ // This matches far too much while a “precise” regex is several pages long.
+ // This is a compromise.
+ const URL_REGEX='((https?|ftp]):)(//([^\s/?#<>]*))?([^\s?#<>]*)(\?([^\s#<>]*))?(#[^\s?#<>]+)?';
+
+
//////////////////////////////////////////////////////////////////////////////
// Escape a string for use in HTML
//////////////////////////////////////////////////////////////////////////////
@@ -68,6 +76,22 @@ class WT_Filter {
}
//////////////////////////////////////////////////////////////////////////////
+ // Escape a string for use in HTML, and additionally:
+ // Convert URLs to links, inserting soft-hyphens at word boundaries so that
+ // the browser can word-wrap.
+ //////////////////////////////////////////////////////////////////////////////
+ public static function expandUrls($text) {
+ return preg_replace_callback(
+ '/' . addcslashes('(?!>)' . self::URL_REGEX . '(?!</a>)', '/') . '/i',
+ create_function( // Insert soft hyphens into the replaced string
+ '$m',
+ 'return "<a href=\"" . $m[0] . "\" target=\"blank\">" . preg_replace("/\b/", "&shy;", $m[0]) . "</a>";'
+ ),
+ nl2br(WT_Filter::escapeHtml($text), false)
+ );
+ }
+
+ //////////////////////////////////////////////////////////////////////////////
// Validate INPUT requests
//////////////////////////////////////////////////////////////////////////////
private static function _input($source, $variable, $regexp=null, $default=null) {