https://www.icyphoenix.com/viewtopic.php?f=26&t=1744 ----------------------------------- Darkheart Thu 26 Apr, 2007 01:35 FAP CUSTOMIZATION - FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Hallo, and thanks for your work Mighty Gorgon! :) I decided to update from Smartors album to FAP, but I have a little problem - the FAP don't works with ROMOTE URL DOWNLOAD/LINK MOD from Smartor's site. Images are not shown and I can't download/link them. :( Maybe you can help me with some changes in this mod to get it work with FAP? Thanks! [code linenumbers=false]############################################################## ## 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('/^(http://)?([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 ]---------------------------------------- # # #-----[ AFTER ADD ]---------------------------------------- # {L_REMOTE_URL}   {L_REMOTE_DL} # #-----[ 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 ]---------------------------------------- # if( empty($thispic) or !file_exists(ALBUM_UPLOAD_PATH . $pic_filename) ) # #-----[ REPLACE WITH ]---------------------------------------- # // Remote download/link mod preg_match('/^(http://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary); if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") { $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 if( empty($thispic) or (!file_exists(ALBUM_UPLOAD_PATH . $pic_filename) and !($url_ary[1]=="http://" or $url_ary[1]=="ftp://")) ) # #-----[ 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]=="http://" or $url_ary[1]=="ftp://") { 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 ]---------------------------------------- # if (!$gd_errored) # #-----[ BEFORE ADD ]---------------------------------------- # // Remote download/link Mod if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") @unlink(ALBUM_UPLOAD_PATH . $pic_filename); // End Remote download/link Mod # #-----[ OPEN ]---------------------------------------- # album_pic.php # #-----[ FIND ]---------------------------------------- # if( empty($thispic) or !file_exists(ALBUM_UPLOAD_PATH . $pic_filename) ) # #-----[ REPLACE WITH ]---------------------------------------- # // Remote download/link mod preg_match('/^(http://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary); if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") { $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(ALBUM_UPLOAD_PATH . $pic_filename) and !($url_ary[1]=="http://" or $url_ary[1]=="ftp://")) ) # #-----[ FIND ]---------------------------------------- # // ------------------------------------ // Okay, now we can send image to the browser // ------------------------------------ # #-----[ BEFORE ADD ]---------------------------------------- # // Remote download/link mod if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") { header("Location: $pic_filename"); exit; } // End Remote download/link mod # #-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ # # EoM[/code] ----------------------------------- Darkheart Fri 27 Apr, 2007 17:39 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Still not solved :cry: Here is the topic of this MOD: http://smartor.is-root.com/viewtopic.php?t=1209 ----------------------------------- Artie Sun 29 Apr, 2007 01:35 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- [quote user="Darkheart" post="12929"]Still not solved :cry: Here is the topic of this MOD: http://smartor.is-root.com/viewtopic.php?t=1209[/quote] That link take me to the topic - [highlight=#FFFFAA]last 24 hrs users in italics?[/highlight] ----------------------------------- Darkheart Sun 29 Apr, 2007 13:40 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Sorry, I have not copied whole link, there is one number missing. Here is the right link, please: http://smartor.is-root.com/viewtopic.php?t=12091 [quote="nuffmon"]Been away for a while and didn't realise anyone still used this. There are huge changes in FAP. I think it would take a while to get it running. [u]It may be worth mentioning it to MG as a future enhancement.[/u][/quote] I think that would be a usefull feature in FAP. Mighty Gorgon, what do you think about this? :roll: ----------------------------------- pepi Sun 29 Apr, 2007 21:04 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Hi I have tried to install this MOD but did not run into FAP IP :( :( :( Pepi ----------------------------------- Darkheart Tue 01 May, 2007 14:19 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- [img]http://ankh.id.lv/images/smiles/sos.gif[/img] Somebody?! :roll: ----------------------------------- Lord Phobos Fri 13 Jul, 2007 14:51 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- PLEASE, i need it too!! :( ----------------------------------- Lord Phobos Wed 25 Jul, 2007 01:35 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- :( :( :( ----------------------------------- pepi Wed 25 Jul, 2007 01:47 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- [quote user="pepi" post="13045"]Hi I have tried to install this MOD but did not run into FAP IP :( :( :( Pepi[/quote] Artie and Mighty please help Pepi ----------------------------------- Artie Wed 25 Jul, 2007 03:29 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Artie is busy trying to get his own site together at the moment. Don't know that I would have any better luck getting this to work than you did, pepi :wink: ----------------------------------- Mighty Gorgon Sun 29 Jul, 2007 14:37 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- I'll try to have a look... but since I'm busy in porting FAP into phpBB 3 this may not happen soon... I hope you may be a bit patient and still try to figure out yourself why it is not working... :roll: ----------------------------------- pepi Sun 29 Jul, 2007 15:07 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Hello The Problem is this [spoiler][code linenumbers=false]# #-----[ OPEN ]---------------------------------------- # album_thumbnail.php # #-----[ FIND ]---------------------------------------- # if( empty($thispic) or !file_exists(ALBUM_UPLOAD_PATH . $pic_filename) ) # #-----[ REPLACE WITH ]---------------------------------------- # // Remote download/link mod preg_match('/^(http://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary); if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") { $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 if( empty($thispic) or (!file_exists(ALBUM_UPLOAD_PATH . $pic_filename) and !($url_ary[1]=="http://" or $url_ary[1]=="ftp://")) ) # #-----[ FIND ]---------------------------------------- # if (!$gd_errored) # #-----[ BEFORE ADD ]---------------------------------------- # // Remote download/link Mod if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") @unlink(ALBUM_UPLOAD_PATH . $pic_filename); // End Remote download/link Mod [/code][/spoiler] and [spoiler][code linenumbers=false]# #-----[ OPEN ]---------------------------------------- # album_pic.php # #-----[ FIND ]---------------------------------------- # if( empty($thispic) or !file_exists(ALBUM_UPLOAD_PATH . $pic_filename) ) # #-----[ REPLACE WITH ]---------------------------------------- # // Remote download/link mod preg_match('/^(http://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary); if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") { $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(ALBUM_UPLOAD_PATH . $pic_filename) and !($url_ary[1]=="http://" or $url_ary[1]=="ftp://")) ) [/code][/spoiler] Dosn't find this code to edit pepi ----------------------------------- Mighty Gorgon Fri 10 Aug, 2007 16:55 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Because those files are now totally different from the original ones. I'll try to have a look, and I can point you where that code has to be inserted... but I have no time to get it working. Next time I'll open FAP files I'll have a look. ----------------------------------- krisbfunk Wed 10 Oct, 2007 18:59 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Since smartor-is-root has been down for a couple weeks, can someone post the mod files? ----------------------------------- stech786 Mon 16 Jun, 2008 00:31 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- has anyone fix this yet. It does not work with the newest FAP. ----------------------------------- stech786 Sun 22 Jun, 2008 20:00 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- anyone???? ----------------------------------- Mighty Gorgon Thu 26 Jun, 2008 16:00 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? ----------------------------------- remorseful Wed 16 Sep, 2009 02:13 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 [b][/b] FIND [codeblock] ############################################################## ## 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('/^(http://)?([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 ]---------------------------------------- # # #-----[ AFTER ADD ]---------------------------------------- # {L_REMOTE_URL}   {L_REMOTE_DL} # #-----[ 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('/^(http://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary); if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") { $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]=="http://" or $url_ary[1]=="ftp://")) ) # #-----[ 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]=="http://" or $url_ary[1]=="ftp://") { 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]=="http://" or $url_ary[1]=="ftp://") @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('/^(http://)?([w-.]+):?([0-9]*)/(.*)$/', $pic_filename, $url_ary); if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") { $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]=="http://" or $url_ary[1]=="ftp://")) ) # #-----[ FIND ]---------------------------------------- # // ------------------------------------ // Okay, now we can send image to the browser // ------------------------------------ # #-----[ BEFORE ADD ]---------------------------------------- # // Remote download/link mod if($url_ary[1]=="http://" or $url_ary[1]=="ftp://") { header("Location: $pic_filename"); exit; } // End Remote download/link mod # #-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ # # EoM [/codeblock] ----------------------------------- Mighty Gorgon Tue 22 Sep, 2009 00:27 Re: FAP With REMOTE URL DOWNLOAD/LINK MOD ----------------------------------- Thanks for sharing!