Standalone - got it working

jeffbh

Joined: 2002-12-26
Posts: 38
Posted: Thu, 2003-01-02 09:54

If, like me, you are trying to use Random Block standalone (e.g. in an IFRAME),
I suggest you try making the following two changes to your copy of block-random.php.

1. Fix the "ERROR: requested index [] out of bounds" problem that occurs on second
invocation of the code by changing the following line in readCache():

$cache[$key] = $val;

to:

$cache[$key] = trim($val);

2. Open Gallery in a new window, rather than within the IFRAME, when clicking on the random picture by adding target=_blank to the generated link, as highlighted in the following code snippet:

$id = $album->getPhotoId($index);
echo ""
."<a href=" .makeAlbumUrl($album->fields["name"], $id) ." target=_blank>"
.$album->getThumbnailTag($index)
."</a>";

These two changes are incorporated in my version of block-random.php, described at http://www.barcahall.com/gallery-block-random.html .

And here's how I use it in an HTML page:

<IFRAME src="/gallery/block-random.php" width="150" height="200" align=top
scrolling=no frameborder=0> [This feature requires IFRAME.] </IFRAME>

 
Agatka
Agatka's picture

Joined: 2002-10-19
Posts: 140
Posted: Fri, 2003-01-03 03:19

Hey,

It works great. I just don't know how to center the picture and also, it seems that I have to specify the height of the iframe and then it doesn't just get the height of the picture :sad:. I don't like that.

Can anyone help me fix those?

Thanks
Agata

http://www.jambra.com

 
jeffbh

Joined: 2002-12-26
Posts: 38
Posted: Fri, 2003-01-03 08:47

Glad to see this worked for you.

I like your suggestions, so I took a whack at those, too.

Centering is easy. I've added the modifications to center the photo. I also made the background color and text follow the style of the album from which the random photo gets selected. Here's <!-- BBCode Start --><A HREF="http://www.barcahall.com/gallery-block-random.html" TARGET="_blank">my version of the source</A><!-- BBCode End --> with these changes.

Sizing the IFRAME to fit its content, however, is trickier, but can be done, and I agree that'd be nice. I may have a chance to get to that in the next few days, if someone else doesn't jump in here and code it up first. In the meantime, make your IFRAME about 10 pixels wider than your widest thumbnail, and about 40 pixels taller than your tallest thumbnail (or taller, if you have a lot of long captions.)

BTW, the changes I've hacked into this file have only been minimally tested, and only in standalone usage, not with Nuke.

 
Agatka
Agatka's picture

Joined: 2002-10-19
Posts: 140
Posted: Fri, 2003-01-03 11:59

That's great. :smile:

Thanks to you I am getting close to what I want. I guess I could live with having have to specify the IFrame height since I don't show captions (some of them are too long).

What I would want however, is the ability to specify the size of the thumb that is being displayed. The space that I have for showing the random photo is much narrower than the actual thumbs in my gallery. Right now, I had to resize all my gallery thumbs to be able to fit in the space for random photo and I think it should be the other way around. :smile:

Would be greatfull for this :smile:

Thanks,
Agatka

 
dodofreak
dodofreak's picture

Joined: 2002-12-09
Posts: 75
Posted: Fri, 2003-01-03 17:45

Yeah, I tried it out too and it works great!

Thanks! :smile:

 
jeffbh

Joined: 2002-12-26
Posts: 38
Posted: Sat, 2003-01-04 02:21

OK, here's <!-- BBCode Start --><A HREF="http://www.barcahall.com/gallery-block-random.html" TARGET="_blank">my latest custom version of block-random.php</A><!-- BBCode End -->.

This version adds support for an optional size parameter to resize the thumbnail so that neither dimension exceeds the specified value. Aspect ratio is maintained. Will enlarge as well as reduce images (although enlarging results in a poor quality image.) The resize occurs only in the browser; the original thumbnail image file is unchanged.

Here's an example of how you might use this in your HTML page to make your thumbnail images scale to 100 pixels:

