Jump to content
TNG Community

TNG Joomla Bridge - url path to a personID


miguel

Recommended Posts

I have some Joomla articles were I mention persons I have in TNG database.

I wish to have links to these persons that would open their personal page within TNG Joomla Bridge.

Is this possible?

Somehow this might be a combination of two commands:

1st) the Joomla Bridge: ../index.php?option=com_tng&Itemid=XX

and

2nd) the path to a person: ../tng/getperson.php?personID=IXXX&tree=X

Thanks,

Miguel

Link to comment
Share on other sites

  • 7 months later...

I wrestled with this same problem for a while after installing the bridge. I wanted to be able to link directly to any TNG page (e.g. person, family, photo, document, etc.) from a Joomla page such as an article. After tweaking a couple of files I think have come up with a working solution. If anyone else knows of a better or more elegant way to accomplish this, please share it with the group! I'm curious to see how others have implemented this functionality.

In the meantime, here is what I came up with.

The two files you need to edit are:

(1) tng.php

(2) index_joomla.php

We'll look at the files one at a time.

(1) tng.php

First, we need to extract any TNG page parameters that were passed in the link to this component. At the top of the file, just after the comments, add the following code:

// grab any TNG page parameters that were passed in the link
if ($_GET) {
    // shift off the first key->value pair ("option=com_tng")
    array_shift($_GET);
    $page = '';
    // concatenate each key->value pair onto the $page string
    foreach ($_GET as $key => $value) {
        if (!empty($value)) {
            $page .= '&' . $key;
            $page .= '=' . $value;
        }
    }        
}
Next, we need to pass those parameters on to TNG. Add the following code immediately after the line that says "$scripturl .= $check;":
// pass TNG page parameters to index_joomla.php
$scripturl .= $page;
Lastly, you may want to add this code if you're using Joomla's main menu module for your site navigation and you have active highlighting turned on. When TNG is called from a link in an article (rather than by clicking the menu item for TNG), the TNG menu item is not highlighted. This code fixes that. You'll need to fill in the ID and actual text of your main menu item that points to TNG. Add this to the end of the file just before the closing </script> tag:
// set the class of the TNG main-menu item to 'active'
var items = document.getElementById('yourMainMenuID').getElementsByTagName('SPAN');
for (var i=0; i < items.length; i++) {
    var nodes = items[i].childNodes;
    for (var j=0; j < nodes.length; j++) {
        if (nodes[j].nodeType == 3) { // Text node
            if (nodes[j].nodeValue == 'titleOfYourTngMenuItem') {
                nodes[j].parentNode.parentNode.parentNode.className += ' active';
            }
        }
    }
}    
Now the second file. (2) index_joomla.php First, we need to grab any page parameters that were passed in. If none were passed (i.e. user just clicked on the menu item for TNG), it will default to the TNG homepage. Add this code near the top of the file immediately after the line that says "$check = $form_vars['check'];" (~line 15):
// grab parameters for specific TNG page
$tngPage = '';
if ($_GET['page']) {
    // shift off the first key->value pair ("parm=...")
    array_shift($_GET);
    $tngPage = $_GET['page'] . '?';
    foreach ($_GET as $key => $value) {
        if (!empty($value)) {
            $tngPage .= '&' . $key;
            $tngPage .= '=' . $value;
        }
    }            
} else {
    $tngPage = $homepage;
}
Lastly, we need to point the browser to the correct page. The default action of this file is to point to the TNG homepage. There are three places where that is done, so we need to edit each of them. I prefer to comment out lines that I replace or edit so I can see the changes, but you can just replace them if you want. Search for the following line:
header( "Location: " . $homepage );
and replace each instance of it with:
header( "Location: " . $tngPage );

That's it. Now, in order to implement this you have to code your links in a certain way. Use the TNG component URL and then tack on the additional TNG parameters, beginning with "&page=".

