Jump to content
TNG Community
theKiwi

Roger's code for Random Photo

Recommended Posts

theKiwi

This comes from the photoblock.php that is included by Darrin as part of TNG. I modified it to make the image and the description clickable to the showphoto.php page for that image. It excludes documents, and excludes living people.

Roger

PS I've now added the file as an attachment.

<?php
// based on photoblock.php by Darrin Lythgoe as part of TNG
//modified by Roger Moffat to make the image and description
//clickable
include_once("config.php");
include_once("genlib.php");
//include("begin.php");
//include($cms[tngpath] . "genlib.php");
//include($cms[tngpath] . "getlang.php");
//include($cms[tngpath] . "$mylanguage/text.php");
tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;
//include($cms[tngpath] . "checklogin.php");


//COPY EVERYTHING IN THIS BLOCK
//Change these vars to affect max width & height of your photo. Aspect ratio will be maintained. Leaving
//these values blank will cause your photo to be displayed actual size.
$maxwidth = "175";
$maxheight = "175";

$query = "SELECT distinct $photos_table.photoID, path, $photos_table.description
    FROM $photos_table, $photolinks_table, $people_table
    WHERE $photos_table.photoID = $photolinks_table.photoID AND $photolinks_table.gedcom = $people_table.gedcom AND $photolinks_table.personID = $people_table.personID AND phototype != 1 AND (living != \"1\" OR alwayson = \"1\")
    ORDER BY RAND() LIMIT 1";
$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");
$imgrow = mysql_fetch_assoc($result);
mysql_free_result( $result );

$photoinfo = @GetImageSize( "$rootpath$photopath/$imgrow[path]" );
$photowtouse = $photoinfo[0];
$photohtouse = $photoinfo[1];

//these lines do the resizing
if( $maxheight && $photohtouse > $maxheight ) {
    $photowtouse = intval( $maxheight * $photowtouse / $photohtouse );
    $photohtouse = $maxheight;
}
if( $maxwidth && $photowtouse > $maxwidth ) {
    $photohtouse = intval( $maxwidth * $photohtouse / $photowtouse );
    $photowtouse = $maxwidth;
}

//these lines restrict the table width so the caption will not be wider than the photo
if( $maxwidth ) $width = "width=\"$maxwidth\"";
if( $maxheight ) $height = "height=\"$maxheight\"";

echo "<table>\n"; //$width $height>\n";
echo "<tr><td align=\"center\"><a href=\"$cms[url]showphoto.php?photoID=$imgrow[photoID]\"><img src=\"$photopath/" . str_replace("%2F","/",rawurlencode( $imgrow[path] )) . "\" border=\"1\" width=\"$photowtouse\" height=\"$photohtouse\" alt=\"$imgrow[description]\"></a></td></tr>\n";
echo "<tr><td align=\"center\"><span class=\"normal\"><a href=\"$cms[url]showphoto.php?photoID=$imgrow[photoID]\">$imgrow[description]</a></span></td></tr>";
echo "</table>";
?>

randomphoto.php

Edited by theKiwi

Share this post


Link to post
Share on other sites
cdmcquee

This is sweet, and works great at:

http://www.mcqueens.us/genealogy/

The problem is, I require registration and log in for all users, and some of the photos link to living people. Unregistered users can't see more data, but I don't want the image and name of a living person to be displayed.

I only know enough PHP to cut and paste. Can anyone show me how to mod this to protect living individuals?

Thanks!

Share this post


Link to post
Share on other sites
theKiwi

This is sweet, and works great at:

http://www.mcqueens.us/genealogy/

The problem is, I require registration and log in for all users, and some of the photos link to living people. Unregistered users can't see more data, but I don't want the image and name of a living person to be displayed.

I guess I thought it was set to not show living individuals - unless you have set the picture to be always visible. That's what this part of the code is doing I believe...

AND (living != \"1\" OR alwayson = \"1\")

If Living does not equal 1 or Always Visible does equal 1

Are you sure that it does show people who are living? Of course without a log in to your site I can't check for myself. Is Todd McQueen - an old picture of a boy (photo ID was 39 I think) still living? How about the boy in photo ID 60 - Kenneth Peter McQueen?

Roger

Share this post


Link to post
Share on other sites
cdmcquee

I guess I thought it was set to not show living individuals - unless you have set the picture to be always visible. That's what this part of the code is doing I believe...

AND (living != \"1\" OR alwayson = \"1\")

If Living does not equal 1 or Always Visible does equal 1

Are you sure that it does show people who are living? Of course without a log in to your site I can't check for myself. Is Todd McQueen - an old picture of a boy (photo ID was 39 I think) still living? How about the boy in photo ID 60 - Kenneth Peter McQueen?

Roger

I think we are on the same track. All my photos were set to "Always Viewable = On." I've unchecked that box on photos of living individuals. Now it *almost never* displays a photo that has that box unchecked.

Of interest is the fact that when I am logged in it doesn't tend to display more photos of living people.

Todd McQueen and Kenneth Peter McQueen are both still living.

This note is in Darrin's photoblock.php:

"To simplify matters here, all photos attached to living individuals have been removed. No check is done, however, to see if the photo is attached to a source cited for a living individual or a family flagged as living."

Share this post


Link to post
Share on other sites
theKiwi

Of interest is the fact that when I am logged in it doesn't tend to display more photos of living people.

There is no test of whether you're logged in and so allowed to see Living people or not - the way this query is set up it excludes Living people for all users. So you should see the same photos whether you're logged in or not.

I used to have another code block that did test for if you were logged in or not and depending on that it would display photos of Living people, but that took several seconds to process, so when Darrin came out with his photoblock which processed way faster than what I had I changed to that.

Besides I have very few pictures that contain living people, AND I only have a couple of people that have log ins to the site to see Living data, so I didn't need the test to show photos of living people only to those logged in - hiding them for everyone is fine.

Roger

Share this post


Link to post
Share on other sites
Guest nbflint

I think we are on the same track. All my photos were set to "Always Viewable = On." I've unchecked that box on photos of living individuals. Now it *almost never* displays a photo that has that box unchecked.

Of interest is the fact that when I am logged in it doesn't tend to display more photos of living people.

Todd McQueen and Kenneth Peter McQueen are both still living.

This note is in Darrin's photoblock.php:

"To simplify matters here, all photos attached to living individuals have been removed. No check is done, however, to see if the photo is attached to a source cited for a living individual or a family flagged as living."

How about adding a check to see if the current user is logged in and has rights to view living individuals; if so allow the random photo block to show living individuals, if not then display as above.

Share this post


Link to post
Share on other sites
Rasmus

Hey Roger!

Just want to say that your code works like a dream on my webpage. Thanks a lot, you have saved me for a lot of work.

Rasmus from Copenhagen, Denmark

Share this post


Link to post
Share on other sites
beun.net

How about adding a check to see if the current user is logged in and has rights to view living individuals; if so allow the random photo block to show living individuals, if not then display as above.

That I would like :)

I just now added the code to my site (along with the random document add-on), but I have temporarily disabled it, since it also appears to be showing photos with living individuals on it, while not being logged in.

When one clicks the photo to see the larger version of that photo, nothing is shown, which is correct, since there are living individuals on the photo. Unfortunately it does give away the direct URL to the picture, so the large version can still be viewed by circumnavigating the TNG-software.

So... How to prevent displaying photos of living individuals with the above PHP?

FYI: Not one photo in my database has "Always Viewable = On".

Anyone? The ever helpful "theKiwi" maybe? ;-) :razz:

Share this post


Link to post
Share on other sites
theKiwi

That I would like :)