<IFRAME src="/gallery/block-random.php?size=100" width="116" height="150"
align=top scrolling=no frameborder=0> [This feature requires IFRAME.] </IFRAME>

Again, I offer this latest hack with the caveat that it's barely been tested (and I'm barely familiar with the Gallery source and PHP.) Enjoy. Anyone more familiar with the Gallery code is encouraged to suggest a better way to do this (and/or a better way to deal with the IFRAME as the mechanism to embed block-random.php in a standalone page.)

 
Agatka
Agatka's picture

Joined: 2002-10-19
Posts: 140
Posted: Sat, 2003-01-04 03:30

Ok works :smile:.

Now I really whould like some help regarding the IFrame. I have the random block and last updates included in my html web site using IFrame and both don't resize automaticaly to the height needed.

Thanks jeffbh :smile:

Agata

http://jambra.com

 
jeffbh

Joined: 2002-12-26
Posts: 38
Posted: Sat, 2003-01-04 07:03

All right, here is some code that will resize the IFRAME. Plus a minor mod to block-random.php to remove extra padding around the image.

In the page that contains the IFRAME, place the following Javascript somewhere in the document HEAD (between the <HEAD> and </HEAD> tags):

<script language="JavaScript">
// Credit goes to user kenny9336 on http://www.experts-exchange.com
function iFrameHeight() {
if(document.getElementById &amp;&amp; !(document.all)) {
var h = document.getElementById('blockrandom').contentDocument.body.scrollHeight;
document.getElementById('blockrandom').style.height = h;
}
else if(document.all) {
h = document.frames('blockrandom').document.body.scrollHeight;
document.all.blockrandom.style.height = h;
}
}
</script>

Then edit your IFRAME tag so it calls this function when its content loads, and so that it has an ID. Here's how my IFRAME tag does this:

<IFRAME src="/gallery/block-random.php?size=100" width="100" height="100"
hspace=0 vspace=0 onLoad="iFrameHeight();" id="blockrandom"
align=top scrolling=no frameborder=0> [This feature requires IFRAME.] </IFRAME>

You'll notice that I now have the width of the IFRAME equal to the size parameter passed to block-random.php. That's because I've tweaked block-random one more time to specify no margins in the document body. This allows for the tightest possible layout. To add some padding, specify values greater than 0 for hspace and vspace in the IFRAME tag. And I'd suggest specifying a height parameter close to what the actual height will be, to keep page redraw "motion" to a minimum.

The latest version of my tweaked block-random.php can be found <!-- BBCode Start --><A HREF="http://www.barcahall.com/gallery-block-random.html" TARGET="_blank">Here</A><!-- BBCode End -->.

I've tested this with IE 5.5. If anyone tries it in a Netscape/Mozilla 6+ browser or the latest Opera, please post the results. It will not work in older browsers.

-Jeff

 
Agatka
Agatka's picture

Joined: 2002-10-19
Posts: 140
Posted: Sat, 2003-01-04 13:27

Good Morning jeffbh

Thank you for all your help. I really appreciate it and if you could spedn few more minutes on this I would appreciate it even more :smile:

I have changed the iFrame parameters and added the java script but I am getting the error: access is denied.

It shows line with the following as an error line:

h = document.frames('blockrandom').document.body.scrollHeight;

Can you take a look at that?

Agatka,

http://www.jambra.com

 
jeffbh

Joined: 2002-12-26
Posts: 38
Posted: Sat, 2003-01-04 18:00

Sorry. I should have thought through the cross-domain javascript security issues. Your container page and your gallery PHP pages must both be served by the same server for that version to work and dynamically resize the IFRAME. The browser is protecting you from potentially malicious code from someone else's server.

If, however, the servers hosting each page are within the same second-level domain ("agatka.net", or "jambra.com", to use your servers, Agatka, as an example), then I have a new version of block-random that should work. But this is getting pretty tricky.

