Jump to content
TNG Community

Use of the Birthdays, Anniversaries, Deaths, Surnames Scripts on a site with WordPress


theKiwi

Recommended Posts

I've been struggling for a while to solve a problem with these little add-ons of mine with 2 aspects of characters - the scripts correctly handle extended characters and curly quotes if they are:

  1. used directly with TNG - eg on a modified index.php page that is calling the scripts - eg http://LisaAndRoger.com/tng/index.php - this is a page displayed purely using TNG;
  2. used with a TNG page called through the TNG-WordPress plugin - again for example a modified index.php page that is calling these scripts - eg http://LisaAndRoger.com/Genealogy/index.php - the same page as above, but passed through the TNG-WordPress plugin to wrap the page in the WordPress headers and footers.

In both the above instances any extended characters and curly quotes used in people's names show up correctly in the output. (There aren't any today, and likely won't be tomorrow either...) 

My databases and TNG and WordPress are all set up to use UTF-8

But...

When these same scripts are used within a WordPress plugin like Enhanced Text Plugin others that allow you execute your own PHP code, then the output of these same scripts as they appear in the widget somehow are taking the extended characters and the curly quotes and apparently turning trying to show them as ISO-8859-1 - and so they show as the dreaded black diamond when these are included into the WordPress side bar - for example on http://LisaAndRoger.com/

The reason I'm suspecting that somewhere on the path through WordPress from the include in the Enhanced Text Widget then out to the page is changing them to ISO-8859-1 is that if I wrap the bits of the scripts that are dealing with names with the utf8_encode() function**, the extended characters display correctly in the WordPress sidebar, and somewhat surprisingly the curly quotes simply vanish.

But...

When the scripts using the utf8_encode() function are viewed both in the pure TNG environment, and in the TNG index.php page processed through the TNG-WordPress plugin, the characters become mangled which is hardly surprising since they are UTF-8 characters that are assumed to be ISO-8859-1 and then converted to UTF-8 again - which doesn't work.

So...

Are others that have battled to get these various birthday scripts working with WordPress - either with the Kloosterman method, or using the plugin - @cjb, @fluffy82, @PapaTango etc seeing the same problem - that extended characters and curly quotes are mangled when shown in the sidebar compared to when they're shown in the TNG index.php page?

Is anyone using extended characters in their TNG database?

I have searched online, and found enough to suggest that WordPress is doing some processing of strings of output using functions such as wpauto but can't find enough information to know for sure what the problem might be.

It seems to be theme independent - I've tried Suffusion, Atahualpa and TwentyNineteen and they all show the problem, which you can see today only at [Website Example URL Removed as Website is Defunct] 

Thanks

Roger

 

** the utf8_encode() function is designed to take a string in ISO-8859-1 and turn it into a UTF-8 string.

Edited by theKiwi
[Website Example URL Removed as Website is Defunct]
Link to comment
Share on other sites

I have a similar problem...

1) when using the widget plugin, the characters don't show properly
2) when using the exact same code in and extended text widget, it doesn't work at all, I get no result displayed
3) when using my own code in an extended widget, is works fine

You can see them on my home page. The Top 10 lists and statistics, are 3 short pieces of code I've written (taking info directly from the database, without going through TNG). Below, you see the "today's events" using the plugin. Special characters don't show - even though my database tables and everything else is set to be UTF-8.

I am now working on a way to replace the "today's events" widgets with my own code. But it's a bit more complicated than just counting surnames :)

Link to comment
Share on other sites

1 hour ago, fluffy82 said:

You can see them on my home page. The Top 10 lists and statistics, are 3 short pieces of code I've written (taking info directly from the database, without going through TNG). Below, you see the "today's events" using the plugin. Special characters don't show - even though my database tables and everything else is set to be UTF-8.

 

Do you know that the top 10 lists and statistics that you have written will correctly show extended characters? (none of the ones shown have extended characters in them).

I guess to know that for sure you'd have to edit one of the most popular place names to have extended characters in it and see how it displays. (then change it back afterwards).

Roger

Link to comment
Share on other sites

On 3/21/2019 at 8:25 PM, fluffy82 said:

3) when using my own code in an extended widget, is works fine

