Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

Announcement

FluxBB 1.5.6 and 1.4.12 released

These releases fix a security issue - please update your forums! Download links: v1.5.6 | v1.4.12

#1 2013-01-28 16:57:37

doki
Member
Registered: 2008-05-10
Posts: 25

Modz that capture img tag

Is there a mod or hack that captures the pictures 

[img][/img]

bbcode and save it to local server. The reason i ask this because if the images from img tag hosted on the 3rd party image hosting server is deleted the images will no show up.

Last edited by doki (2013-01-28 16:58:50)

Offline

#2 2013-01-28 22:51:41

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 5,610
Website

Re: Modz that capture img tag

Haven't heard of one, although we once had a rewrite of the parser code that had this feature, too.

Assuming you know how to add code that would do this, this function in include/parser.php would be the place to add such code.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Online

#3 2013-01-29 03:02:12

doki
Member
Registered: 2008-05-10
Posts: 25

Re: Modz that capture img tag

hi Franz,

I have this code from net but i don't know how to insert it in the parser. I think it needs another code to determine the new link from the local server to replace the original link posted by the user.

function GetImageFromUrl($link)
 {
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_POST, 0);
 curl_setopt($ch,CURLOPT_URL,$link);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
$result=curl_exec($ch);
curl_close($ch);
return $result;
} 

I hope you can give me hint or help resolving this. thanks in advance.

Offline

#4 2013-01-30 18:09:40

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 5,610
Website

Re: Modz that capture img tag

Do you know PHP?

If so, here's some pseudo-code how I would do it:

$url_hash = md5($img_url);
if ($url_hash not in image_cache_path)
{
    download_image($img_url, $url_hash); // store it as $url_hash.ext
}

$img_url = '/path/to/image/cache/'.$url_hash.'.ext';

fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Online

#5 2013-01-31 06:36:47

doki
Member
Registered: 2008-05-10
Posts: 25

Re: Modz that capture img tag

Hi Franz,

I'm not a coder and just understand few php codes sad if you could help me accomplish the task that would be a big help to me.

Thanks in advance

Offline

#6 2013-01-31 19:48:02

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 5,610
Website

Re: Modz that capture img tag

Try replacing the function handle_img_tag() in include/parser.php with this code:

// Change this to your path
define('UPLOAD_PATH', 'img/uploads/');

//
// Turns an URL from the [img] tag into an <img> tag or a <a href...> tag
//
function handle_img_tag($url, $is_signature = false, $alt = null)
{
	global $lang_common, $pun_user;

	if (is_null($alt))
		$alt = basename($url);

	$extension = pathinfo($url, PATHINFO_EXTENSION);

	if (in_array($extension, array('jpg', 'jpeg', 'gif', 'png')))
	{
		$url_hash = md5($url);
		$cache_name = $url_hash.'.'.$extension;
		if (!file_exists(PUN_ROOT.UPLOAD_PATH.'.$cache_name))
		{
			download_image($url, PUN_ROOT.UPLOAD_PATH.'.$cache_name);
		}

		$url = get_base_url().'/'.UPLOAD_PATH.'/'.$cache_name;
	}

	$img_tag = '<a href="'.$url.'" rel="nofollow">&lt;'.$lang_common['Image link'].' - '.$alt.'&gt;</a>';

	if ($is_signature && $pun_user['show_img_sig'] != '0')
		$img_tag = '<img class="sigimage" src="'.$url.'" alt="'.$alt.'" />';
	else if (!$is_signature && $pun_user['show_img'] != '0')
		$img_tag = '<span class="postimg"><img src="'.$url.'" alt="'.$alt.'" /></span>';

	return $img_tag;
}

Some things to note:

  1. Please realize that you're downloading user-defined files to a public directory on your own webserver. I limited the extensions to jpeg, jpg, gif and png - as far as I know, that should be enough; but I'm not a security expert.

  2. You have to set the UPLOAD_PATH constant at the beginning to the path where the images should be stored (relative to your FluxBB installation root). That path needs to be writable by the webserver.

  3. You still need to create a function called download_image(). That must receive two parameters - first a URL, second a path on your machine where the file should be stored. The function you mentioned is probably a good start.

  4. I didn't test this - no guarantees for nothing.

Good luck with that. smile


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Online

#7 2013-02-01 06:24:01

doki
Member
Registered: 2008-05-10
Posts: 25

Re: Modz that capture img tag

Thanks Franz for your help. I will try it out tonight. By the way i'm trying to implement it to one of my current forums meaning there are already img tag with the image hosted on the 3rd party server. If i change the parser, im thinking that it will break the existing links. Am I correct?

Last edited by doki (2013-02-01 06:25:05)

Offline

#8 2013-02-01 08:51:36

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 5,610
Website

Re: Modz that capture img tag

Nope, it should download them the next time they're page is loaded. I think.


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Online

Board footer

Powered by FluxBB 1.5.6