diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2021-07-10 18:35:05 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2021-07-10 18:35:05 +0200 |
commit | 89d075c749b5b25dbc901c6d1337dcdad2c0670a (patch) | |
tree | 7f4c3d9106dd70d7a70ecfc7321ae744333ad2bb | |
parent | 3c1ff667a8fb7f177234f44e0d742da66e463669 (diff) | |
download | volse-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.php | 19 |
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']); } } } |