Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Insane Ninja on December 23, 2005, 02:07:27 PM

Title: non-attached photos, click-resize (updated 2006 01 17)
Post by: Insane Ninja on December 23, 2005, 02:07:27 PM
UPDATE: check latest post (http://www.simplemachines.org/community/index.php?topic=61948.msg456735#msg456735) by me

recently i wrote this into my template..

if (stripos($message['body'], 'photobucket.com/albums') !== false)
$message['body'] = preg_replace('#(<img src=")(http://[^\.]+.photobucket.com/albums/[^\.]+/)((?<!th_)[^\/]+\.(jpg|gif))(\"[^>]*>)#i', '$1$2th_$3" onclick="this.src=\'$2$3\';$5', $message['body']);


the idea is to automatically turn photobucket images into their thumbnail versions, where you can click them to return to normal size.. just as attachments do..

i'm asking if theres a better/faster place to put it, thats not in display.template.php


addition:
what would be the best way to revert the image.. i cant find anything about a defaultSrc just yet
Title: Re: photo click-resize (non-attachments)
Post by: dtm.exe on December 23, 2005, 02:46:53 PM
Where do you have it now?  Is it functional?
Title: Re: photo click-resize (non-attachments)
Post by: Insane Ninja on January 17, 2006, 10:36:18 AM
new method.. within /Sources/Display.php

upgraded to work with photobucket, imageshack.us, and myspace photos.. weither posted as thumbnails or not

the lines on top of this code block are to show location within the file

// Do the censor thang.
censorText($message['body']);
censorText($message['subject']);

// Run BBC interpreter on the message.
$message['body'] = parse_bbc($message['body'], $message['smileysEnabled'], $message['ID_MSG']);

// Filter photos to thumbnails
if (stripos($message['body'], '.llnwd.net/') !== false)
$message['body'] = preg_replace('#(<img src=")(http://myspace-[0-9]+[^\/]+.llnwd.net/[^\.]+)(?:_[s|m|l])(\.(png|bmp|jpg|gif))(\"[^>]*>)#i', '$1$2_m$3" style="cursor:pointer;cursor:hand;" onclick="this.src=(this.src==\'$2_l$3\'?\'$2_m$3\':\'$2_l$3\');$5', $message['body']);
if (stripos($message['body'], '.imageshack.us/img') !== false)
$message['body'] = preg_replace('#(<img src=")(http://img[0-9]+.imageshack.us/img[^\.]+)(?:\.th)?(\.(png|bmp|jpg|gif))(\"[^>]*>)#i', '$1$2.th$3" style="cursor:pointer;cursor:hand;" onclick="this.src=(this.src==\'$2$3\'?\'$2.th$3\':\'$2$3\');$5', $message['body']);
if (stripos($message['body'], 'photobucket.com/albums') !== false)
$message['body'] = preg_replace('#(<img src=")(http://[^\.]+.photobucket.com/albums/[^\.]+/)(?:th_)?([^\/]+\.(png|bmp|jpg|gif))(\"[^>]*>)#i', '$1$2th_$3" style="cursor:pointer;cursor:hand;" onclick="this.src=(this.src==\'$2$3\'?\'$2th_$3\':\'$2$3\');$5', $message['body']);
Title: Re: non-attached photos, click-resize (updated 2006 01 17)
Post by: Insane Ninja on January 18, 2006, 08:24:19 PM
nobody tested this?

i made it apart of my "usual theme edits" smf mod on my own site.. but its small enough that i'd just call it a tip/trick
Title: Re: non-attached photos, click-resize (updated 2006 01 17)
Post by: SleePy on January 18, 2006, 08:45:33 PM
Quote from: Insane Ninja on January 18, 2006, 08:24:19 PM
nobody tested this?

i made it apart of my "usual theme edits" smf mod on my own site.. but its small enough that i'd just call it a tip/trick

what if somebody didn't make a thumbnail such as imageshack were you don't always get one...
Title: Re: non-attached photos, click-resize (updated 2006 01 17)
Post by: Insane Ninja on January 19, 2006, 12:20:47 AM
i dont use imageshack.. i had my friend give me the url to a thumb.. i could put in an onerror code to revert it to the origional form
Title: Re: non-attached photos, click-resize (updated 2006 01 17)
Post by: SleePy on January 19, 2006, 08:08:37 PM
i don't remember were but i saw some were that php can create the thumbnail. could you do that if the thumbnail doesn't exist?
Title: Re: non-attached photos, click-resize (updated 2006 01 17)
Post by: Insane Ninja on January 19, 2006, 08:30:58 PM
i do plan to tweak it for hard-coded guest permissions such as replacing images with [guests may not view] or similar