Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: Kermit in Juli 11, 2010, 05:07:13 VORMITTAG

Titel: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Kermit in Juli 11, 2010, 05:07:13 VORMITTAG
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) Auswählen

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


Code (replace) Auswählen

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) Auswählen
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);
}
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Joker™ in Juli 11, 2010, 05:21:14 VORMITTAG
Really cool trick , gonna use it soon   ;D .

in demo it's me , how cool  8)
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: DoctorMalboro in Juli 11, 2010, 12:13:41 NACHMITTAGS
Isn't that a mod? ::)

Nice trick! :P
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Kermit in Juli 11, 2010, 12:45:12 NACHMITTAGS
Zitat von: DoctorMalboro in Juli 11, 2010, 12:13:41 NACHMITTAGS
Isn't that a mod? ::)

Is it ? ^^
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: DoctorMalboro in Juli 11, 2010, 02:27:46 NACHMITTAGS
Zitat von: Duncan85 in Juli 11, 2010, 12:45:12 NACHMITTAGS
Zitat von: DoctorMalboro in Juli 11, 2010, 12:13:41 NACHMITTAGSIsn't that a mod? ::)
Is it ? ^^
Isn't this the same function that AeMe has? or i'm just crazy? :P
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: ~DS~ in Juli 11, 2010, 02:44:22 NACHMITTAGS
Zitat von: DoctorMalboro in Juli 11, 2010, 02:27:46 NACHMITTAGS
Zitat von: Duncan85 in Juli 11, 2010, 12:45:12 NACHMITTAGS
Zitat von: DoctorMalboro in Juli 11, 2010, 12:13:41 NACHMITTAGSIsn'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...
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: ~DS~ in Juli 12, 2010, 04:22:56 NACHMITTAGS
Zitat von: Delita Heiral in Juli 11, 2010, 02:44:22 NACHMITTAGS
Zitat von: DoctorMalboro in Juli 11, 2010, 02:27:46 NACHMITTAGS
Zitat von: Duncan85 in Juli 11, 2010, 12:45:12 NACHMITTAGS
Zitat von: DoctorMalboro in Juli 11, 2010, 12:13:41 NACHMITTAGSIsn'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


Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Kermit in Juli 13, 2010, 05:09:02 VORMITTAG
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);
}
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: ~DS~ in Juli 13, 2010, 10:53:01 VORMITTAG
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?
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Kermit in Juli 13, 2010, 12:02:32 NACHMITTAGS
Zitat von: Delita Heiral in Juli 13, 2010, 10:53:01 VORMITTAG
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
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: ~DS~ in Juli 13, 2010, 12:15:17 NACHMITTAGS
Zitat von: Duncan85 in Juli 13, 2010, 12:02:32 NACHMITTAGS
Zitat von: Delita Heiral in Juli 13, 2010, 10:53:01 VORMITTAG
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. :)
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: devoetbalkantine in März 03, 2011, 11:00:52 VORMITTAG
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
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Kermit in März 04, 2011, 03:56:01 VORMITTAG
Zitat von: devoetbalkantine in März 03, 2011, 11:00:52 VORMITTAG
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
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: devoetbalkantine in März 19, 2011, 07:01:28 NACHMITTAGS
In which file is that?
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Kermit in März 24, 2011, 04:10:15 VORMITTAG
Zitat von: devoetbalkantine in März 19, 2011, 07:01:28 NACHMITTAGS
In which file is that?

The file is written already in the first message ;)
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: devoetbalkantine in März 28, 2011, 04:16:42 NACHMITTAGS
Ai... Guess I had my blonde moment
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: pearpandas in März 29, 2011, 09:02:16 VORMITTAG
This is a good one.  Especially for my gallery site. Thnx.
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: bros in Januar 18, 2012, 02:01:54 NACHMITTAGS
Any way to make this play nicely with http://custom.simplemachines.org/mods/index.php?mod=195
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Biology Forums in Juni 11, 2012, 10:47:51 NACHMITTAGS
Is there a way to automatically have the [ img ] and [/ img] inserted between an image link?
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Kermit in Juni 12, 2012, 11:58:02 VORMITTAG
Zitat von: Liam_michael in Juni 11, 2012, 10:47:51 NACHMITTAGS
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
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Biology Forums in Juni 12, 2012, 04:41:13 NACHMITTAGS
Zitat von: Kermit in Juni 12, 2012, 11:58:02 VORMITTAG
Zitat von: Liam_michael in Juni 11, 2012, 10:47:51 NACHMITTAGS
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.
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Biology Forums in Juli 10, 2012, 02:10:54 NACHMITTAGS
Zitat von: Liam_michael in Juni 23, 2012, 11:14:21 VORMITTAG
Can anyone else assist me here? :-[

Bump...
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: Guy Verschuere in August 04, 2013, 04:02:01 VORMITTAG
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?
Titel: Re: Auto-show image links as pictures without using [img] tag in messages
Beitrag von: rallepralle in März 09, 2014, 06:49:36 VORMITTAG
Zitat von: Kermit in Juli 11, 2010, 05:07:13 VORMITTAG
For nCode Image Resizer Mod (http://custom.simplemachines.org/mods/index.php?mod=1197) users,they need to replace with this one

Code (replace) Auswählen
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.