PLEASE NOTE: You have to change the question mark after the TNG page name to an ampersand (&) and also remove any empty parameters. For some reason when there are empty parameters it crashes. I haven't figured out how to overcome that problem yet. Here are some example links.

If the direct TNG link would normally be this:

  1. getperson.php?personID=I67&tree=br
  2. familygroup.php?familyID=F26&tree=br
  3. showmedia.php?mediaID=320&medialinkID=440
  4. search.php?mylastname=RAWLINS&lnqualify=equals&mybool=AND&tree=br
  5. anniversaries.php?tngevent=birth&tngyear=1850&tngneedresults=1&tree=br
Code the indirect link from Joomla like this:
  1. index.php?option=com_tng&page=getperson.php&personID=I67&tree=br
  2. index.php?option=com_tng&page=familygroup.php&familyID=F26&tree=br
  3. index.php?option=com_tng&page=showmedia.php&mediaID=320&medialinkID=440
  4. index.php?option=com_tng&page=search.php&mylastname=RAWLINS&lnqualify=equals&mybool=AND&tree=br
  5. index.php?option=com_tng&page=anniversaries.php&tngevent=birth&tngyear=1850&tngneedresults=1&tree=br
I've been using this on my site (www.brettsgen.com) and it seems to work great so far. You can link to a specific record like a person or a photo, or even link to search results. For example, above I have a link for people with the surname "Rawlins" and another one for people born in 1850. You can even bookmark these links. Hopefully this will help someone else struggling with the same problem.

-Brett

Link to comment
Share on other sites

reverendspam

Thanks for that very useful nugget Brett.

By the way, your site is uber fast on my end. Will you pm me who you use for your ISP and if you are happy with them. I may be getting another one soon. thanks.

-joe

Link to comment
Share on other sites

  • 2 weeks later...

Thank you for posting this information. It would be very helpful except that I am stuck. You wrote:

First, we need to extract any TNG page parameters that were passed in the link to this component. At the top of the file, just after the comments, add the following code:

CODE// grab any TNG page parameters that were passed in the link

if ($_GET) {

// shift off the first key->value pair ("option=com_tng")

array_shift($_GET);

$page = '';

// concatenate each key->value pair onto the $page string

foreach ($_GET as $key => $value) {

if (!empty($value)) {

$page .= '&' . $key;

$page .= '=' . $value;

}

}

}

I pasted this to my tng.php file as well as the rest of the information.:

Lastly, you may want to add this code if you're using Joomla's main menu module for your site navigation and you have active highlighting turned on. When TNG is called from a link in an article (rather than by clicking the menu item for TNG), the TNG menu item is not highlighted. This code fixes that. You'll need to fill in the ID and actual text of your main menu item that points to TNG. Add this to the end of the file just before the closing </script> tag:

CODE// set the class of the TNG main-menu item to 'active'

var items = document.getElementById('yourMainMenuID').getElementsByTagName('SPAN');

for (var i=0; i < items.length; i++) {

var nodes = items.childNodes;

for (var j=0; j < nodes.length; j++) {

if (nodes[j].nodeType == 3) { // Text node

if (nodes[j].nodeValue == 'titleOfYourTngMenuItem') {

nodes[j].parentNode.parentNode.parentNode.className += ' active';

}

}

}

}

The problem is that I do not have an ID assigned to my main menu other than it says "1" by the menu and I cannot change that.

Also I am not sure what to enter

// grab parameters for specific TNG page

$tngPage = '';

if ($_GET['page']) {

// shift off the first key->value pair ("parm=...")

array_shift($_GET);

$tngPage = $_GET['page'] . '?';

foreach ($_GET as $key => $value) {

if (!empty($value)) {

$tngPage .= '&' . $key;

$tngPage .= '=' . $value;

}

}

} else {

$tngPage = $homepage;

}

for page parameters. My site is http://www.pettettandpettit.com

Your help in figuring out what to put where would be much appreciated. I apologize ahead of time for the lack of understanding exactly how to code the parts on my own. Thank you for yor help.

