Jump to content
TNG Community

Trouble getting Random photos to work


StarChild

Recommended Posts

I downloaded the random photo function from Wayne Kenna's website (www.kennaweb.com) and I have been trying to set it up on my website. First I discovered that I need to change some of the lines in the code to work with my setup.

Line 14 and 15 had to be changed from

include_once("modules/Genealogy/config.php");

include_once("modules/Genealogy/genlib.php");

to

include_once("config.php");

include_once("genlib.php");

Line 16 had to be changed to match my system

db_connect($database_host,$database_name,$database_username,$database_password) or exit;

My database host is localhost. So, I changed $database_host to $localhost

My database name is Genealogy_DB. So, I changed $database_name to $ Genealogy_DB

I made similar changes for my database_username and database_password.

I changed all the references to tables to the names of my tables. For example, $photolinks_table.personID became $tng_photolinks.personID.

I have reached a point where all that shows up on my website is the words “Random Photo” with no photo displayed under them.

I think the problem is the following function:

// =========================================================================

// Function: makeImg()

//

// This function formats and returns a html <img> string using the specified demensions

// Parameters:

// $image The path to the image file

// $hmax The maximum height to limit the image display to

// $wmax The maximum width to limit the image display to

// $alt The alternate text string to display over the image (optional)

// $extra Additional formatting text to include in the <img> statement (optional)

//

// =========================================================================

function makeImg($image, $hmax, $wmax, $alt = "", $extra = "") {

list($width, $height, $type, $attr) = getimagesize($image);

$hscale = $height / $hmax;

$wscale = $width / $wmax;

if (($hscale > 1) || ($wscale > 1)) {

$scale = ($hscale > $wscale)?$hscale:$wscale;

} else {

$scale = 1;

}

$newwidth = floor($width / $scale);

$newheight= floor($height / $scale);

return "<img width='$newwidth' height='$newheight' src='$image' alt='$alt' $extra>";

}

?>

My photos are in a subdirectory called photos. I have tried to change the first line from:

function makeImg($image, $hmax, $wmax, $alt = "", $extra = "")

to

function makeImg($photo, $175, $175, $alt = "", $extra = "")

function makeImg($/photo, 175, 175, $alt = "", $extra = "")

function makeImg($photo/, $175, $175, $alt = "", $extra = "")

function makeImg(/photo, 175, 175, $alt = "", $extra = "")

But they all giver me errors.

Can anyone offer any tips on how I can get this code to run on my site?

Link to comment
Share on other sites

Not sure what else could be wrong but you don;t need to change any of the $ variables. These are setup when you run the setup under the admin section. I use Wayne's code and don't have any problems with it. Maybe you could send me the page byou are trying to get it to work on and I can look at it and see if I can figure it out.

Link to comment
Share on other sites

Thanks Jeff,

I tried it right out of the box but I got error messages on Lines 13, 14, 15.

include_once("modules/Genealogyconfig.php");

include_once("modules/Genealogygenlib.php");

tng_db_connect($localhost,$Genealogy_DB,$yfidom,$flectre) or exit;

In the case of lines 13 and 14, he has his files in a directory called 'modules/Genealogy' and mine are in the root directory where index.php is located. On line 16, I had to change it to match my database name and username and password or it wouldn't even connect to my database.

The rest I am not sure of. I left all the table names set to the default. But They must have been changed at some point. Because, all the defaults begin with tng_ (tng_photolinks). So I changed those to match the table names listed in my administration setup area.

Wayne wrote to me in email and suggested that the line in the function from makeImg($/photos, $100, $75, $alt = "", $extra = "") looked strange.

He suggested I remove the $ signs from the numbers, so I get

makeImg($/photos, 100, 75, $alt = "", $extra = "")

When I did this, I ended up with the following error on my website where the photo should be:

Parse error: parse error, unexpected '$', expecting ')' in /home/sopha/www/www/randomphoto_inc.php on line 67

:?

Link to comment
Share on other sites

Is it connecting like that? It shouldn't. If you want to specify the names of the server , db and stuff it needs to be done like this:

tng_db_connect(localhost,Genealogy_DB,$yfidom,$flectre) or exit;

Here is my randomphoto_inc.php file:

<?php

//========================================================================================================================

// randomphoto_inc.php

// Author: Wayne Kenna, www.kennaweb.com

// This module is released into the public domain

//

// Displays a random photo from the TNG Genealogy database. Displays the photo's thumbnail and a link to the full size photo.

//

