support for bitcoin: URIs. It probably should cleanup/strip any extra //, but I'll leave that to someone else to figure out. It also tries to detect standalone bitcoin addresses and turn them into links. I haven't tested it at all, so use at your own risk. Donations for this patch to 1HXo9py5hFsa528ZuXnSPHcXMyKiB7GN5U
diff -ur smf_1-1-13_install/Sources/Subs-Post.php smf_1-1-13_install.bitcoin/Sources/Subs-Post.php
--- smf_1-1-13_install/Sources/Subs-Post.php 2011-02-07 11:45:09.000000000 -0500
+++ smf_1-1-13_install.bitcoin/Sources/Subs-Post.php 2011-06-11 12:29:56.169981884 -0400
@@ -330,28 +330,28 @@
// [url]http://...[/url]
array(
'tag' => 'url',
- 'protocols' => array('http', 'https'),
+ 'protocols' => array('http', 'https', 'bitcoin:'),
'embeddedUrl' => true,
'hasEqualSign' => false,
),
// [url=http://...]name[/url]
array(
'tag' => 'url',
- 'protocols' => array('http', 'https'),
+ 'protocols' => array('http', 'https', 'bitcoin:'),
'embeddedUrl' => true,
'hasEqualSign' => true,
),
// [iurl]http://...[/iurl]
array(
'tag' => 'iurl',
- 'protocols' => array('http', 'https'),
+ 'protocols' => array('http', 'https', 'bitcoin:'),
'embeddedUrl' => true,
'hasEqualSign' => false,
),
// [iurl=http://...]name[/iurl]
array(
'tag' => 'iurl',
- 'protocols' => array('http', 'https'),
+ 'protocols' => array('http', 'https', 'bitcoin:'),
'embeddedUrl' => true,
'hasEqualSign' => true,
),
@@ -475,7 +475,10 @@
$found = false;
foreach ($protocols as $protocol)
{
+ if (strpos($protocol, ':') === false)
$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
+ else
+ $found = strncasecmp($replace, $protocol, strlen($protocol)) === 0;
if ($found)
break;
}
diff -ur smf_1-1-13_install/Sources/Subs.php smf_1-1-13_install.bitcoin/Sources/Subs.php
--- smf_1-1-13_install/Sources/Subs.php 2011-02-07 11:45:09.000000000 -0500
+++ smf_1-1-13_install.bitcoin/Sources/Subs.php 2011-06-11 12:53:18.829672859 -0400
@@ -1330,7 +1330,7 @@
'content' => '<a href="$1">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
$data = strtr($data, array(\'<br />\' => \'\'));
- if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
+ if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0 && strpos($data, \'bitcoin:\') !== 0)
$data = \'http://\' . $data;
'),
),
@@ -1342,7 +1342,7 @@
'validate' => create_function('&$tag, &$data, $disabled', '
if (substr($data, 0, 1) == \'#\')
$data = \'#post_\' . substr($data, 1);
- elseif (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
+ elseif (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0 && strpos($data, \'bitcoin:\') !== 0)
$data = \'http://\' . $data;
'),
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1599,7 +1599,7 @@
'content' => '<a href="$1" target="_blank">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
$data = strtr($data, array(\'<br />\' => \'\'));
- if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
+ if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0 && strpos($data, \'bitcoin:\') !== 0)
$data = \'http://\' . $data;
'),
),
@@ -1609,7 +1609,7 @@
'before' => '<a href="$1" target="_blank">',
'after' => '</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
- if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
+ if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0 && strpos($data, \'bitcoin:\') !== 0)
$data = \'http://\' . $data;
'),
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1747,7 +1747,7 @@
// Take care of some HTML!
if (!empty($modSettings['enablePostHTML']) && strpos($data, '<') !== false)
{
- $data = preg_replace('~<a\s+href=((?:")?)((?:https?://|ftps?://|mailto:)\S+?)\\1>~i', '[url=$2]', $data);
+ $data = preg_replace('~<a\s+href=((?:")?)((?:https?://|ftps?://|mailto:|bitcoin:)\S+?)\\1>~i', '[url=$2]', $data);
$data = preg_replace('~</a>~i', '[/url]', $data);
// <br /> should be empty.
@@ -1836,10 +1836,14 @@
// Only do this if the preg survives.
if (is_string($result = preg_replace(array(
'~(?<=[\s>\.(;\'"]|^)((?:http|https|ftp|ftps)://[\w\-_%@:|]+(?:\.[\w\-_%]+)*(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i',
- '~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i'
+ '~(?<=[\s>(\'<]|^)(www(?:\.[\w\-_]+)+(?::\d+)?(?:/[\w\-_\~%\.@,\?&;=#(){}+:\'\\\\]*)*[/\w\-_\~%@\?;=#}\\\\])~i',
+ '~bitcoin:(\w+(?:\?\S+)?)~i',
+ '~\b([1-9A-HJ-NP-Za-km-z]{26,35})\b'
), array(
'[url]$1[/url]',
- '[url=http://$1]$1[/url]'
+ '[url=http://$1]$1[/url]',
+ '[url]$1[/url]',
+ '[url=bitcoin:$1]$1[/url]',
), $data)))
$data = $result;