Link to comment
Share on other sites

I do not have an ID assigned to my main menu...

You can assign an ID to your menu in the main menu module. To get there (using Joomla 1.5) you select:

1. Extensions > Module Manager

2. Then click on your main menu module (it will be of the type "mod_mainmenu")

3. Under Advanced Parameters you'll find a field called "Menu Tag ID"

That's where you can assign an ID to your menu. Giving it an ID simply provides a way for you to find that part of the page in the HTML code so you can style it or manipulate it. Don't use spaces in your ID. Let's say you call it "top-nav" because it's the navigation menu and it's at the top. That's the ID.

In the left column of that same screen you'll see the title of your main main module. That's the name you clicked on above when you were looking for it in the list under Module Manager. The title can have spaces. Let's say it's called "Main Menu".

Now that you have the ID and title of your main menu, you simply plug those values into the code you pasted into tng.php. You'll replace the text "yourMainMenuID" with "top-nav", and replace "titleOfYourTngMenuItem" with "Main Menu".

I am not sure what to enter for page parameters.

The page parameters come from TNG and you'll need to include them in the link you create for that page. The best way to do this is to copy the URL for that specific page straight from your browser. To find the specific URL of a page:

1. Find the TNG link that points to your desired page

2. Right-click the link and choose "Open in a new window"

3. The page and all its parameters are now in the address bar of your browser

4. Copy from the right side back to the TNG page name which ends in ".php" (e.g. getperson.php)

Now in the HTML code of the article you're linking from, you paste in that URL. There are two adjustments you need to make though:

1. Replace the question mark after ".php" with an ampersand (&)

2. Add this text to the beginning of the URL: "index.php?option=com_tng&page="

For example, let's say you want to place a link to the TNG page for Great-Grandpa Jones in a Joomla article. Using the method above you determine that the TNG URL is:

"getperson.php?personID=I23&tree=myTree"

You replace the question mark after the TNG page name with an ampersand and then add the Joomla stuff to the beginning and end up with this URL:

"index.php?option=com_tng&page=getperson.php&personID=I23&tree=myTree"

Now in the HTML code of your article, you place that URL inside the anchor tag of the link like this:

<p>Here's a page about my great-grandpa <a href="index.php?option=com_tng&page=getperson.php&personID=I23&tree=myTree">Robert Jones</a> who lived in Summit County.</p>

Hope that helps clear things up a little.

-Brett

Link to comment
Share on other sites

Thank you very much Brett.

I've followed your instructions and made the changes to both files but in the end I get an "Sorry" error when I call TNG.

I can now say that the problem is when I add this line:

// pass TNG page parameters to index_joomla.php

$scripturl .= $page;

What version of TNG Joomla Brige did you used? I'm using the last one 7.1.5b

Thanks,

Miguel

Link to comment
Share on other sites

  • 2 weeks later...

This issue has been resolved. Miguel and I have both tested the code and it works for registered users too. In index_joomla.php you just have to be sure to replace *every* instance of this line:

header( "Location: " . $homepage );

with this line:

header( "Location: " . $tngPage );

Link to comment
Share on other sites

Brett,

Do you know of a way to have a Joomla Article link directly to a pedigree.php report for an individual?

I have the other types of links working as addressed in your earlier post, but haven't figured a way to get the pedigree, or other ancestor type reports working yet. In TNG, for a pedigree, I first tried:

<a href="index.php?option=com_tng&page=pedigree.php?personID=I10&tree=tree01&parentset=0&display=standard&generations=4">Ancestors Report</a>
But the person ID doesn't appear to be transferring, and I end up with a blank first box, and unknown in the others. But if you then click the Individual tab in the menu you end up with a blank screen - no menus, etc. I've tried removing the parentset, display, fields and various options, for example

pedigree.php?personID=I113&tree=tree01

