Auto-show image links as pictures without using [img] tag in messages

Started by Kermit, July 11, 2010, 05:07:13 AM

Previous topic - Next topic

Kermit

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 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);
}
My Mods
Please don't PM/mail me for support,unless i invite you
Formerly known as Duncan85
Quote
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

A. Einstein

Joker™

Really cool trick , gonna use it soon   ;D .

in demo it's me , how cool  8)
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

DoctorMalboro


Kermit

My Mods
Please don't PM/mail me for support,unless i invite you
Formerly known as Duncan85
Quote
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

A. Einstein

DoctorMalboro


~DS~

"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

~DS~

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


"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Kermit

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

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);
}
My Mods
Please don't PM/mail me for support,unless i invite you
Formerly known as Duncan85
Quote
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

A. Einstein

~DS~

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?
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

Kermit

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
My Mods
Please don't PM/mail me for support,unless i invite you
Formerly known as Duncan85
Quote
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

A. Einstein

~DS~

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. :)
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

devoetbalkantine

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

Kermit

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
My Mods
Please don't PM/mail me for support,unless i invite you
Formerly known as Duncan85
Quote
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

A. Einstein


Kermit

My Mods
Please don't PM/mail me for support,unless i invite you
Formerly known as Duncan85
Quote
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

A. Einstein


pearpandas

This is a good one.  Especially for my gallery site. Thnx.


Biology Forums

Is there a way to automatically have the [ img ] and [/ img] inserted between an image link?

Kermit

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
My Mods
Please don't PM/mail me for support,unless i invite you
Formerly known as Duncan85
Quote
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."

A. Einstein

Advertisement: