4images Forum & Community

4images Help / Hilfe => Bug Fixes & Patches => Topic started by: Chris on March 16, 2005, 04:24:54 AM

Title: [1.7] Allow IP in download URL and remote image path
Post by: Chris on March 16, 2005, 04:24:54 AM
This fix will let u use IP and FTP addresses in download URL and remote image path.

Open /includes/functions.php

Find:
Code: [Select]
  return (preg_match('#^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $file_name)) ? 1 : 0;
Replace with:
Code: [Select]
  return (preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?(\/)?/i", $file_name)) ? 1 : 0;

Find:
Code: [Select]
  return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.([a-z]{1,4})$)#is", $file_name)) ? 1 : 0;
Replace with:
Code: [Select]
  return (preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/.*\.([a-z]{1,4})$/i", $file_name)) ? 1 : 0;

Find:
Code: [Select]
  return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.(".$config['allowed_mediatypes_match'].")$)#is", $remote_media_file)) ? 1 : 0;
Replace with:
Code: [Select]
  return (preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/.*\.(".$config['allowed_mediatypes_match'].")$/i", $remote_media_file)) ? 1 : 0;

Find:
Code: [Select]
  return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.(gif|jpg|jpeg|png)$)#is", $remote_thumb_file)) ? 1 : 0;
Replace with:
Code: [Select]
  return (preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/.*\.(gif|jpg|jpeg|png)$/i", $remote_thumb_file)) ? 1 : 0;

Find:
Code: [Select]
  if (!preg_match("/^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+/i", $url)) {
Replace with:
Code: [Select]
  if (!preg_match("/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(:[A-Z0-9][A-Z0-9_-]*)?@)?(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?(\/)?/i", $url)) {

I've tested it with this url types:
http://example.com/image.jpg
http://user@example.com/image.jpg
http://user:pass@example.com/image.jpg
http://123.123.123.123/image.jpg
http://user@123.123.123.123/image.jpg
http://user:pass@123.123.123.123/image.jpg
ftp://, https:// and port numbers also working

Please let me know if u find anything not working after these changes.

P.S. there is a bug in member.php that let u upload not existing images by using remote url.
Title: Re: Allow IP in download URL and remote image path
Post by: oswald on March 16, 2005, 09:03:28 AM
Hmmm... what version is it for or what other mods do you have installed..... can't find most of the lines to edit in my original functions.php
Title: Re: Allow IP in download URL and remote image path
Post by: V@no on March 16, 2005, 02:43:53 PM
that fix for v1.7