Even tried setting parentset=1, but nothing has worked so far. Same result when try to run an ahnentafel report.

Have you found a way to do this from a linked Joomla Article?

Thanks,

TomK

Link to comment
Share on other sites

Tom,

I think the problem is that there are two question marks in your link. I tried using a link like that and it behaved just as you described. Try replacing the second question mark with an ampersand (&) like this:

<a href="index.php?option=com_tng&page=pedigree.php&personID=I10&tree=tree01&parentset=0&display=standard&generations=4">Ancestors Report</a>

That should work. I've tested this with all the variations of ancestor and descendant charts and it works fine. You just have to remember to replace the question mark after the TNG page name with an ampersand.

-Brett

Link to comment
Share on other sites

I think the problem is that there are two question marks in your link. I tried using a link like that and it behaved just as you described. Try replacing the second question mark with an ampersand (&) like this:

Brett,

Thanks for the quick response. That did the trick.

I can't believe I didn't notice that 2nd question mark....

Tom

Link to comment
Share on other sites

  • 2 months later...

If you are using the Joom!Fish component to enable multiple languages for your site, it will break the code presented above. Thanks to Miguel for pointing this out to me.

Here is a description of the problem and a quick fix for it.

THE PROBLEM:

Joom!Fish adds a parameter onto the end of each URL to specify the active language (e.g. "&lang=en"). The TNG component doesn't know how to handle this parameter and it chokes yielding an error message that simply says "Sorry". Since Joom!Fish (as far as I know) will not switch the language for your TNG database anyway (I believe TNG has its own utility for handling multiple languages), the easiest resolution is to simply NOT pass the language parameter to TNG. I installed Joom!Fish to test this and my TNG pages load fine when I omit the "&lang=" parameter.

THE FIX:

Edit the "tng.php" file located in the "components/com_tng" folder. By inserting an "If" statement we can prevent the language parameter from being added to the URL. Replace the code block at the top of the file with this one:


// grab any TNG page parameters that were passed in the link
if ($_GET) {
    // shift off the first key->value pair ("option=com_tng")
    array_shift($_GET);
    $page = '';
    // concatenate each key->value pair onto the $page string
    foreach ($_GET as $key => $value) {
        if (!empty($value)) {
            // skip the "&lang=" parameter from Joom!Fish because it breaks TNG
            if ($key == "lang") {
                continue;
            }
            $page .= '&' . $key;
            $page .= '=' . $value;
        }
    }                    
}

That should do the trick.

-Brett

Link to comment
Share on other sites

  • 2 months later...
Edward van der Maarel

Brett,

Thank your for this solution.

If you are using the Joom!Fish component to enable multiple languages for your site, it will break the code presented above.

Will this work, even if I do not use Joomfish yet? Then I need only once make adjustments. 8-)

Link to comment
Share on other sites

Edward,

Yes, the code above will work even if you don't use Joom!Fish. So if you are planning to implement Joom!Fish later, you can make this code change now and it won't break anything.

Link to comment
Share on other sites

Edward van der Maarel

Brett,

Thanks.

I tested it on my local testsite. Without the adjustment for Joomfish I have no problems. After making the adjustment (and without installing Joomfish) I have this error:

Parse error: syntax error, unexpected $end in E:\Xampp\htdocs\joomla\components\com_tng\tng.php on line 117

Did I do something wrong? Because the strange thing is, line 116 is the last one......

Link to comment
Share on other sites

Not sure what the problem is. I'm pretty sure I tested this on my site (which doesn't use Joom!Fish) and it didn't break anything.

In my experience a "syntax error" is usually something small, like a missing bracket or semicolon. Generally the line number listed in the error message is the line *after* the problem line. If you want to send me your file, I'll take a look at it. I'll PM you my email address.

Link to comment
Share on other sites

Edward van der Maarel

Brett,

Thank you but not necessary. I trioed copying again and now it works. So I made a mistake somewhere the first time.

Sorry.

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...