To do this, you would have to use a DNS entry of, say, "galeria.jambra.com" for your gallery if your main page is on, say, "www.jambra.com". You would than pass a domain= parameter to block-random.php, as highlighted below:

<IFRAME src="http://galeria.jambra.com/gallery/block-random.php?size=100&amp;domain=jambra.com" width="100" height="100"
hspace=0 vspace=0 onLoad="iFrameHeight();" id="blockrandom"
align=top scrolling=no frameborder=0> [This feature requires IFRAME.] </IFRAME>

You would then also put the javascript statement:
document.domain="jambra.com";
in a javascript block in the HEAD portion of your page on "www.jambra.com" (the one containing the IFRAME.)

If this is not possible for you, then you can avoid the browser security error by removing the onLoad="iFrameHeight();" from your IFRAME tag. (Of course, the IFRAME will not resize.)

My latest version of block-random.php with support for this domain parameter is
<!-- BBCode Start --><A HREF="http://www.barcahall.com/gallery-block-random.html" TARGET="_blank">Here</A><!-- BBCode End -->.

-Jeff

p.s. More details on document.domain can be found in <!-- BBCode Start --><A HREF="http://developer.netscape.com/docs/manuals/js/client/jsref/document.htm#1193628" TARGET="_blank">this Javascript doc</A><!-- BBCode End -->.

 
Agatka
Agatka's picture

Joined: 2002-10-19
Posts: 140
Posted: Sat, 2003-01-04 19:52

HI there,

Don't know if I understand what to do by reading your directions but I will try to read the Java document.

My gallery and the block-random file are in subdomain of agatka.net domain, called galeria.agatka.net. My html file containing the iFrame is on domain jambra.com. I guess it's even more complicated.

Can I still use the files that you are giving me?

Agatka

 
jeffbh

Joined: 2002-12-26
Posts: 38
Posted: Sun, 2003-01-05 06:57

Agatka,

Yes you can still use the version of block-random.php that I've modified. You will be no worse off than before, and you'll have the other changes I've done except that your IFRAME will stay a fixed size. (See below for discussion of yet another change I've made.)

You should make sure to remove the "OnLoad=iFrameHeight();" from your IFRAME tag. You can also remove the corresponding iFrameHeight() function definition from the HEAD of your page; it won't be called.

I have made one more change. If you would like the targeted photo page to open in the same window (normal link behavior) when a user clicks on the random photo, rather than in a new window, you can now add "target=_top" to the block-random.php call in the IFRAME. For instance:

<IFRAME src="/gallery/block-random.php?size=100&amp;target=_top" width="100" height="100"
hspace=0 vspace=0 onLoad="iFrameHeight();" id="blockrandom"
align=top scrolling=no frameborder=0> [This feature requires IFRAME.] </IFRAME>

As mentioned above, delete the onLoad attribute if your two pages are in different server domains (as in your case, Agatka.)

My customized version of block-random.php is located <!-- BBCode Start --><A HREF="http://www.barcahall.com/gallery-block-random.html" TARGET="_blank">Here</A><!-- BBCode End -->.

-Jeff

 
Agatka
Agatka's picture

Joined: 2002-10-19
Posts: 140
Posted: Sun, 2003-01-05 11:33

Jeff,

Thanks a lot for all your help. I should have mentioned it in the beginning that I have two domain involved then I would have saved you some time.

Anyway, I do appreciate all your help.

And for anyone who has long captions and doesn't want them to show under the random photo, I have used the same hack to shorten the captions that I used in my view-photo.php

To do so ... in block-random.php change:

Quote:
$caption = $album->getCaption($index);
if ($caption) {
echo "<br><span class=caption>$caption";

to

Quote:
$tmpstr = $album->getCaption($index);
if ( (strlen($tmpstr) > 20) ) {
$tmpstr= substr($tmpstr,0,20) . "...";
}
echo "<br>$tmpstr";

Agatka

 
eivind

Joined: 2002-08-22
Posts: 18
Posted: Mon, 2003-03-03 17:31

I've got the Standalone Random Block working perfectly - thanks a lot:) But is it possible to specify which albums the random block should select pictures from? All the albums I have are visible for everyone on my webpage, but I would like to specify that the random block should only include pictures from some of the albums. Is there any (easy) way to accomplish this?

 
somroj

Joined: 2003-02-27
Posts: 8
Posted: Fri, 2003-03-07 07:10

I like to know that too! I have tried Jeff's block-random code and it works perfectly (so was Bharatt's). But both pull pictures from album that not open to public, and clicking on the thumb nail links to the hidden albums, all without logging in. Could some one please post a fix to this or suggest what modifications will be needed to ensure the block-random only pulls from public albums? Many thanks.

Somroj :smile:

 
giorgiod

Joined: 2002-08-27
Posts: 4
Posted: Mon, 2003-04-21 09:21

:???: Not working !

I'm using Gallery 1.3.2, RH 7.2 and PHP 4.2.2 but when I try to add the block-random.php to my page I see this error:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 12 bytes) in /home/virtual/site3/fst/var/www/html/gallery/classes/Album.php on line 417

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 177 bytes) in Unknown on line 0

In the past, prior to upgrade to Gallery 1.3.2, the script runs great and without problems.

Any good idea ?

Thanks in advance
Giorgio

 
wborrelli
wborrelli's picture

Joined: 2003-07-18
Posts: 3
Posted: Fri, 2003-07-18 11:02

Also getting a very similar issue. It happened after I upgraded to Gallery 1.3.4. It also happens in /modules/Gallery/util.php

Any suggestions? Any direction would be greatly appreciated.

RedHat 8, Apache 1.3.23, PHP 4.1.2

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 12 bytes) in /var/www/ExtremeTattoozLive/modules/Gallery/classes/Album.php on line 436

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 64 bytes) in Unknown on line 0

 
swingsick
swingsick's picture

Joined: 2003-07-19
Posts: 2
Posted: Sat, 2003-07-19 03:17

Hi Jeff,

Thanks for the help! It works nicely.

One thing I noticed, though, is that the random block script makes images from all galleries. Even ones I tried to only make accessible by logging in with a name and password.

Is there a way to get the script to skip those images? Right now, if you click on the image in the protected gallery that is shown with the random block script, you can access the entire album.

Look forward to hearing from you!

Rob

 
wborrelli
wborrelli's picture

Joined: 2003-07-18
Posts: 3
Posted: Mon, 2003-07-21 11:40

Figured out my issue. Not enough memory allocated in /etc/php.ini.

Bumped it up, restarted, and now works fine. I have no idea why all of the sudden it ran out of memory after more then 1 year of working fine.

I love computers. NOT!

 
punkin

Joined: 2003-09-20
Posts: 10
Posted: Sun, 2003-09-21 09:38

I´m using jeffbh random block, I have the gallery 4.1 with only one album and three photos inside it. I have done all what jeffbh says at her pege but I have this error each three or four enter times:

ERROR: requested index [5] out of bounds [3]
"Fatal error: Call to a member function on a non-object in /web/htdocs/www.todopunk.com/home/galeriacuartos/classes/Album.php on line 705"

The other message error that is shown each two or three times is:
"No photo chosen."

What can I do?? The page is: www.todopunk.com/principal2.shtml
Thankss

 
natcatchpole

Joined: 2003-10-09
Posts: 1
Posted: Mon, 2003-10-13 17:33

Does anyone use this random-block or similar to display full/resized pictures instead of thumbnails? I assume it require changing the getThumb part of the code, but don't know any php at all, so wouldn't know how to modify it. I have thumbnails coming up (albeit with resizing issues, but early days) using the code supplied above.

 
PhilyFn
PhilyFn's picture

Joined: 2003-10-07
Posts: 11
Posted: Tue, 2003-10-14 17:16

nat, check out this thread, this version has the ability to specify full size.

http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=8923