// 1/29/04 - Added logic to work around entries in the photos table that do not have a file name defined. This can happen on gedcom

// imports. Also added logic to resize photos in the event the thumbnail image of the photo is too large.

//

//========================================================================================================================

include_once("config.php");

include_once("genlib.php");

tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;

$max_height = 100; // the maximum height to use when displaying an image

$max_width = 100; // the maximum width to use when displaying an image

$photo_not_ok = 1; // flag for the while() loop

$max_trys = 100; // maximum number of times we will try to find a good photo entry; this keeps us from looping forever

$trys = 0; //

$mycontent = ""; // text variable that will be displayed

if( $currentuser ) {

while ($photo_not_ok == 1) {

$trys = $trys + 1;

// get a random photo (make sure we limit ourselves to folks not flagged as living

$query = "SELECT $photolinks_table.personID, $photolinks_table.ordernum, $people_table.living, ( $photolinks_table.ID / $photolinks_table.ID ) * RAND( ) AS MyRandom FROM $photolinks_table, $people_table WHERE $photolinks_table.personID = $people_table.personID ORDER BY MyRandom DESC LIMIT 1 , 1";

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

$row1 = mysql_fetch_assoc($result);

mysql_free_result($result);

// get the details

$query = "SELECT path, thumbpath, description, notes, ordernum, personID, $photos_table.photoID as photoID FROM $photos_table, $photolinks_table WHERE ($photos_table.photoID = "$row1[photoID]" OR (personID = "$row1[personID]" AND ordernum = "$row1[ordernum]")) AND $photos_table.photoID = $photolinks_table.photoID";

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

$row = mysql_fetch_assoc($result);

mysql_free_result($result);

// check to make sure a thumbnail defined and the file exists

if ($row[thumbpath]!="" && file_exists("$rootpath$photopath/$row[thumbpath]")) {

$photo_not_ok = 0; // photo ok to use

$mycontent = "<center><a href="$cms/showphoto.php?photoID=$row[photoID]">".makeImg($photopath."/".$row[thumbpath],$max_height,$max_width,$row[description],"border='2'")."</a><br>$row[description]</center>";

}

if ($trys > $max_trys) {

$mycontent = "Tried $trys times to find a photo - FAILED";

break;

}

}

}else {

while ($photo_not_ok == 1) {

$trys = $trys + 1;

// get a random photo (make sure we limit ourselves to folks not flagged as living

$query = "SELECT $photolinks_table.personID, $photolinks_table.ordernum, $people_table.living, ( $photolinks_table.ID / $photolinks_table.ID ) * RAND( ) AS MyRandom FROM $photolinks_table, $people_table WHERE $photolinks_table.personID = $people_table.personID AND $people_table.living = 0 ORDER BY MyRandom DESC LIMIT 1 , 1";

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

$row1 = mysql_fetch_assoc($result);

mysql_free_result($result);

// get the details

$query = "SELECT path, thumbpath, description, notes, ordernum, personID, $photos_table.photoID as photoID FROM $photos_table, $photolinks_table WHERE ($photos_table.photoID = "$row1[photoID]" OR (personID = "$row1[personID]" AND ordernum = "$row1[ordernum]")) AND $photos_table.photoID = $photolinks_table.photoID";

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

$row = mysql_fetch_assoc($result);

mysql_free_result($result);

// check to make sure a thumbnail defined and the file exists

if ($row[thumbpath]!="" && file_exists("$rootpath$photopath/$row[thumbpath]")) {

$photo_not_ok = 0; // photo ok to use

$mycontent = "<center><a href="$cms/showphoto.php?photoID=$row[photoID]">".makeImg($photopath."/".$row[thumbpath],$max_height,$max_width,$row[description],"border='2'")."</a><br>$row[description]</center>";

}

if ($trys > $max_trys) {

$mycontent = "Tried $trys times to find a photo - FAILED";

break;

}

}

}

echo $mycontent."n";

// =========================================================================

// Function: makeImg()

//

// This function formats and returns a html <img> string using the specified demensions

// Parameters:

// $image The path to the image file

// $hmax The maximum height to limit the image display to

// $wmax The maximum width to limit the image display to

// $alt The alternate text string to display over the image (optional)

// $extra Additional formatting text to include in the <img> statement (optional)

//

// =========================================================================