I just now added the code to my site (along with the random document add-on), but I have temporarily disabled it, since it also appears to be showing photos with living individuals on it, while not being logged in.

When one clicks the photo to see the larger version of that photo, nothing is shown, which is correct, since there are living individuals on the photo. Unfortunately it does give away the direct URL to the picture, so the large version can still be viewed by circumnavigating the TNG-software.

So... How to prevent displaying photos of living individuals with the above PHP?

FYI: Not one photo in my database has "Always Viewable = On".

Anyone? The ever helpful "theKiwi" maybe? ;-):razz:

Try this other file, which is the one I mentioned earlier which takes significantly longer to process - it does contain a test for if the user is logged in or not.

Roger

randomphotoOriginal.php

Share this post


Link to post
Share on other sites
beun.net

Try this other file, which is the one I mentioned earlier which takes significantly longer to process - it does contain a test for if the user is logged in or not.

Roger

I'm sorry to say though, that this one too just now showed me a picture of living persons when I tried it out on my site, while I was not logged in.

Thanks anyway :)

Share this post


Link to post
Share on other sites
theKiwi

If you've updated to TNG6, you'll need a new randomphoto.php.

It's attached to this post. As before, based on the code from photoblock.php that Darrin supplies with TNG6

Cheers

Roger

randomphoto.php

