From b1ed1f48ea6567265b57dda365c68e8dffe2e17f Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 3 Feb 2016 12:55:00 +0100 Subject: [PATCH] Configurable linkify for bare IPv4/IPv6 --- lib/default.php | 3 +++ lib/util.php | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/default.php b/lib/default.php index 2e681e34b1..947875fa58 100644 --- a/lib/default.php +++ b/lib/default.php @@ -204,7 +204,10 @@ $default = array('default' => null, 'welcome' => null), 'linkify' => array( + // "bare" below means "without schema", like domain.com vs. https://domain.com 'bare_domains' => false, // convert domain.com to domain.com ? + 'bare_ipv4' => false, // convert IPv4 addresses to hyperlinks? + 'bare_ipv6' => false, // convert IPv6 addresses to hyperlinks? ), 'attachments' => array('server' => null, diff --git a/lib/util.php b/lib/util.php index f61ecf35d7..3f6e5e94ec 100644 --- a/lib/util.php +++ b/lib/util.php @@ -953,10 +953,14 @@ function common_replace_urls_callback($text, $callback, $arg = null) { ')'. // URLs without domain name, like magnet:?xt=... '|(?:(?:' . implode('|', common_url_schemes(_URL_SCHEME_NO_DOMAIN)) . '):)'. - '|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'. //IPv4 - '|(?:'. //IPv6 - '\[?(?:(?:(?:[0-9A-Fa-f]{1,4}:){7}(?:(?:[0-9A-Fa-f]{1,4})|:))|(?:(?:[0-9A-Fa-f]{1,4}:){6}(?::|(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})|(?::[0-9A-Fa-f]{1,4})))|(?:(?:[0-9A-Fa-f]{1,4}:){5}(?:(?::(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|(?:(?::[0-9A-Fa-f]{1,4}){1,2})))|(?:(?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