function makeImg($image, $hmax, $wmax, $alt = "", $extra = "") {

list($width, $height, $type, $attr) = getimagesize($image);

$hscale = $height / $hmax;

$wscale = $width / $wmax;

if (($hscale > 1) || ($wscale > 1)) {

$scale = ($hscale > $wscale)?$hscale:$wscale;

} else {

$scale = 1;

}

$newwidth = floor($width / $scale);

$newheight= floor($height / $scale);

return "<img width='$newwidth' height='$newheight' src='$image' alt='$alt' $extra>";

}

?>

I just do a include("randomphoto_inc.php"); where aI want the photo and it works.

Hopefully this will help you. BTW, are you using PHP-Nuke or soemthing like that? Seems like when I looked at your site you weren't. If not, this should work for you also.

Link to comment
Share on other sites

Thanks Jeff, That fixes the problem.

In the line;

tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;

Will these variables automatically read my settings and connect even if I don't specify the respective names?

I found basically the same line in my index.php file and when I changed the line to specify my assigned names, the pictures began to work right.

Anyway thanks for the help.

Now, I would like to resize the photos to be a little bit largerso they match the size of the calander to the right of them. (see my page) Is that possible to do in the code? or do I have to just physically make the thumbs larger?

You asked about PHP-Nuke. I am planning to use the attachment from Darren's site for PHP-Nuke, But as yet have not attempted it yet.

Link to comment
Share on other sites

I figured out the resizing of the photo. I just went into Administration General Setup and changed the max size for thumbs to 175 by 125.

Link to comment
Share on other sites

Glad it works now. The tng_db_connect line reads those variables as tehy were setup when you installed TNG. If you look at config.php in your root folder you will see ALL the variables TNG uses. This file was written when you nran setup. Not sure how much PHP or programmming you do but this makes it a lot easier than when something changes having to goto 400 pages to fix it. Let me know if you have anymore problems and I'll try to help.

Link to comment
Share on other sites

Hi Jeff,

I have done a little HTML programming (Static Web Pages) over the past 5 or 10 years. In the beginning, I used Windows Notepad to build my pages. Because of this I got a basic understanding of HTML. In more recent years I began using Microsoft's Front Page, which is more or less WYSIWYG.

I have never touched or heard of PHP until last week, when I purchased TNG from Darrin. I have heard of MySQL but I have never done anything with it and have no previous knowledge.

I found a lot of tutorial sites on the web for PHP and have begun to understand it a little. It seemes to be the same type of thing as CSS. You can make a change on one page (say a menu page) and it automatically updates every page with a link to that menu page. MySQL is basically a relational database like Microsoft Access.

Anyway, thanks for your help.

Link to comment
Share on other sites

Glad to hear it. If I can be of any help, let me know. BTW, I found a today in History php script... It's called CDay PHP. I have it implemented on my page if yuo want to check it out.

Link to comment
Share on other sites

I noticed right away that the first Ham Radio transmission occurred today (18 May) when in 1909, Einar Dessau of Denmark made a transmission on the shortwave bands as a ham.

Aparently, ICDSoft is in Europe somewhere (or else they have their servier time set to UTC) Because, last night, when I installed the script, The calendar on my website (JavaScript) said it was March 17. This is determined by the system clock on the visitors computer.

At the same time, Birthdays/News Events list said it was March 18. This is due to the fact that PHP runs on the server and uses the server time.

I need to find a way to use the visitors computer clock to determine the date. If I can't do this, I will just changed the lable from

"Today is Friday, March 18, 2005"

to something like

"It is currently Friday, March 18, 2005 UTC"

If I can figure out a way to transfer data from JavaScript variables to PHP variables, then I could use the same JavaScript code that I use in the calendar and then pass the variable to PHP.

Link to comment
Share on other sites

The only problem is that PHP is server-side. This means that the script runs on the server and tehn outputs the data in html format. I just left off the "Today is" part of the script. Check out my site and you will see how I did mine. I'll see if I can figure out how to do it but it will probably take a little while to do.

Link to comment
Share on other sites

I found a site on the internet that supposedly displays a visitors' localtime using JavaScript and PHP without even asking them to select their timezone. However, it seems quite complicated to me.

If you are interested, the webpage with the JavaScript/PHP code is at:

http://www.olate.com/articles/254

At lunch, I checked my website (12:30 PM Eastern Standard Time, March 18 = March 19 at my server) So, they have to be at least 12 hours ahead of my local time. I wrote to them to ask where the server is located. One possibility is that I might be able to subtract say 13 hours from the server time. Then the date would be more closely tracking Central Time anyway.

