aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2021-07-10 18:35:05 +0200
committerHarald Eilertsen <haraldei@anduin.net>2021-07-10 18:35:05 +0200
commit89d075c749b5b25dbc901c6d1337dcdad2c0670a (patch)
tree7f4c3d9106dd70d7a70ecfc7321ae744333ad2bb
parent3c1ff667a8fb7f177234f44e0d742da66e463669 (diff)
downloadvolse-hz-addons-89d075c749b5b25dbc901c6d1337dcdad2c0670a.tar.gz
volse-hz-addons-89d075c749b5b25dbc901c6d1337dcdad2c0670a.tar.bz2
volse-hz-addons-89d075c749b5b25dbc901c6d1337dcdad2c0670a.zip
unshorturl: replace with long url
-rw-r--r--unshorturl/unshorturl.php19
1 files changed, 18 insertions, 1 deletions
diff --git a/unshorturl/unshorturl.php b/unshorturl/unshorturl.php
index e8c747a..f172b08 100644
--- a/unshorturl/unshorturl.php
+++ b/unshorturl/unshorturl.php
@@ -22,6 +22,23 @@ function unshorturl_uninstall() {
Hook::unregister('prepare_body', 'addon/unshorturl/unshorturl.php', 'unshorturl_prepare_body');
}
+function unshorturl_get_long_url($shorturl) {
+ $ch = curl_init($shorturl);
+ curl_setopt_array($ch, [
+ CURLOPT_HEADER => true,
+ CURLOPT_NOBODY => true,
+ CURLOPT_RETURNTRANSFER => true
+ ]);
+ $res = curl_exec($ch);
+
+ if ($res !== false) {
+ $matches = [];
+ if (preg_match('/^Location: (.*)$/', $res, $matches)) {
+ return $matches[1];
+ }
+ }
+}
+
function unshorturl_prepare_body(&$body) {
if (!local_channel() || !Apps::addon_app_installed(local_channel(), 'unshorturl')) {
return;
@@ -33,7 +50,7 @@ function unshorturl_prepare_body(&$body) {
foreach ($matches as $links) {
error_log('unshorturl: Links found: ' . implode(', ', $links));
foreach($links as $l) {
- $body['html'] = str_replace($l, '[filtered bit.ly url]', $body['html']);
+ $body['html'] = str_replace($l, unshorturl_get_long_url($l), $body['html']);
}
}
}