FAP CUSTOMIZATION - FAP With REMOTE URL DOWNLOAD/LINK MOD
		
		
		Subject: Re: FAP With REMOTE URL DOWNLOAD/LINK MOD
		
						
	
		Unfortunately I don't have the time to have a look at this.
Do you have the same error as the first post in this topic?
		Do you have the same error as the first post in this topic?
		
		
		Subject: Re: FAP With REMOTE URL DOWNLOAD/LINK MOD
		
						
	
		
	
		
	###SOLVED BY REMORSEFUL###
###All except the $gd part but just ignore that for now I guess###
###Heres the full correct modification fixed by me###
###Also on a side note I will fix this part at a later time but the user must put the url of the image in the choose file upload box and click okay and then submit. This is a very easy fix on the .tpl i beleive but I'm to lazy to fix it ATM###
OPEN
FIND
		###All except the $gd part but just ignore that for now I guess###
###Heres the full correct modification fixed by me###
###Also on a side note I will fix this part at a later time but the user must put the url of the image in the choose file upload box and click okay and then submit. This is a very easy fix on the .tpl i beleive but I'm to lazy to fix it ATM###
OPEN
FIND
Code: [Download] [Hide] [Select]
############################################################## 
## MOD Title: ROMOTE URL DOWNLOAD/LINK MOD
## for Photo Album Addon v2 for phpBB2
## MOD Author: I'm not admitting to writing this one either.
## MOD Description:
##
## Download or Link to an image from another website.
##
## Tested with: phpBB 2.0.8 - PHP4.3.3
## MySQL 3.23.x and Smartor's Photo Album Addon v2 for phpBB2
##
## MOD Version:
##
## Installation Level: easy
## Installation Time: 15 minutes
##
## Files To Edit: 5
## album_upload.php
## album_thumbnail.php
## album_pic.php
## templates/subSilver/album_upload_body.tpl
## language/lang_english/lang_main_album.php
##
##############################################################
## Author Notes:
##
## Limited testing. Feedback is always nice.
## Take this as a beta version.
##
##############################################################
## Before Adding This MOD To Your Photo Album,
## You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ OPEN ]-------------------------------------------------------
#
album_upload.php
#
#-----[ FIND ]----------------------------------------
#
'L_MAX_FILESIZE' => $lang['Max_file_size'],
'S_MAX_FILESIZE' => $album_config['max_file_size'],
#
#-----[ BEFORE ADD ]----------------------------------------
#
'L_REMOTE_URL' => $lang['Remote_url'],
'L_REMOTE_DL' => $lang['Remote_DL'],
#
#-----[ FIND ]----------------------------------------
#
// --------------------------------
// Prepare variables
// --------------------------------
$pic_time = time();
$pic_user_id = $userdata['user_id'];
$pic_user_ip = $userdata['session_ip'];
#
#-----[ AFTER ADD ]----------------------------------------
#
// -----------------------
// Remote url download mod
// -----------------------
if( $HTTP_POST_FILES['pic_file']['size']==0 and $HTTP_POST_VARS['remote_url'] != "" and empty($HTTP_POST_VARS['remote_dl']) ) $HotLinked = true;
if( $HTTP_POST_FILES['pic_file']['size']==0 and $HTTP_POST_VARS['remote_url'] != "" )
{
$remote_filename = $HTTP_POST_VARS['remote_url'];
if ( preg_match('/^(h**p://)?([w-.]+):?([0-9]*)/(.*)$/', $remote_filename, $url_ary) )
{
if ( empty($url_ary[4]) )
{
message_die(GENERAL_ERROR, 'Incomplete URL.', '', __LINE__, __FILE__);
}
$base_get = '/' . $url_ary[4];
$port = ( !empty($url_ary[3]) ) ? $url_ary[3] : 80;
if ( !($fsock = fsockopen($url_ary[2], $port, $errno, $errstr)) )
{
message_die(GENERAL_ERROR, 'Could not open URL.', '', __LINE__, __FILE__);
}
@fputs($fsock, "GET $base_get HTTP/1.1rn");
@fputs($fsock, "HOST: " . $url_ary[2] . "rn");
@fputs($fsock, "Connection: closernrn");
unset($remote_data);
$remote_data .= @fread($fsock, 1024);
if (!preg_match('#Content-Length: ([0-9]+)[^ /][s]+#i', $remote_data, $file_data1) || !preg_match('#Content-Type: image/[x-]*([a-z]+)[s]+#i', $remote_data, $file_data2))
{
//Server hasn't sent correct headers, typical so lets do it the cheap way.
if(substr_count( strtolower($url_ary[4]), strtolower(".jpg")) or substr_count( strtolower($url_ary[4]), strtolower(".jpeg"))) $file_data2[1]="jpeg";
if(substr_count( strtolower($url_ary[4]), strtolower(".png"))) $file_data2[1]="png";
if(substr_count( strtolower($url_ary[4]), strtolower(".gif"))) $file_data2[1]="gif";
if(substr_count( strtolower($url_ary[4]), strtolower(".php"))) preg_match('#Content-Type: image/[x-]*([a-z]+)[s]+#i', $remote_data, $file_data2);
//Need to download the data in a different way.
$handle = fopen ($url_ary[0], "rb");
unset($remote_data);
do
{
$data = fread($handle, 8192);
if (strlen($data) == 0) break;
$remote_data .= $data;
} while(true);
fclose ($handle);
$file_data1[1] = strlen($remote_data);
}
else
{
while( !@feof($fsock) )
{
$remote_data .= @fread($fsock, 1024);
}
@fclose($fsock);
}
      
$remote_filesize = $file_data1[1];
$remote_filetype = $file_data2[1];
switch ($remote_filetype)
{
case 'jpeg':
case 'jpg':
case 'pjpeg':
if ($album_config['jpg_allowed'] == 0)
{
message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
}
$pic_filetype = '.jpg';
break;
case 'png':
case 'x-png':
if ($album_config['png_allowed'] == 0)
{
message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
}
$pic_filetype = '.png';
break;
case 'gif':
if ($album_config['gif_allowed'] == 0)
{
message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
}
$pic_filetype = '.gif';
break;
default:
message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
}
if ( $remote_filesize > 0 and $remote_filesize < $album_config['max_file_size'] )
{
$remote_data = substr($remote_data, strlen($remote_data) - $remote_filesize, $remote_filesize);
srand((double)microtime()*1000000);
do
{
$pic_filename = md5(uniqid(rand())) . $pic_filetype;
} while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) or file_exists(ALBUM_CACHE_PATH . $pic_filename) );
$fptr = fopen(ALBUM_UPLOAD_PATH . $pic_filename, 'wb');
$bytes_written = fwrite($fptr, $remote_data, $remote_filesize);
fclose($fptr);
if ( $bytes_written != $remote_filesize )
{
unlink(ALBUM_UPLOAD_PATH . $pic_filename);
message_die(GENERAL_ERROR, 'Could not write file to local storage.', '', __LINE__, __FILE__);
}
}
else
{
message_die(GENERAL_MESSAGE, $lang['Bad_upload_file_size']);
}
}
}
else
{
// ---------------------------
// End remote url download mod
// ---------------------------
#
#-----[ FIND ]----------------------------------------
#
// --------------------------------
// Well, it's an image. Check its image size
// --------------------------------
#
#-----[ BEFORE ADD ]----------------------------------------
#
// Remote url download mod
}
// -----------------------
#
#-----[ FIND ]----------------------------------------
#
while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) );
#
#-----[ REPLACE WITH ]----------------------------------------
#
while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) or file_exists(ALBUM_CACHE_PATH . $pic_filename) );
#
#-----[ FIND ]----------------------------------------
#
// --------------------------------
// Insert into DB
// --------------------------------
#
#-----[ AFTER ADD ]----------------------------------------
#
if( $HTTP_POST_FILES['pic_file']['size']==0 and $HTTP_POST_VARS['remote_url'] != "" and empty($HTTP_POST_VARS['remote_dl']) )
{
@unlink(ALBUM_UPLOAD_PATH . $pic_filename);
$pic_filename = $url_ary[0];
}
#
#-----[ OPEN ]----------------------------------------
#(for all your templates, subsilver etc)
album_upload_body.tpl
#
#-----[ FIND ]----------------------------------------
#
else if (document.upload.pic_file.value.length < 2)
#
#-----[ REPLACE WITH ]----------------------------------------
#
else if (document.upload.pic_file.value.length < 2 && document.upload.remote_url.value.length < 2)
#
#-----[ FIND ]----------------------------------------
#
<!-- END switch_manual_thumbnail -->
#
#-----[ AFTER ADD ]----------------------------------------
#
<tr>
<td class="row1" height="28"><span class="gen">{L_REMOTE_URL}</span></td>
<td class="row2"><input class="post" type="text" name="remote_url" size="45" />  <input type="checkbox" name="remote_dl"><span class="gensmall">{L_REMOTE_DL}</span></td>
</tr>
#
#-----[ OPEN ]----------------------------------------
#(for all your languages)
lang_main_album.php
#
#-----[ FIND ]----------------------------------------
#
?>
#
#-----[ BEFORE ADD ]----------------------------------------
#
$lang['Remote_url'] = "Upload image from URL";
$lang['Remote_DL'] = "Download";
#
#-----[ OPEN ]----------------------------------------
#
album_thumbnail.php
#
#-----[ FIND ]----------------------------------------
#
//This part was corrected by Remorseful
if( empty($thispic) || !file_exists($pic_fullpath) )
#
#-----[ REPLACE WITH ]----------------------------------------
#
// Remote download/link mod
preg_match('/^(h**p://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary);
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")
{
$base_get = '/' . $url_ary[4];
$port = ( !empty($url_ary[3]) ) ? $url_ary[3] : 80;
if ( !($fsock = fsockopen($url_ary[2], $port, $errno, $errstr)) ) die('Could not open URL.');
@fputs($fsock, "GET $base_get HTTP/1.1rn");
@fputs($fsock, "HOST: " . $url_ary[2] . "rn");
@fputs($fsock, "Connection: closernrn");
unset($remote_data);
$remote_data = @fread($fsock, 1024);
@fclose($fsock);
if (!preg_match('#Content-Type: image/[x-]*([a-z]+)[s]+#i', $remote_data, $file_data))
{
//Server hasn't sent correct headers, typical so lets do it the cheap way.
if(substr_count( strtolower($url_ary[4]), strtolower(".jpg")) or substr_count( strtolower($url_ary[4]), strtolower(".jpeg"))) $file_data2[1]="jpeg";
if(substr_count( strtolower($url_ary[4]), strtolower(".png"))) $file_data2[1]="png";
if(substr_count( strtolower($url_ary[4]), strtolower(".gif"))) $file_data2[1]="gif";
}
switch ($file_data[1])
{
case 'jpeg':
case 'jpg':
case 'pjpeg':
$pic_filetype = '.jpg';
break;
case 'png':
case 'x-png':
$pic_filetype = '.png';
break;
case 'gif':
$pic_filetype = '.gif';
break;
}
}
// end Remote download/link mod - next line also modded
//This part was fixed by remorseful
if( empty($thispic) or (!file_exists($pic_fullpath) and !($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")) )
#
#-----[ FIND ]----------------------------------------
#
// --------------------------------
// Hmm, cache is empty. Try to re-generate!
// --------------------------------
#
#-----[ BEFORE ADD ]----------------------------------------
#
// Remote download/link Mod
// Cache is empty so i guess we need to download again.
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")
{
if ( !($fsock = fsockopen($url_ary[2], $port, $errno, $errstr)) ) die('Could not open URL.');
@fputs($fsock, "GET $base_get HTTP/1.1rn");
@fputs($fsock, "HOST: " . $url_ary[2] . "rn");
@fputs($fsock, "Connection: closernrn");
unset($remote_data);
$remote_data .= @fread($fsock, 1024);
if (!preg_match('#Content-Length: ([0-9]+)[^ /][s]+#i', $remote_data, $file_data1))
{
//Need to download the data in a different way.
$handle = fopen ($url_ary[0], "rb");
unset($remote_data);
do
{
$data = fread($handle, 8192);
if (strlen($data) == 0) break;
$remote_data .= $data;
} while(true);
fclose ($handle);
$file_data1[1] = strlen($remote_data);
}
else
{
while( !@feof($fsock) )
{
$remote_data .= @fread($fsock, 1024);
}
@fclose($fsock);
}
$pic_filesize = $file_data1[1];
if ( $pic_filesize > 0 )
{
$remote_data = substr($remote_data, strlen($remote_data) - $pic_filesize, $pic_filesize);
srand((double)microtime()*1000000);
do
{
$pic_filename = md5(uniqid(rand())) . $pic_filetype;
} while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) or file_exists(ALBUM_CACHE_PATH . $pic_filename) );
$fptr = fopen(ALBUM_UPLOAD_PATH . $pic_filename, 'wb');
$bytes_written = fwrite($fptr, $remote_data, $pic_filesize);
fclose($fptr);
if ( $bytes_written != $pic_filesize )
{
unlink(ALBUM_UPLOAD_PATH . $pic_filename);
die('Could not write file to local storage.');
}
}
else
{
die($lang['Bad_upload_file_size']);
}
}
// End Remote download/link mod
#
#-----[ FIND ]----------------------------------------
#
//This part isn't fixed at all yet by me so just ignore this change for now!
if (!$gd_errored)
#
#-----[ BEFORE ADD ]----------------------------------------
#
//This part isn't fixed at all yet by me so just ignore this change for now!
// Remote download/link Mod
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://") @unlink(ALBUM_UPLOAD_PATH . $pic_filename);
// End Remote download/link Mod
#
#-----[ OPEN ]----------------------------------------
#
album_pic.php
#
#-----[ FIND ]----------------------------------------
#
//This part fixed by Remorseful
if( empty($thispic) || !file_exists($pic_fullpath) )
#
#-----[ REPLACE WITH ]----------------------------------------
#
// Remote download/link mod
preg_match('/^(h**p://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary);
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")
{
$base_get = '/' . $url_ary[4];
$port = ( !empty($url_ary[3]) ) ? $url_ary[3] : 80;
if ( !($fsock = fsockopen($url_ary[2], $port, $errno, $errstr)) ) die('Could not open URL.');
@fputs($fsock, "GET $base_get HTTP/1.1rn");
@fputs($fsock, "HOST: " . $url_ary[2] . "rn");
@fputs($fsock, "Connection: closernrn");
unset($remote_data);
$remote_data = @fread($fsock, 1024);
@fclose($fsock);
preg_match('#Content-Type: image/[x-]*([a-z]+)[s]+#i', $remote_data, $file_data);
switch ($file_data[1])
{
case 'jpeg':
case 'jpg':
case 'pjpeg':
$pic_filetype = '.jpg';
break;
case 'png':
case 'x-png':
$pic_filetype = '.png';
break;
case 'gif':
$pic_filetype = '.gif';
break;
}
}
// end Remote download/link mod - next line also modded
if( empty($thispic) or (!file_exists($pic_fullpath) and !($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")) )
#
#-----[ FIND ]----------------------------------------
#
// ------------------------------------
// Okay, now we can send image to the browser
// ------------------------------------
#
#-----[ BEFORE ADD ]----------------------------------------
#
// Remote download/link mod
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")
{
header("Location: $pic_filename");
exit;
}
// End Remote download/link mod
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
## MOD Title: ROMOTE URL DOWNLOAD/LINK MOD
## for Photo Album Addon v2 for phpBB2
## MOD Author: I'm not admitting to writing this one either.
## MOD Description:
##
## Download or Link to an image from another website.
##
## Tested with: phpBB 2.0.8 - PHP4.3.3
## MySQL 3.23.x and Smartor's Photo Album Addon v2 for phpBB2
##
## MOD Version:
##
## Installation Level: easy
## Installation Time: 15 minutes
##
## Files To Edit: 5
## album_upload.php
## album_thumbnail.php
## album_pic.php
## templates/subSilver/album_upload_body.tpl
## language/lang_english/lang_main_album.php
##
##############################################################
## Author Notes:
##
## Limited testing. Feedback is always nice.
## Take this as a beta version.
##
##############################################################
## Before Adding This MOD To Your Photo Album,
## You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ OPEN ]-------------------------------------------------------
#
album_upload.php
#
#-----[ FIND ]----------------------------------------
#
'L_MAX_FILESIZE' => $lang['Max_file_size'],
'S_MAX_FILESIZE' => $album_config['max_file_size'],
#
#-----[ BEFORE ADD ]----------------------------------------
#
'L_REMOTE_URL' => $lang['Remote_url'],
'L_REMOTE_DL' => $lang['Remote_DL'],
#
#-----[ FIND ]----------------------------------------
#
// --------------------------------
// Prepare variables
// --------------------------------
$pic_time = time();
$pic_user_id = $userdata['user_id'];
$pic_user_ip = $userdata['session_ip'];
#
#-----[ AFTER ADD ]----------------------------------------
#
// -----------------------
// Remote url download mod
// -----------------------
if( $HTTP_POST_FILES['pic_file']['size']==0 and $HTTP_POST_VARS['remote_url'] != "" and empty($HTTP_POST_VARS['remote_dl']) ) $HotLinked = true;
if( $HTTP_POST_FILES['pic_file']['size']==0 and $HTTP_POST_VARS['remote_url'] != "" )
{
$remote_filename = $HTTP_POST_VARS['remote_url'];
if ( preg_match('/^(h**p://)?([w-.]+):?([0-9]*)/(.*)$/', $remote_filename, $url_ary) )
{
if ( empty($url_ary[4]) )
{
message_die(GENERAL_ERROR, 'Incomplete URL.', '', __LINE__, __FILE__);
}
$base_get = '/' . $url_ary[4];
$port = ( !empty($url_ary[3]) ) ? $url_ary[3] : 80;
if ( !($fsock = fsockopen($url_ary[2], $port, $errno, $errstr)) )
{
message_die(GENERAL_ERROR, 'Could not open URL.', '', __LINE__, __FILE__);
}
@fputs($fsock, "GET $base_get HTTP/1.1rn");
@fputs($fsock, "HOST: " . $url_ary[2] . "rn");
@fputs($fsock, "Connection: closernrn");
unset($remote_data);
$remote_data .= @fread($fsock, 1024);
if (!preg_match('#Content-Length: ([0-9]+)[^ /][s]+#i', $remote_data, $file_data1) || !preg_match('#Content-Type: image/[x-]*([a-z]+)[s]+#i', $remote_data, $file_data2))
{
//Server hasn't sent correct headers, typical so lets do it the cheap way.
if(substr_count( strtolower($url_ary[4]), strtolower(".jpg")) or substr_count( strtolower($url_ary[4]), strtolower(".jpeg"))) $file_data2[1]="jpeg";
if(substr_count( strtolower($url_ary[4]), strtolower(".png"))) $file_data2[1]="png";
if(substr_count( strtolower($url_ary[4]), strtolower(".gif"))) $file_data2[1]="gif";
if(substr_count( strtolower($url_ary[4]), strtolower(".php"))) preg_match('#Content-Type: image/[x-]*([a-z]+)[s]+#i', $remote_data, $file_data2);
//Need to download the data in a different way.
$handle = fopen ($url_ary[0], "rb");
unset($remote_data);
do
{
$data = fread($handle, 8192);
if (strlen($data) == 0) break;
$remote_data .= $data;
} while(true);
fclose ($handle);
$file_data1[1] = strlen($remote_data);
}
else
{
while( !@feof($fsock) )
{
$remote_data .= @fread($fsock, 1024);
}
@fclose($fsock);
}
$remote_filesize = $file_data1[1];
$remote_filetype = $file_data2[1];
switch ($remote_filetype)
{
case 'jpeg':
case 'jpg':
case 'pjpeg':
if ($album_config['jpg_allowed'] == 0)
{
message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
}
$pic_filetype = '.jpg';
break;
case 'png':
case 'x-png':
if ($album_config['png_allowed'] == 0)
{
message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
}
$pic_filetype = '.png';
break;
case 'gif':
if ($album_config['gif_allowed'] == 0)
{
message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
}
$pic_filetype = '.gif';
break;
default:
message_die(GENERAL_ERROR, $lang['Not_allowed_file_type']);
}
if ( $remote_filesize > 0 and $remote_filesize < $album_config['max_file_size'] )
{
$remote_data = substr($remote_data, strlen($remote_data) - $remote_filesize, $remote_filesize);
srand((double)microtime()*1000000);
do
{
$pic_filename = md5(uniqid(rand())) . $pic_filetype;
} while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) or file_exists(ALBUM_CACHE_PATH . $pic_filename) );
$fptr = fopen(ALBUM_UPLOAD_PATH . $pic_filename, 'wb');
$bytes_written = fwrite($fptr, $remote_data, $remote_filesize);
fclose($fptr);
if ( $bytes_written != $remote_filesize )
{
unlink(ALBUM_UPLOAD_PATH . $pic_filename);
message_die(GENERAL_ERROR, 'Could not write file to local storage.', '', __LINE__, __FILE__);
}
}
else
{
message_die(GENERAL_MESSAGE, $lang['Bad_upload_file_size']);
}
}
}
else
{
// ---------------------------
// End remote url download mod
// ---------------------------
#
#-----[ FIND ]----------------------------------------
#
// --------------------------------
// Well, it's an image. Check its image size
// --------------------------------
#
#-----[ BEFORE ADD ]----------------------------------------
#
// Remote url download mod
}
// -----------------------
#
#-----[ FIND ]----------------------------------------
#
while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) );
#
#-----[ REPLACE WITH ]----------------------------------------
#
while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) or file_exists(ALBUM_CACHE_PATH . $pic_filename) );
#
#-----[ FIND ]----------------------------------------
#
// --------------------------------
// Insert into DB
// --------------------------------
#
#-----[ AFTER ADD ]----------------------------------------
#
if( $HTTP_POST_FILES['pic_file']['size']==0 and $HTTP_POST_VARS['remote_url'] != "" and empty($HTTP_POST_VARS['remote_dl']) )
{
@unlink(ALBUM_UPLOAD_PATH . $pic_filename);
$pic_filename = $url_ary[0];
}
#
#-----[ OPEN ]----------------------------------------
#(for all your templates, subsilver etc)
album_upload_body.tpl
#
#-----[ FIND ]----------------------------------------
#
else if (document.upload.pic_file.value.length < 2)
#
#-----[ REPLACE WITH ]----------------------------------------
#
else if (document.upload.pic_file.value.length < 2 && document.upload.remote_url.value.length < 2)
#
#-----[ FIND ]----------------------------------------
#
<!-- END switch_manual_thumbnail -->
#
#-----[ AFTER ADD ]----------------------------------------
#
<tr>
<td class="row1" height="28"><span class="gen">{L_REMOTE_URL}</span></td>
<td class="row2"><input class="post" type="text" name="remote_url" size="45" />  <input type="checkbox" name="remote_dl"><span class="gensmall">{L_REMOTE_DL}</span></td>
</tr>
#
#-----[ OPEN ]----------------------------------------
#(for all your languages)
lang_main_album.php
#
#-----[ FIND ]----------------------------------------
#
?>
#
#-----[ BEFORE ADD ]----------------------------------------
#
$lang['Remote_url'] = "Upload image from URL";
$lang['Remote_DL'] = "Download";
#
#-----[ OPEN ]----------------------------------------
#
album_thumbnail.php
#
#-----[ FIND ]----------------------------------------
#
//This part was corrected by Remorseful
if( empty($thispic) || !file_exists($pic_fullpath) )
#
#-----[ REPLACE WITH ]----------------------------------------
#
// Remote download/link mod
preg_match('/^(h**p://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary);
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")
{
$base_get = '/' . $url_ary[4];
$port = ( !empty($url_ary[3]) ) ? $url_ary[3] : 80;
if ( !($fsock = fsockopen($url_ary[2], $port, $errno, $errstr)) ) die('Could not open URL.');
@fputs($fsock, "GET $base_get HTTP/1.1rn");
@fputs($fsock, "HOST: " . $url_ary[2] . "rn");
@fputs($fsock, "Connection: closernrn");
unset($remote_data);
$remote_data = @fread($fsock, 1024);
@fclose($fsock);
if (!preg_match('#Content-Type: image/[x-]*([a-z]+)[s]+#i', $remote_data, $file_data))
{
//Server hasn't sent correct headers, typical so lets do it the cheap way.
if(substr_count( strtolower($url_ary[4]), strtolower(".jpg")) or substr_count( strtolower($url_ary[4]), strtolower(".jpeg"))) $file_data2[1]="jpeg";
if(substr_count( strtolower($url_ary[4]), strtolower(".png"))) $file_data2[1]="png";
if(substr_count( strtolower($url_ary[4]), strtolower(".gif"))) $file_data2[1]="gif";
}
switch ($file_data[1])
{
case 'jpeg':
case 'jpg':
case 'pjpeg':
$pic_filetype = '.jpg';
break;
case 'png':
case 'x-png':
$pic_filetype = '.png';
break;
case 'gif':
$pic_filetype = '.gif';
break;
}
}
// end Remote download/link mod - next line also modded
//This part was fixed by remorseful
if( empty($thispic) or (!file_exists($pic_fullpath) and !($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")) )
#
#-----[ FIND ]----------------------------------------
#
// --------------------------------
// Hmm, cache is empty. Try to re-generate!
// --------------------------------
#
#-----[ BEFORE ADD ]----------------------------------------
#
// Remote download/link Mod
// Cache is empty so i guess we need to download again.
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")
{
if ( !($fsock = fsockopen($url_ary[2], $port, $errno, $errstr)) ) die('Could not open URL.');
@fputs($fsock, "GET $base_get HTTP/1.1rn");
@fputs($fsock, "HOST: " . $url_ary[2] . "rn");
@fputs($fsock, "Connection: closernrn");
unset($remote_data);
$remote_data .= @fread($fsock, 1024);
if (!preg_match('#Content-Length: ([0-9]+)[^ /][s]+#i', $remote_data, $file_data1))
{
//Need to download the data in a different way.
$handle = fopen ($url_ary[0], "rb");
unset($remote_data);
do
{
$data = fread($handle, 8192);
if (strlen($data) == 0) break;
$remote_data .= $data;
} while(true);
fclose ($handle);
$file_data1[1] = strlen($remote_data);
}
else
{
while( !@feof($fsock) )
{
$remote_data .= @fread($fsock, 1024);
}
@fclose($fsock);
}
$pic_filesize = $file_data1[1];
if ( $pic_filesize > 0 )
{
$remote_data = substr($remote_data, strlen($remote_data) - $pic_filesize, $pic_filesize);
srand((double)microtime()*1000000);
do
{
$pic_filename = md5(uniqid(rand())) . $pic_filetype;
} while( file_exists(ALBUM_UPLOAD_PATH . $pic_filename) or file_exists(ALBUM_CACHE_PATH . $pic_filename) );
$fptr = fopen(ALBUM_UPLOAD_PATH . $pic_filename, 'wb');
$bytes_written = fwrite($fptr, $remote_data, $pic_filesize);
fclose($fptr);
if ( $bytes_written != $pic_filesize )
{
unlink(ALBUM_UPLOAD_PATH . $pic_filename);
die('Could not write file to local storage.');
}
}
else
{
die($lang['Bad_upload_file_size']);
}
}
// End Remote download/link mod
#
#-----[ FIND ]----------------------------------------
#
//This part isn't fixed at all yet by me so just ignore this change for now!
if (!$gd_errored)
#
#-----[ BEFORE ADD ]----------------------------------------
#
//This part isn't fixed at all yet by me so just ignore this change for now!
// Remote download/link Mod
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://") @unlink(ALBUM_UPLOAD_PATH . $pic_filename);
// End Remote download/link Mod
#
#-----[ OPEN ]----------------------------------------
#
album_pic.php
#
#-----[ FIND ]----------------------------------------
#
//This part fixed by Remorseful
if( empty($thispic) || !file_exists($pic_fullpath) )
#
#-----[ REPLACE WITH ]----------------------------------------
#
// Remote download/link mod
preg_match('/^(h**p://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary);
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")
{
$base_get = '/' . $url_ary[4];
$port = ( !empty($url_ary[3]) ) ? $url_ary[3] : 80;
if ( !($fsock = fsockopen($url_ary[2], $port, $errno, $errstr)) ) die('Could not open URL.');
@fputs($fsock, "GET $base_get HTTP/1.1rn");
@fputs($fsock, "HOST: " . $url_ary[2] . "rn");
@fputs($fsock, "Connection: closernrn");
unset($remote_data);
$remote_data = @fread($fsock, 1024);
@fclose($fsock);
preg_match('#Content-Type: image/[x-]*([a-z]+)[s]+#i', $remote_data, $file_data);
switch ($file_data[1])
{
case 'jpeg':
case 'jpg':
case 'pjpeg':
$pic_filetype = '.jpg';
break;
case 'png':
case 'x-png':
$pic_filetype = '.png';
break;
case 'gif':
$pic_filetype = '.gif';
break;
}
}
// end Remote download/link mod - next line also modded
if( empty($thispic) or (!file_exists($pic_fullpath) and !($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")) )
#
#-----[ FIND ]----------------------------------------
#
// ------------------------------------
// Okay, now we can send image to the browser
// ------------------------------------
#
#-----[ BEFORE ADD ]----------------------------------------
#
// Remote download/link mod
if($url_ary[1]=="h**p://" or $url_ary[1]=="f*p://")
{
header("Location: $pic_filename");
exit;
}
// End Remote download/link mod
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
Page 2 of 2
		You cannot post new topicsYou cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events
This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by Icy Phoenix based on phpBB
Generation Time: 0.9002s (PHP: 2% SQL: 98%)
SQL queries: 10 - Debug Off - GZIP Enabled