Bravo List
Register
Go Back   > Bravo List > Source Code > Archived Trackers > TBDev
Reply
  #1  
Old 14th February 2019, 12:08
Tedmorris Tedmorris is offline
Senior Member
 
Join Date: Sep 2017
Posts: 62
Default 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:
[img]http://www/image.gif[/img]
$s preg_replace("/\[img\](http:\/\/[^\s'\"<>]+(\.gif|\.jpg|\.png))\[\/img\]/""<img border=0 src=\"\\1\">"$s); 
To this..

PHP Code:
[img]http://www/image.gif[/img]
$s preg_replace("/\[img\](http:\/\/[^\s'\"<>]+(\.gif|\.jpg|\.png))\[\/img\]/""<img border=0 src=\"\\https://images.weserv.nl/?url=ssl:\1\" >"$s); 
Is outputting https://images.weserv.nl/?url=ssl:" width="150" height="150" alt=""> I'm not getting the image url inserted and I know I need to strip the http:// from it but wanted to try atleast getting the http link added to the end of the image proxy link first. The src="\\1" appears to be the user inputted url but I've formatted it wrong in the modded version..

Any help would be great and much appreciated.[/QUOTE]
Reply With Quote
  #2  
Old 14th February 2019, 12:18
darkalchemy darkalchemy is offline
Administrator
 
Join Date: Dec 2017
United States
Posts: 101
Default
I think you are missing a back slash.
Code:
url=ssl:\1
Code:
url=ssl:\\1
There may be other mistakes, but this is the first thing I saw.
Reply With Quote
  #3  
Old 14th February 2019, 12:48
Tedmorris Tedmorris is offline
Senior Member
 
Join Date: Sep 2017
Posts: 62
Default
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 ?
Reply With Quote
  #4  
Old 14th February 2019, 12:56
darkalchemy darkalchemy is offline
Administrator
 
Join Date: Dec 2017
United States
Posts: 101
Default
Change:
Code:
(http:\/\/
To:
Code:
http:\/\/(
Reply With Quote
  #5  
Old 14th February 2019, 13:27
Tedmorris Tedmorris is offline
Senior Member
 
Join Date: Sep 2017
Posts: 62
Default
Sweet. Now outputting

https://images.weserv.nl/?url=ssl:images2.imagebam.com/2f/9d/32/b55ec21038500004.png">

From..
PHP 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); 
For some reason I'm guessing the >" at the end of the png is causing the problem as the image wont render and just outputs the above.
Reply With Quote
  #6  
Old 14th February 2019, 14:03
darkalchemy darkalchemy is offline
Administrator
 
Join Date: Dec 2017
United States
Posts: 101
Default
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);
It seems that you changed your needs from your first post.

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.
Reply With Quote
  #7  
Old 14th February 2019, 14:37
Tedmorris Tedmorris is offline
Senior Member
 
Join Date: Sep 2017
Posts: 62
Default
Legend

PHP Code:
$s preg_replace("/\[img\]http:\/\/([^\s'\"<>]+(\.gif|\.jpg|\.png))\[\/img\]/""<img border=\"0\" src=\"https://images.weserv.nl/?url=ssl:\\1\">"$s); 
Works like a charm. Thank you so much. Now I just need to figure out how to apply it to rendered avatar images pulled from a users table row. Eventually I'd like to do as you have with the image proxy on the same server as the tracker in order to prevent being defendant on a 3rd party image proxy but one thing at a time I guess lol

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:
if ($CURUSER["avatars"] == "yes")
 
$avatar htmlspecialchars($row["avatar"]);
        
print(
"<td align=center width=150 style='padding: 0px'><img width=150 src=$avatar></td>\n"); 
To this..

PHP Code:
if ($CURUSER["avatars"] == "yes")
 
$avatar preg_replace("/\http:\/\/([^\s'\"<>]+(\.gif|\.jpg|\.png))\/""<img border=\"0\" src=\"https://images.weserv.nl/?url=ssl:\\$users[avatar]\">"$avatar);
        
print(
"<td align=center width=150 style='padding: 0px'><img width=150 src=$avatar></td>\n"); 

Last edited by Tedmorris; 14th February 2019 at 15:15.
Reply With Quote
  #8  
Old 14th February 2019, 17:21
darkalchemy darkalchemy is offline
Administrator
 
Join Date: Dec 2017
United States
Posts: 101
Default
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.
Reply With Quote
  #9  
Old 14th February 2019, 18:27
Tedmorris Tedmorris is offline
Senior Member
 
Join Date: Sep 2017
Posts: 62
Default
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:
$avatar $CURUSER["avatar"];
$avatar2 "https://images.weserv.nl/?url=ssl:$avatar";
  echo(
"<img src='$avatar2' />"); 
This works but the link outputs to https://images.weserv.nl/?url=ssl:ht...com/avatar.png so I need to strip the http:// from the variable first or try make preg_replace do it or try make it work with your custom function I guess.

I tried using
PHP Code:
$avatar2 preg_replace("/\http:\/\/([^\s'\"<>]+(\.gif|\.jpg|\.png))\/""<img border=\"0\" src=\"https://images.weserv.nl/?url=ssl:\\$avatar\">"$avatar2); 
But it doesn't work, I think I removed the img tags from it incorrectly.

PHP Code:
$avatar2 preg_replace("/\[img\]http:\/\/([^\s'\"<>]+(\.gif|\.jpg|\.png))\[\/img\]/""<img border=\"0\" src=\"https://images.weserv.nl/?url=ssl:\\$avatar\">"$avatar2); 
Reply With Quote
  #10  
Old 14th February 2019, 18:59
darkalchemy darkalchemy is offline
Administrator
 
Join Date: Dec 2017
United States
Posts: 101
Default
Just strip it out like
Code:
str_replace(['http://', 'https://'], $avatar)
My function is url_proxy, in bittorrent.php.

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.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT +2. The time now is 22:04. vBulletin skin by ForumMonkeys. Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.