By doing this, anyone in the US would be with in 2 hours (instead of 12 hours) and for a greater part of the day, they would be viewing the events for the correct date.

I think I would have to get the 24 hour time from the server. Then if the hour segment of the time was between 00:01 and 12:00, I would subtract 1 from the day segment of the server date. Else, I would leave the server date the same if the hour segment of the time was between 12:01 and 24:00.

Something like that anyway...

It turns out that my server is in Hong Kong. (GMT+8) I just created the file .htaccess in my webspace. Inside the file I placed the following line: SetEnv TZ :Etc/GMT+(-6)    This effectively changed my server time to CST. That smiley face is supposed to be an 8 not a smiley face
Link to comment
Share on other sites

  • 10 months later...

I'm trying to do the same thing as StarChild--pop up a random photo on my front page. I've changed the paths and table names as suggested above. Now the output I get from randomphotos.php is

: SELECT .personID, .ordernum, .living, ( .ID / .ID ) * RAND( ) AS MyRandom FROM , WHERE .personID = .personID AND .living = 0 ORDER BY MyRandom DESC LIMIT 1 , 1

I'm new to PHP and MySQL, but this looks to me like raw query text. Do you guys know why I'm seeing it instead of the results of the query?

Link to comment
Share on other sites

  • 1 month later...

Thanks Jeff, That fixes the problem.

In the line;

tng_db_connect($database_host,$database_name,$database_username,$database_password) or exit;

Will these variables automatically read my settings and connect even if I don't specify the respective names?

I found basically the same line in my index.php file and when I changed the line to specify my assigned names, the pictures began to work right.

Anyway thanks for the help.

Now, I would like to resize the photos to be a little bit largerso they match the size of the calander to the right of them. (see my page) Is that possible to do in the code? or do I have to just physically make the thumbs larger?

You asked about PHP-Nuke. I am planning to use the attachment from Darren's site for PHP-Nuke, But as yet have not attempted it yet.

Forgive my extreme ignorance here...

I went to your page and refreshed several times. I did notice that each time a new photo is displayed (as you mentioned in the post) I did a view source and I could not find the randominclude php anywhere I did see the photo and path for the photo being displayed however I am still confused as to how to implement.

My guess is as follows: (please add update delete where wrong)

Step 01: Create a randomphoto.php file using the code in this list

Step 02: Make some refererence to this php file in the index.php file

(where I am not sure. my guess would be to replace the mainphoto.jpg with some sort of reference)

Is it really that simple?

Am I missing some steps?

Could you be more specific as to the changes to the index.php?

Thanks,

GENFAN

Link to comment
Share on other sites

  • 2 months later...
Newfloridian

Random Photo Block - a gentle warning.

I use the Photo Block customised in six different ways in our magazine - once for each coloured section. The choice of photos depends in part on the labelling of the tree with branches.

Beware that if you do a full GEDCOM over-write update you will need to use the TNG "relabel branches" facility. I had the bizarre situation recently where the RED (unlabelled branch in the main tree) and the BLUE (separate tree) sections were working normally after an update but the remaining sections displayed only a random block some 2mm square. The update had wiped out the branch labels.

I'd be happy to share my modifications of the code if anone is interested.

The Craxford Family Genealogy Magazine

Alan

Link to comment
Share on other sites

  • 4 months later...

I see you found the script and implemented it. Looks good.

The random photo has been working on my site for over a year now. I recently upgraded my TNG to version 6. Now, when I open my webpage, everything looks fine and most everything works normally. However, I just discovered that if I click on the random photo I just get the following error message.

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

This action would have taken me to the photo's page in the past but now I just get the error.

I suspect that in the upgrade process, I uploaded (and overwrote) showphoto.php eliminating the link to whatever file contained the function get_photo_offsets()

Does anyone know which file contains this get_photo_offsets() function?

Link to comment
Share on other sites

The random photo has been working on my site for over a year now. I recently upgraded my TNG to version 6. Now, when I open my webpage, everything looks fine and most everything works normally. However, I just discovered that if I click on the random photo I just get the following error message.

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

This action would have taken me to the photo's page in the past but now I just get the error.

I suspect that in the upgrade process, I uploaded (and overwrote) showphoto.php eliminating the link to whatever file contained the function get_photo_offsets()

Does anyone know which file contains this get_photo_offsets() function?

FYI, there is an V6-update of this other random-photo script...

http://www.tngforum.us/index.php?showtopic=1210

And it just so happens that I also have a problem with this specific add-on ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...