Share this post


Link to post
Share on other sites
Bret

I believe I've fixed the randomphoto.php file to properly display (or not display) living individuals. I have this code in place on my site (http://www.rumseyfamily.com) using TNG v6.0 and it seems to be working well for me. I've attached my version of the php file to this message as randomphoto_new.php.

It looks very similar to Roger's version, with the exception of the query itself. In addition to modifying the query to perform two passes (so that all individuals in a photo can be checked for living status), Roger's original also had a typo on the alt setting in the IMG tag (should be $imgrow[description] instead of $description).

randomphoto_new.php

Share this post


Link to post
Share on other sites
beun.net

I believe I've fixed the randomphoto.php file to properly display (or not display) living individuals. I have this code in place on my site (http://www.rumseyfamily.com) using TNG v6.0 and it seems to be working well for me. I've attached my version of the php file to this message as randomphoto_new.php.

It looks very similar to Roger's version, with the exception of the query itself. In addition to modifying the query to perform two passes (so that all individuals in a photo can be checked for living status), Roger's original also had a typo on the alt setting in the IMG tag (should be $imgrow[description] instead of $description).

This one doesn't seem to work for me? (V6)

I get a txt-error:

: SELECT tng_medialink.personID FROM tng_medialink JOIN tng_people on tng_medialink.personID = tng_people.personID WHERE tng_medialink.mediaID = 67 AND tng_people.living = "1"

Any suggestions? :)

Share this post


Link to post
Share on other sites
theKiwi

Sorry I don't have a suggestion, but the randomphoto_new.php does work on my site - try it here

http://roger.lisaandroger.com/randomphoto_new.php

Is there any indication in your server error logs as to what might have gone wrong when you try and view that page - a line saying there was a parse error or something like that?

Roger

Share this post


Link to post
Share on other sites
StarChild

http://genealogie.beun.net/randomphoto_new.php

Will check the logs tonight for anything strange..

On my version 5 page I had a random photo the showed living people if the person was logged in. If the person was not logged in, it restricted the photos to non-living people.

