Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Kermit on July 11, 2010, 05:07:13 AM

Title: Auto-show image links as pictures without using [img] tag in messages
Post by: Kermit on July 11, 2010, 05:07:13 AM
This little trick would show up the image links without inserting image links between the img tags

Demo:

http://i28.tinypic.com/xdih5k.jpg

./Sources/Subs.php

Code (find) Select

if (substr($message, 0, 1) == ' ')
$message = ' ' . substr($message, 1);


Code (replace) Select

if (substr($message, 0, 1) == ' ')
$message = ' ' . substr($message, 1);
             
if (strpos($message, '<a href') !== false && !strpos($message ,'quote'))
{
    //show up images without inserting them between [img] tags ;)
$message = preg_replace('~<a href="(.*?)(\.(?i)(jpg|jpeg|gif|png|bmp))"(.*?)>(.*?)(\.(?i)(jpg|jpeg|gif|png|bmp))</a>~i', '<img src="$1$2" alt="" />', $message);
}


For nCode Image Resizer Mod (http://custom.simplemachines.org/mods/index.php?mod=1197) users,they need to replace with this one

Code (replace) Select
if (substr($message, 0, 1) == ' ')
$message = '&nbsp;' . substr($message, 1);

if (strpos($message, '<a href') !== false && !strpos($message ,'quote'))
{
   //show up images without inserting them between [img] tags ;)
$message = preg_replace('~<a href="(.*?)(\.(?i)(jpg|jpeg|gif|png|bmp))"(.*?)>(.*?)(\.(?i)(jpg|jpeg|gif|png|bmp))</a>~i', '<img src="$1$2" alt="" onload="NcodeImageResizer.createOn(this);"/>', $message);
}
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Jokerâ„¢ on July 11, 2010, 05:21:14 AM
Really cool trick , gonna use it soon   ;D .

in demo it's me , how cool  8)
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: DoctorMalboro on July 11, 2010, 12:13:41 PM
Isn't that a mod? ::)

Nice trick! :P
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Kermit on July 11, 2010, 12:45:12 PM
Quote from: DoctorMalboro on July 11, 2010, 12:13:41 PM
Isn't that a mod? ::)

Is it ? ^^
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: DoctorMalboro on July 11, 2010, 02:27:46 PM
Quote from: Duncan85 on July 11, 2010, 12:45:12 PM
Quote from: DoctorMalboro on July 11, 2010, 12:13:41 PMIsn't that a mod? ::)
Is it ? ^^
Isn't this the same function that AeMe has? or i'm just crazy? :P
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: ~DS~ on July 11, 2010, 02:44:22 PM
Quote from: DoctorMalboro on July 11, 2010, 02:27:46 PM
Quote from: Duncan85 on July 11, 2010, 12:45:12 PM
Quote from: DoctorMalboro on July 11, 2010, 12:13:41 PMIsn't that a mod? ::)
Is it ? ^^
Isn't this the same function that AeMe has? or i'm just crazy? :P
I don't think AeMe embed images in a post...
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: ~DS~ on July 12, 2010, 04:22:56 PM
Quote from: Delita Heiral on July 11, 2010, 02:44:22 PM
Quote from: DoctorMalboro on July 11, 2010, 02:27:46 PM
Quote from: Duncan85 on July 11, 2010, 12:45:12 PM
Quote from: DoctorMalboro on July 11, 2010, 12:13:41 PMIsn't that a mod? ::)
Is it ? ^^
Isn't this the same function that AeMe has? or i'm just crazy? :P
I don't think AeMe embed images in a post...
Nope it doesn't...

Duncan85 is there a way to disable (not to show) it?
[noembed][/noembed] won't do


Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Kermit on July 13, 2010, 05:09:02 AM
You mean not to show the images ? Then just not change the codes like i gave above  O:)

or maybe you want to make it like ,when there is an image link in message,it should be shown as like

