aboutsummaryrefslogtreecommitdiffstats
path: root/include/text.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2012-01-17 16:30:32 -0800
committerfriendica <info@friendica.com>2012-01-17 16:30:32 -0800
commitd84094362165524ce64fb2f0a588a376efa96c68 (patch)
tree57a9fe91c49aa356bfc8ff766174f36c6f8d3eec /include/text.php
parent2cc02716e1866ca16f941f82874fa7471af613a1 (diff)
downloadvolse-hubzilla-d84094362165524ce64fb2f0a588a376efa96c68.tar.gz
volse-hubzilla-d84094362165524ce64fb2f0a588a376efa96c68.tar.bz2
volse-hubzilla-d84094362165524ce64fb2f0a588a376efa96c68.zip
use reltoabs - primarily for github activity feeds
Diffstat (limited to 'include/text.php')
-rw-r--r--include/text.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/text.php b/include/text.php
index 1db88ca2c..416e19927 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1065,3 +1065,37 @@ function array_xmlify($val){
if (is_array($val)) return array_map('array_xmlify', $val);
return xmlify((string) $val);
}
+
+
+function reltoabs($text, $base)
+{
+ if (empty($base))
+ return $text;
+
+ $base = rtrim($base,'/');
+
+ $base2 = $base . "/";
+
+ // Replace links
+ $pattern = "/<a([^>]*) href=\"(?!http|https|\/)([^\"]*)\"/";
+ $replace = "<a\${1} href=\"" . $base2 . "\${2}\"";
+ $text = preg_replace($pattern, $replace, $text);
+
+ $pattern = "/<a([^>]*) href=\"(?!http|https)([^\"]*)\"/";
+ $replace = "<a\${1} href=\"" . $base . "\${2}\"";
+ $text = preg_replace($pattern, $replace, $text);
+
+ // Replace images
+ $pattern = "/<img([^>]*) src=\"(?!http|https|\/)([^\"]*)\"/";
+ $replace = "<img\${1} src=\"" . $base2 . "\${2}\"";
+ $text = preg_replace($pattern, $replace, $text);
+
+ $pattern = "/<img([^>]*) src=\"(?!http|https)([^\"]*)\"/";
+ $replace = "<img\${1} src=\"" . $base . "\${2}\"";
+ $text = preg_replace($pattern, $replace, $text);
+
+
+ // Done
+ return $text;
+}
+