On my index.php I used a line <?php include ("randomphoto_inc.php"); ?> to insert hte photo into the page. This routine called the randomphoto_inc.php file to get the photo. This file was created by Wayne Kenna, [http://www.kennaweb.com]

If you clicked on the photo, it would open the showphoto page to view the photo. But, after upgrading to TNG version 6, now it just get the following errror when I click on the photo.

Fatal error: Call to undefined function: get_photo_offsets() in /home/sopha/www/www/showphoto.php on line 79

I did some research and found the photoblock.php file and the file discussed in this thread. But I do not understand how to implement it on my site. In both files, it says, "// COPY EVERYTHING IN THIS BLOCK" but it does not say where to copy it to.

I tried to call this file using <?php include ("randomphoto_new.php"); ?> But I end up with an error about declaring genlib.php twice or something like that.

I tried to copy the block into my index.php file, but I get the whole file just listed out in text.

What do I copy to where?

If you want to view the way my site should look, it is at Sopha Family Website. It displays ok, but you can't go to the showphoto page without an error. The problem occurs when you click on the photo.

Thanks for any help you can provide.

Share this post


Link to post
Share on other sites
Frans Kniesmeijer

Hello I just copied the following part from photoblock.php to my index.php on the place I wanted it and it works fine:

------------------------------------------------------------------------------------

<?php

//COPY EVERYTHING IN THIS BLOCK

//Change these vars to affect max width & height of your photo. Aspect ratio will be maintained. Leaving

//these values blank will cause your photo to be displayed actual size.

$maxwidth = "100";

$maxheight = "100";

$showmedia_url = getURL( "showmedia", 1 );

$query = "SELECT distinct $media_table.mediaID, path, $media_table.description, usecollfolder

FROM ($media_table, $medialinks_table, $people_table)

WHERE $media_table.mediaID = $medialinks_table.mediaID AND $medialinks_table.gedcom = $people_table.gedcom AND $medialinks_table.personID = $people_table.personID AND mediatypeID = \"photos\" AND (living != \"1\" OR alwayson = \"1\")

ORDER BY RAND() LIMIT 1";

$result = mysql_query($query) or die ("$text[cannotexecutequery]: $query");

$imgrow = mysql_fetch_assoc($result);

mysql_free_result( $result );

$usefolder = $imgrow[usecollfolder] ? $photopath : $mediapath;

$photoinfo = @GetImageSize( "$rootpath$usefolder/$imgrow[path]" );

$photowtouse = $photoinfo[0];

$photohtouse = $photoinfo[1];

//these lines do the resizing

if( $maxheight && $photohtouse > $maxheight ) {

$photowtouse = intval( $maxheight * $photowtouse / $photohtouse ) ;

$photohtouse = $maxheight;

}

if( $maxwidth && $photowtouse > $maxwidth ) {

$photohtouse = intval( $maxwidth * $photohtouse / $photowtouse ) ;

$photowtouse = $maxwidth;

}

//these lines restrict the table width so the caption will not be wider than the photo

if( $maxwidth ) $width = "width=\"$maxwidth\"";

if( $maxheight ) $height = "height=\"$maxheight\"";

echo "<table $width $height>\n";

echo "<tr><td align=\"center\"><a href=\"$showmedia_url" . "mediaID=$imgrow[mediaID]\"><img src=\"$usefolder/" . str_replace("%2F","/",rawurlencode( $imgrow[path] )) . "\" border=\"0\" width=\"$photowtouse\" height=\"$photohtouse\" alt=\"$description\"></a></td></tr>\n";

echo "<tr><td align=\"center\"><span class=\"normal\"><a href=\"$showmedia_url" . "mediaID=$imgrow[mediaID]\">$imgrow[description]</a></span></td></tr>";

echo "</table>";

?>

--------------------------------------------------------------------------------------------

Goodluck

Share this post


Link to post
Share on other sites
StarChild

Hello I just copied the following part from photoblock.php to my index.php on the place I wanted it and it works fine:

------------------------------------------------------------------------------------

The text you copied... Listed above in the previous post

--------------------------------------------------------------------------------------------

Goodluck

Thanks Frans,

I copied that aagin into my webpage and it works fine this time. I must have picked up an extra line or missed one when I copied and pasted it before.

However, If I do the same thing (copy and paste the PHP section) with the modification that Roger made at the start of this thread, I just get the same error:

Fatal error: Call to undefined function: get_photo_offsets() in /home/sopha/www/www/showphoto.php on line 79

It seems to want this get_photo_offsets() function when I click on the picture to go to the photo page. The function doesn't exist anywhere as far as I can tell.

So, at least for now, I can just remove all photos of living people till I can figure out a way to exclude them to non-registered users.

Again thanks for your help.

Share this post


Link to post
Share on other sites
theKiwi

You can't use the first randomphoto.php file that is linked at the start of this thread with TNG6. You need the one that is linked in a post by me partway down the page where I noted there was a new file.

Roger

Share this post


Link to post
Share on other sites
Robert Burns

Hi,

I have added the code to the home page and it works great, but I would like to have it only use pictures in a specified folder, that way I can ensure all the pictures fit in with the template I have used and look professional.

I have tried changing the path in the code from \"photos/" to the folder path I want, but that doesn't work.

Help from a person that knows PHP a bit better would be very helpful.

Thanks.

Share this post


Link to post
Share on other sites
theKiwi

Hi, How do I get this to only make the home page photo random and take these pictures from a specified folder (so that they all fit with the template).

This addon is designed to make a query to the TNG tables and just grab any photo from the media table, of type photos and display it. It's not designed to deal with only the pictures from a particular folder that is outside of the information entered into TNG for media.

Roger

Share this post


Link to post
Share on other sites
Jesper

Hi!

The code works. It's fantastic!

Except for one thing:

I "told the code" to show border around photo. So far so good.

But border color switches between purple and blue...

I would like to make it black.

How do I do that?

Please help!

Jesper

Share this post


Link to post
Share on other sites
theKiwi

I'm assuming you changed the border="0" to border="1" in the randomphoto.php script?

The border around the photo changes colour because it's indicating that there is a link "under" the photo, and so it shows the new link and visited link colours from your css file.

If you want a black (or other fixed colour) border around the photo, you'd need to setup borders for the top, bottom, left and right of the table cell that the photo is in as a css style in your mytngstyle.css file and put that style into the table cell. Something like this maybe..

/*border on photo*/

.photoborder {

border-color: #000000;

border-width: 2px;

border-style: solid;

}

then in randomphoto.php change line 47 so it says this

echo "<tr><td align=\"center\" $photowtouse $photohtouse class=\"photoborder\"><a href=\"$showmedia_url" . "mediaID=$imgrow[mediaID]\"><img src=\"$usefolder/" . str_replace("%2F","/",rawurlencode( $imgrow[path] )) . "\" border=\"0\" width=\"$photowtouse\" height=\"$photohtouse\" alt=\"$imgrow[description]\"></a></td></tr>\n";

should do it

Roger

Share this post


Link to post
Share on other sites
Reginald Vaughn Finley Sr

I have tried all the codes posted. Yet, my pages are still showing living photos to non-registered users. I'm really confused about the $showmedia_url = getURL( "showmedia", 1 ); portion.

I changed it to zero but it's still showing living folks to non-registered. Can someone please provide me the code to show random photos to everyone, but only deceased to non-registered?

Thanks.

Okay nevermind.. I think I got it. I remember turning "always viewable on" most of my pics because I wasn't seeing them in my family tree view. Then I remembered that clicking default made it show or something. nevermind. I just have about 200 pics to change. crap!

Sigh.. I am still runnning into trouble. Family are showing up that are NOT set to display. I'm really confused.

Is there a code that just looks for living individuals and shows them to logged in members.. and non-members get deceased photos. I am have done everything I'm supposed to do on my end I think. Help!

Share this post


Link to post
Share on other sites
Kami Olsson-tapp

I've got it almost working and need a wee bit of advice.

The link to the photo works but the picture itself is not correctly displaying at http://www.tappfamily.us/rp-index.php

I'm pretty confident that the problem rests in that my rp-index.php is one level above my tng folder. The photos are in www.tappfamily.us/tng/photos. If I move the rp-index file to the tng folder it works like a champ - but that is not where my site begins.

Any words of wisdom for me?

Thanks,

Kami

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×