Image (http://blabla.image.jpg)

If yes,you can do this

if (substr($message, 0, 1) == ' ')
$message = '&nbsp;' . substr($message, 1);

if (strpos($message, '<a href') !== false )
{
    //show up images without inserting them between [img] tags ;)
$message = preg_replace('~<a href="(.*?)(\.(?i)(jpg|jpeg|gif|png|bmp))"(.*?)>(.*?)(\.(?i)(jpg|jpeg|gif|png|bmp))</a>~i', '<a href="$1$2">Image</a> ', $message);
}
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: ~DS~ on July 13, 2010, 10:53:01 AM
Let's say it auto show the images, great, but what if some user rather not show but a normal link if they so decide?
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Kermit on July 13, 2010, 12:02:32 PM
Quote from: Delita Heiral on July 13, 2010, 10:53:01 AM
Let's say it auto show the images, great, but what if some user rather not show but a normal link if they so decide?

It's a thing which would demand kinda long work,as this is just a little trick,i would rather not do it here,if you want ,you can create a topic in mod request board
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: ~DS~ on July 13, 2010, 12:15:17 PM
Quote from: Duncan85 on July 13, 2010, 12:02:32 PM
Quote from: Delita Heiral on July 13, 2010, 10:53:01 AM
Let's say it auto show the images, great, but what if some user rather not show but a normal link if they so decide?

It's a thing which would demand kinda long work,as this is just a little trick,i would rather not do it here,if you want ,you can create a topic in mod request board
That's allright.  8)
Thanks for sharing with the community. :)
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: devoetbalkantine on March 03, 2011, 11:00:52 AM
I have a question... This is working perfectly with 1 minor problem...

When a picture is posted without using the img-tags and the message also has a quote-tags in it, the picture doesn't show.

Just to be clear: The image is NOT in the quote but above it
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Kermit on March 04, 2011, 03:56:01 AM
Quote from: devoetbalkantine on March 03, 2011, 11:00:52 AM
I have a question... This is working perfectly with 1 minor problem...

When a picture is posted without using the img-tags and the message also has a quote-tags in it, the picture doesn't show.

Just to be clear: The image is NOT in the quote but above it

I think it's because of this line

if (strpos($message, '<a href') !== false && !strpos($message ,'quote'))

you can try to replace this with this

if (strpos($message, '<a href') !== false)

I didn't try it by myself,but i think it might work
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: devoetbalkantine on March 19, 2011, 07:01:28 PM
In which file is that?
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Kermit on March 24, 2011, 04:10:15 AM
Quote from: devoetbalkantine on March 19, 2011, 07:01:28 PM
In which file is that?

The file is written already in the first message ;)
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: devoetbalkantine on March 28, 2011, 04:16:42 PM
Ai... Guess I had my blonde moment
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: pearpandas on March 29, 2011, 09:02:16 AM
This is a good one.  Especially for my gallery site. Thnx.
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: bros on January 18, 2012, 02:01:54 PM
Any way to make this play nicely with http://custom.simplemachines.org/mods/index.php?mod=195
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Biology Forums on June 11, 2012, 10:47:51 PM
Is there a way to automatically have the [ img ] and [/ img] inserted between an image link?
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Kermit on June 12, 2012, 11:58:02 AM
Quote from: Liam_michael on June 11, 2012, 10:47:51 PM
Is there a way to automatically have the [ img ] and [/ img] inserted between an image link?

What for ? If images would be shown without insterting those tags in the post
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Biology Forums on June 12, 2012, 04:41:13 PM
Quote from: Kermit on June 12, 2012, 11:58:02 AM
Quote from: Liam_michael on June 11, 2012, 10:47:51 PM
Is there a way to automatically have the [ img ] and [/ img] inserted between an image link?

What for ? If images would be shown without insterting those tags in the post

Because if I don't add [ img ] to the link, it won't obey the settings in the admin section that asks how large a picture can be. I've set mine to 350 px.
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Biology Forums on July 10, 2012, 02:10:54 PM
Quote from: Liam_michael on June 23, 2012, 11:14:21 AM
Can anyone else assist me here? :-[

Bump...
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: Guy Verschuere on August 04, 2013, 04:02:01 AM
Nice trick!

But: I notice that this one breaks all old topics as it is used for every view. Topics with picture with IMG tags are also processed.
Is there a way to have this trick in /Sources/Post.php?
Title: Re: Auto-show image links as pictures without using [img] tag in messages
Post by: rallepralle on March 09, 2014, 06:49:36 AM
Quote from: Kermit on July 11, 2010, 05:07:13 AM
For nCode Image Resizer Mod (http://custom.simplemachines.org/mods/index.php?mod=1197) users,they need to replace with this one

Code (replace) Select
if (substr($message, 0, 1) == ' ')
$message = '&nbsp;' . substr($message, 1);

if (strpos($message, '<a href') !== false && !strpos($message ,'quote'))
{
    //show up images without inserting them between [img] tags ;)
$message = preg_replace('~<a href="(.*?)(\.(?i)(jpg|jpeg|gif|png|bmp))"(.*?)>(.*?)(\.(?i)(jpg|jpeg|gif|png|bmp))</a>~i', '<img src="$1$2" alt="" onload="NcodeImageResizer.createOn(this);"/>', $message);
}


What does 'img src="$1$2"' mean? I want to understand what it means because I modify the code so it can also display videos without adding a tag to the link.