PDA

View Full Version : trying to integrate thumbnail viewer into my php forum



gn0stik
03-26-2007, 08:53 PM
1) Script Title:
image thumbnail viewer
2) Script URL (on DD):
http://dynamicdrive.com/dynamicindex4/thumbnail.htm
3) Describe problem:

I'm trying to integrate the thumbnail script into my forums for image uploads.

I've integrated everything but the last bit where you set the images up as hrefs instead of img tags.

The script requires you to format the images like this, as you can see from the instructions....



<p><a href="http://img201.imageshack.us/img201/6923/countryxb6.gif" rel="thumbnail"><img src="thumbnail.gif" style="width: 50px; height: 50px" /></a></p>


Now in my forum's tag to html converter area there's a section that uses preg_replace to translate the bbcode into html for display in the forum.

I'm not familiar with the pattern matching in php, and preg_replace requires you to use escape chars etc to format it in such a way that the string is replaced correctly.

Currently, the line I'm trying to change looks like this.


Code:
$sb_message_txt = preg_replace("/\[img\](.*?)\[\/img\]/si","<img src=\"$1\" border=\"0\" />",$sb_message_txt);


Every time I try to format the href with this pattern recognition syntax, I break my forum. I've read a rather large reference on preg_replace, and pattern matching in php, but have thus far been unsuccessful.

Can someone show me how it should look? I have several lines I need to format this way, if someone could help me by doing the first one as an example of how to do it with an href, that would be great.

This is what I've done so far, that has not worked.


$sb_message_txt = preg_replace("/\[img\](.*?)\[\/img\]/si",<p><a href=\"$1\" rel=\"thumbnail\"><img src=\"thumbnail.gif\" style=\"width: 50px; height: 50px\" /></a></p>,$sb_message_txt);

I got a parse error with that one.

I also posted this in the php forum but got no replies after 3 days so I'm posting it here. Admins can delete the other one.

Any help would be appreciated,

Rich

thetestingsite
03-26-2007, 09:02 PM
You may want to try putting quotes around the string like so:



$sb_message_txt = preg_replace("/\[img\](.*?)\[\/img\]/si","<p><a href=\"$1\" rel=\"thumbnail\"><img src=\"thumbnail.gif\" style=\"width: 50px; height: 50px\" /></a></p>",$sb_message_txt);


If that still doesn't work, post the parse error so that we have an idea of what's going on.

Hope this helps.

gn0stik
03-26-2007, 10:10 PM
cool, will do, thanks. I should have thought of posting the parse error. Duh. I'll post the results.

Rich

gn0stik
03-26-2007, 10:19 PM
OK, now it doesn't throw the parse error, but the small image is a redx and the new image doesn't show up in the pretty div that the script draws, just in a new window.

Odd. I'm looking into it deeper.

Edit: partially fixed, see next post.... disregard this one...

Rich

gn0stik
03-26-2007, 10:42 PM
This is the current code, that doesn't throw a parse error..


$sb_message_txt = preg_replace("/\[img\](.*?)\[\/img\]/si","<p><a href=\"$1\" rel=\"thumbnail\"><img src=\"$1\" style=\"width: 150px;\" /></a></p>",$sb_message_txt);

I got rid of the height part of the style, as It retains proportion this way, and increased it to 150px as you can see.

I also changed the img tag to use the same variable so that it loads the same image as the thumbnail. Not making it any smaller or faster to load, but I don't have a script that will automatically generate the thumbs anyway.

This is the html that it produces.


<p><a href="http://www.dynamicdrive.com/dynamicindex4/portrait.jpg" rel="thumbnail"><img src="http://www.dynamicdrive.com/dynamicindex4/portrait.jpg" style="width: 150px;" /></a></p>

Looks correct to me, not sure why it's not firing the script.

Internet explorer throws an "error: expected identifier, string, or number" between these lines in the script.



targetlinks:[], //Array to hold links with rel="thumbnail"

if (document.getElementById){


So say the line starting with targetlinks: is 10 and the beginning of that if statement is 12

the line number it throws and error for is 11. Which would lead me to believe the erorr is actually on 10. But I see nothing wrong with that. The script is supposed to load up that array, is it not? I mean, I'm not supposed to initialize it am I?

The script it self, in our imaginary line numbering scheme I stated says on line number 8, "no need to edit beyond here".

And that's exactly how it's running in the example.

I don't get it.

Rich

gn0stik
03-27-2007, 12:00 AM
UPDATE::

OK, working in IE7 now, but not FF. I get a little tiny sliver of a thumbnail in spite of the fact that it shows ok in IE, and when I click it the "loading...." flashes, but no image window pops up.

Rich

thetestingsite
03-27-2007, 12:05 AM
Can you either post (or PM) a link to the problem page so that we can take a look at it to find out what's going on with it?

gn0stik
03-27-2007, 12:49 AM
OK, it's working in IE7 and FF now, with no problems that I can see however I still get the script error in ie7 mentioned above.

It's odd, it works but still throws that error in iE7.

my site (www.gn0sis.com) don't think i'm cook please.

unfortunately, you will need to log in in order to view the forums.

gn0stik
03-27-2007, 02:11 AM
I can remove the login requirement for you to see the forums without logging in. If that helps.

thetestingsite
03-27-2007, 02:20 AM
I'm logged in right now, and currently looking at the Image Thumbnails topic. Not sure why (probably something with server cache or whatnot), but the first two images don't show up until I view it using the link (copying it and pasting it in the address bar).

thetestingsite
03-27-2007, 02:26 AM
I noticed that it adds the thumbnail viewer script (which should be in the head of the website) everytime a new post is added. This could be a problem (along with the part not being in the head of the document. Try placing it like the directions say on the demo page (the link you posted in the original post).

Hope this helps.

gn0stik
03-27-2007, 02:55 AM
Yep that did it.

I had that in the forum template instead of the site template. That's why, I was trying to only add it to the forum template, so it would be more portable, and I could give it to other people.

Oh well. It working, and being welded to my site, is better than it not working and being portable.

I couldn't figure out a way to add it to the forum template and have it only load once.

Regards,

Rich