You can see them on my home page. The Top 10 lists and statistics, are 3 short pieces of code I've written (taking info directly from the database, without going through TNG). Below, you see the "today's events" using the plugin. Special characters don't show - even though my database tables and everything else is set to be UTF-8.

Did you basically use a SQL to the TNG database and display the result(s)?  Do you have any sample code you can share?  I guessing the query would be similar to a custom SQL report.  However, I have not had any experience displaying results from a database.

Thanks, Kevin

Link to comment
Share on other sites

3 hours ago, KevyNC said:

Did you basically use a SQL to the TNG database and display the result(s)?  Do you have any sample code you can share?  I guessing the query would be similar to a custom SQL report.  However, I have not had any experience displaying results from a database.

Thanks, Kevin

That's exactly what I did :)

Wordpress and TNG use the same database, so I can access the TNG tables with the password and connection used by Wordpress. It's just a question of establishing the exact variable names used in the database and getting info out of them using SQL.

Here's the basic form if my code displaying the top 10 names:

Quote

<?php

require_once(ABSPATH . 'wp-settings.php');
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysqli_select_db($connection, DB_NAME);

$query = "SELECT count(*) as count, lastname FROM tng_people WHERE lastname != '___' GROUP BY lastname HAVING COUNT(*) BETWEEN 1 and 1000 ORDER BY count(*) DESC LIMIT 10";
$result = mysqli_query($connection, $query);
?>

FYI I use ___ for unknown surnames and there's a lot of those, so I excluded them. 

 

regards,

Tom

Link to comment
Share on other sites

2 hours ago, fluffy82 said:

$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysqli_select_db($connection, DB_NAME);

Tom,

are these different than

tng_db_connect($database_host,$database_name,$database_username,$database_password)?

also why does one have $ sign on the fields?

FYI I use ___ for unknown surnames and there's a lot of those, so I excluded them.  

I used to do this also based off a recommendation I saw about 10 years or so ago. I  recently have removed them in part for that reason, but mainIy discovered it could cause other issues. 

Thanks

Kevin

 

Link to comment
Share on other sites

13 hours ago, KevyNC said:

are these different than


tng_db_connect($database_host,$database_name,$database_username,$database_password)?

 

They are just the different way that TNG and WordPress are set to interact with the database

Quote

 also why does one have $ sign on the fields?

TNG uses the variables that start with the $ sign - it then substitutes  the value of the variable, whereas WordPress is using a different method that seems to be calling the value directly.

