|
#1
|
|||
|
|||
External image proxy modifications
I'm trying to use an external image proxy server to load http images over https. For example, a user uses the image tag on the forums of http://images2.imagebam.com/2f/9d/32...1038500004.png
By adding https://images.weserv.nl/?url=ssl: to the start of the url and stripping the http:// the embeded link becomes https://images.weserv.nl/?url=ssl:im...1038500004.png but I'm struggling to get it working in globalstar.. This.. PHP Code:
PHP Code:
Any help would be great and much appreciated.[/QUOTE] |
#2
|
|||
|
|||
I think you are missing a back slash.
Code:
url=ssl:\1 Code:
url=ssl:\\1 |
#3
|
|||
|
|||
Thanks champ.
Now outputting https://images.weserv.nl/?url=ssl:http://i68.tinypic.com/2qcm3x5.jpg" width="150" height="150" alt=""> Any idea how to strip the http:// from the image inserted via the [img] tag ? |
#4
|
|||
|
|||
Change:
Code:
(http:\/\/ Code:
http:\/\/( |
#5
|
|||
|
|||
Sweet. Now outputting
https://images.weserv.nl/?url=ssl:images2.imagebam.com/2f/9d/32/b55ec21038500004.png"> From.. PHP Code:
|
#6
|
|||
|
|||
This is a bit difficult to do on my phone. But this should work.
Code:
$s = preg_replace("/\[img\]http:\/\/([^\s'\"<>]+(\.gif|\.jpg|\.png))\[\/img\]/", "<img border=\"0\" src=\"https://images.weserv.nl/?url=ssl:\\1\">", $s); Code:
$s = preg_replace("/\[img\]http:\/\/([^\s'\"<>]+(\.(jpg|gif|png))\[\/img\]/i", "<a href=\"\\1\" target=\"_self\"><img border=\"0\" src=\"https://images.weserv.nl?url=ssl:\\1\"></a>", $s); Last edited by darkalchemy; 14th February 2019 at 14:13. |
#7
|
|||
|
|||
Legend
PHP Code:
Again many thanks m8. It's very appreciated. What does the "i" do that was removed from \[\/img\]/i", I know why it changed from first post, I used an older version in my last post that I had commented out and didnt realise until you pointed it out sry, I'm guessing if it's got the \.gif|\.jpg|\.png etc and not just gif| jpg|png then the "i" is required I'm thinking for the http avatars in forums, change this.. PHP Code:
PHP Code:
Last edited by Tedmorris; 14th February 2019 at 15:15. |
#8
|
|||
|
|||
Avatars are a bit more work, since they are requested all over.
They way that I handled it was to create a function that would replace the url with the proxied one. Then everywhere avatars are requested use the function. This also makes caching much easier. |
#9
|
|||
|
|||
Yeah it does seem a bit tricky, I've been playing around with it for the best part of 2 hours lol..is your function in the Pu-239 source?
I couldnt get the preg_replace to work, I'm still learning the metacharacters and how to use them properly. Havent played with the preg_replace function before. I tested that it outputs with a variable added without preg_replace.. PHP Code:
I tried using PHP Code:
PHP Code:
|
#10
|
|||
|
|||
Just strip it out like
Code:
str_replace(['http://', 'https://'], $avatar) Code:
function url_proxy($url, $image = false, $width = null, $height = null, $quality = null) { global $site_config; if (empty($url) || preg_match('#' . preg_quote($site_config['domain']) . '#', $url) || preg_match('#' . preg_quote($site_config['pic_baseurl']) . '#', $url)) { return $url; } if (!$image) { return (!empty($site_config['anonymizer_url']) ? $site_config['anonymizer_url'] : '') . $url; } if ($site_config['image_proxy']) { $image_proxy = new Pu239\ImageProxy(); $image = $image_proxy->get_image($url, $width, $height, $quality); if (!$image) { return $site_config['pic_baseurl'] . 'noposter.png'; } else { return $site_config['pic_baseurl'] . 'proxy/' . $image; } } return $url; } Last edited by darkalchemy; 14th February 2019 at 19:12. |
|
|