Having TNG and WordPress share the database does have some advantages, but it is also possible to get WordPress to query a second database directly too (currently the scripts as written and called into WordPress are querying the database via TNG which is I'm' sure the reason that you can't query more than once with multiple widgets).

Roger

Link to comment
Share on other sites

  • 4 months later...

I just returned to this thread--looking for a prior cure to a heading issue that was resolved--and then re-instituted with an update to Avada...  ☠️

For whatever reason, the ability to set a list of surnames on my landing page keeps haunting me.  As we know, if using a MySQL call on a page using the code developed by @theKiwi (aka Roger) only works in a single instance or query--or multiple results if coded in a single widget.  WordPress, as noted in Roger's earlier post will not allow multiple widgets or MySQL queries to produce results on the same page.

Having not looked at this thread since February 2019, I did not see the supposed 'fix' as a direct MyPHP Db connection and query as described by @fluffy82 & @KevyNC.  I had hoped this was a solution.  WRONG for me...  👎

I have attempted to deploy this code via the plugins PHP Everywhere, Insert PHP, and its successor the whorishly monetized Woody Ad Snippets for $19USD.  All of them threw numerous PHP errors--undefined constants (including misconfigured "expectations", 'getaddress' failures, and boolean errors.  I wasted half a day attempting to recode this in PHP 7+ standards--and even tried PDO and deprecated 5.X rules.  No joy.

Just how are the two of you getting this to work?

Link to comment
Share on other sites

I don't use the plugins anymore. I access the database straight from WordPress, and entered the SQL code from the plugin wrapped in my own html output through a php plugin.

About WirdPress and multiple plugins in one page: I think it's calling the TNG .php pages which is the problem. I have one page with a huge heap of MySQL queries and it works perfectly. All straight through WordPress. The disadvantage is that it doesn't take into account registration limits, like showing living people. I could incorporate that, but I don't really see the use of that for what I use it for.

Here's the page (still under construction):

https://huygens-vandemoortel-ancestry.be/genealogie/statistieken/#

Link to comment
Share on other sites

  • 2 years later...
54 minutes ago, Drake said:

@theKiwi Can you provide sample code, or explain how you were able to add these items to wordpress?

Put this block of code into a PHP Widget - it works on my site - it all has to be one widget - I never did figure out how to get it to work in multiple widgets

<?php
global $wp_tng_path, $link;
$path = get_option('mbtng_path');
chdir ($path);
$wp_tng_path = get_option('mbtng_url');
include ("userscripts/list_birthdays.php");
mbtng_close_tng_table ();
echo "<br />";
include ("userscripts/list_anniversaries.php");
mbtng_close_tng_table ();
echo "<br />";
include ("userscripts/list_deaths.php");
mbtng_close_tng_table ();
echo "<br/>";
echo "<span class=\"normal\" align=\"center\">Surnames</span>";
include ("userscripts/surnamesTagCloud.php");
mbtng_close_tng_table ();
?>

Roger

Link to comment
Share on other sites

I must have spent ~30 hours across time working with these snippets.  One can put all of them in one widget--and they will all work.  If you try to put them into separate widgets, the errors pile up, and some themes (I use Avada) will completely crash the page, or fail with an empty box.  As in Roger's example (I use Dr. K's method--the "eliminate double headers" version) I use the code below with my current site--and it is working with the Laragon development site that will eventually replace what is there now.

<?php
global $wp_tng_path, $link;
$path = "/home3/pthrush219/journeys/genealogy/";
chdir ($path);
$wp_tng_path = "genealogy";
include ("userscripts/list_birthdays.php");
echo "<hr />";
include ("userscripts/list_anniversaries.php");
echo "<hr />";
include ("userscripts/list_deaths.php");
?>



*******************************************************


In each of the core PHP files (list_birthdays, list_deaths, list_anniversaries) search in notepad or other PHP editor instances of a href and add the full base URL:


echo "<span class=\"smaller\"><a href=\"" . $cms['tngpath'] . "getperson.php?personID=" . $row['personID'] . "&amp;tree=" . $row['gedcom'] . "\">" . $row['firstname'] . " " . $row['lnprefix'] . " " . $row['lastname'] . "</a> - <i>" . displaydate ( $row['DeathYear']) . "</i></span>" . $agostring . "<br />";
				break;

To this:

echo "<span class=\"smaller\"><a href=\"https://journeysingenealogy.com/tng/" . $cms['tngpath'] . "getperson.php?personID=" . $row['personID'] . "&amp;tree=" . $row['gedcom'] . "\">" . $row['firstname'] . " " . $row['lnprefix'] . " " . $row['lastname'] . "</a> - <i>" . displaydate ( $row['DeathYear']) . "</i></span>" . $agostring . "<br />";
				break;

 

Link to comment
Share on other sites

That is weird that putting them in separate widgets does not work.   I activated the TNG plug-in , and added the widget to display the menu on the sidebar.  That worked (after modifying the I base url).

I then created the widget to display the top 50 surnames.    I received the dreaded "TNG is not communicating with your host".    I deactivated the tng plug-in and the surnames widget worked.

I figured both of these would work together  . . I guess I will need to create a script to display the menu, and add to the widget,  instead of trying to use the TNG plugin.

 

 

Link to comment
Share on other sites

  • 1 month later...
PapaTango

For whatever reason, multiple calls for this information confuse the database interface.

To date, unless one is only using the TNG template interface, it will fail in WP.  That includes the latest version, 5.9.3.  Have not tested under PHP 8.x yet--dreading what might happen...

Link to comment
Share on other sites

  • 3 weeks later...

Here is an advisory.  I just updated my site to WP 6.0, and PHP v8.1.  There are a few wrinkles on the WP and TNG sides--but they are being easily ironed out.

The biggest issue I have found in TNG is to use the most current (ala updated this year) mods to support your platform.  The same with the WP side.  I have had to find replacements or outright abandon some things because they are too much trouble and not maintained.  Otherwise, the 3-part display functions flawlessly and is not throwing errors or warnings...  😎

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